|
1 | | -using System; |
2 | 1 | using System.Linq; |
3 | 2 | using System.Threading.Tasks; |
4 | 3 | using Shouldly; |
5 | | -using VimeoDotNet.Enums; |
6 | 4 | using VimeoDotNet.Models; |
7 | | -using VimeoDotNet.Parameters; |
8 | 5 | using Xunit; |
9 | 6 |
|
10 | 7 | namespace VimeoDotNet.Tests |
11 | 8 | { |
12 | 9 |
|
13 | 10 | public class FolderTest : BaseTest |
14 | 11 | { |
15 | | - private const int TotalFoldersCount = 7; |
16 | | - private const int RootFoldersCount = 2; |
17 | | - |
18 | 12 | [Fact] |
19 | | - public async Task ShouldCorrectlyGetFolderList() |
| 13 | + public async Task ShouldCorrectlyGetFolderListForMe() |
| 14 | + { |
| 15 | + MockHttpRequest(new RequestSettings |
| 16 | + { |
| 17 | + UrlSuffix = "/me/folders", |
| 18 | + ResponseJsonFile = "Folder.user-folder-list.json" |
| 19 | + }); |
| 20 | + var client = CreateAuthenticatedClient(); |
| 21 | + var folders = await client.GetUserFolders(UserId.Me); |
| 22 | + folders.Total.ShouldBeGreaterThan(1); |
| 23 | + folders.Total.ShouldBe(12); |
| 24 | + folders.PerPage.ShouldBe(25); |
| 25 | + folders.Data.Count.ShouldBeGreaterThan(1); |
| 26 | + folders.Data.Count.ShouldBeLessThanOrEqualTo(12); |
| 27 | + AssertPagingNext(folders); |
| 28 | + folders.Paging.Previous.ShouldBeNull(); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public async Task ShouldCorrectlyGetFolderListForUserId() |
20 | 33 | { |
| 34 | + const long userId = 2433258; |
| 35 | + MockHttpRequest(new RequestSettings |
| 36 | + { |
| 37 | + UrlSuffix = $"/users/{userId}/folders", |
| 38 | + ResponseJsonFile = "Folder.user-folder-list.json" |
| 39 | + }); |
21 | 40 | var client = CreateAuthenticatedClient(); |
22 | | - Paginated<Folder> folders = await client.GetUserFolders(null); |
| 41 | + var folders = await client.GetUserFolders(userId); |
23 | 42 | folders.Total.ShouldBeGreaterThan(1); |
24 | | - folders.Total.ShouldBe(TotalFoldersCount); |
| 43 | + folders.Total.ShouldBe(12); |
25 | 44 | folders.PerPage.ShouldBe(25); |
26 | 45 | folders.Data.Count.ShouldBeGreaterThan(1); |
27 | | - folders.Data.Count.ShouldBeLessThanOrEqualTo(TotalFoldersCount); |
| 46 | + folders.Data.Count.ShouldBeLessThanOrEqualTo(12); |
28 | 47 | AssertPagingNext(folders); |
29 | 48 | folders.Paging.Previous.ShouldBeNull(); |
30 | 49 | } |
31 | 50 |
|
| 51 | + |
| 52 | + [Fact] |
| 53 | + public async Task ShouldCorrectlyGetFolderItemsListForMe() |
| 54 | + { |
| 55 | + const long folderId = 15721523; |
| 56 | + MockHttpRequest(new RequestSettings |
| 57 | + { |
| 58 | + UrlSuffix = "/me/projects/15721523/items", |
| 59 | + ResponseJsonFile = "Folder.folder-15721523-items.json" |
| 60 | + }); |
| 61 | + MockHttpRequest(new RequestSettings |
| 62 | + { |
| 63 | + UrlSuffix = "/me/projects/15721574/items", |
| 64 | + ResponseJsonFile = "Folder.folder-15721574-items.json" |
| 65 | + }); |
| 66 | + var client = CreateAuthenticatedClient(); |
| 67 | + var rootItems = await client.GetFolderItems(UserId.Me, folderId); |
| 68 | + var folder = rootItems.Data.OrderBy(x => x.IsFolder ? x.Folder.Name : x.Video.Name).First(x => x.IsFolder); |
| 69 | + folder.Folder.Id.ShouldNotBeNull(); |
| 70 | + var folderItems = await client.GetFolderItems(UserId.Me, folder.Folder.Id.Value); |
| 71 | + folderItems.Total.ShouldBe(1); |
| 72 | + } |
| 73 | + |
| 74 | + [Fact] |
| 75 | + public async Task ShouldCorrectlyGetFolderItemsListForUserId() |
| 76 | + { |
| 77 | + const long userId = 2433258; |
| 78 | + const long folderId = 15721523; |
| 79 | + MockHttpRequest(new RequestSettings |
| 80 | + { |
| 81 | + UrlSuffix = $"/users/{userId}/projects/15721523/items", |
| 82 | + ResponseJsonFile = "Folder.folder-15721523-items.json" |
| 83 | + }); |
| 84 | + MockHttpRequest(new RequestSettings |
| 85 | + { |
| 86 | + UrlSuffix = $"/users/{userId}/projects/15721574/items", |
| 87 | + ResponseJsonFile = "Folder.folder-15721574-items.json" |
| 88 | + }); |
| 89 | + var client = CreateAuthenticatedClient(); |
| 90 | + var rootItems = await client.GetFolderItems(userId, folderId); |
| 91 | + var folder = rootItems.Data.OrderBy(x => x.IsFolder ? x.Folder.Name : x.Video.Name).First(x => x.IsFolder); |
| 92 | + folder.Folder.Id.ShouldNotBeNull(); |
| 93 | + var folderItems = await client.GetFolderItems(userId, folder.Folder.Id.Value); |
| 94 | + folderItems.Total.ShouldBe(1); |
| 95 | + } |
| 96 | + |
32 | 97 | [Fact] |
33 | | - public async Task ShouldCorrectlyGetRootItemsList() |
| 98 | + public async Task ShouldCorrectlyCreateFolder() |
34 | 99 | { |
35 | 100 | var client = CreateAuthenticatedClient(); |
36 | | - Paginated<Item> items = await client.GetUserRootItems(VimeoSettings.UserId); |
37 | | - |
38 | | - items.Total.ShouldBeGreaterThan(1); |
39 | | - items.Total.ShouldBeLessThan(7); |
40 | | - items.PerPage.ShouldBe(25); |
41 | | - items.Data.Where(x=>x.IsVideo).Count().ShouldBe(1); |
42 | | - items.Data.Where(x => x.IsFolder).Count().ShouldBe(1); |
43 | | - items.Data.Count.ShouldBe(RootFoldersCount); |
44 | | - AssertPagingNext<Item>(items); |
45 | | - items.Paging.Previous.ShouldBeNull(); |
| 101 | + MockHttpRequest(new RequestSettings |
| 102 | + { |
| 103 | + UrlSuffix = "/me/folders", |
| 104 | + Method = RequestSettings.HttpMethod.Post, |
| 105 | + RequestTextBody = "name=Test+folder", |
| 106 | + ResponseJsonFile = "Folder.post-folder.json" |
| 107 | + }); |
| 108 | + await client.CreateFolder(UserId.Me, "Test folder"); |
46 | 109 | } |
47 | 110 |
|
48 | 111 | [Fact] |
49 | | - public async Task ShouldCorrectlyGetFolderItemsList() |
| 112 | + public async Task ShouldCorrectlyDeleteFolder() |
50 | 113 | { |
| 114 | + const long folderId = 15721704; |
| 115 | + MockHttpRequest(new RequestSettings |
| 116 | + { |
| 117 | + UrlSuffix = $"/me/projects/{folderId}", |
| 118 | + Method = RequestSettings.HttpMethod.Delete, |
| 119 | + StatusCode = 204 |
| 120 | + }); |
51 | 121 | var client = CreateAuthenticatedClient(); |
52 | | - Paginated<Item> rootItems = await client.GetUserRootItems(VimeoSettings.UserId); |
53 | | - var folder = rootItems.Data.First(x => x.IsFolder); |
54 | | - Paginated<Item> folderItems = await client.GetFolderItems(VimeoSettings.UserId, folder.Folder.Id.Value); |
55 | | - folderItems.Total.ShouldBe(7); |
| 122 | + await client.DeleteFolder(UserId.Me, folderId); |
56 | 123 | } |
57 | 124 |
|
58 | 125 | private static void AssertPagingNext<T>(Paginated<T> paginated) where T:class |
|
0 commit comments