Skip to content

Commit b75fc44

Browse files
committed
Fix folder support
1 parent 819746f commit b75fc44

8 files changed

Lines changed: 9657 additions & 55 deletions

File tree

src/VimeoDotNet.Tests/FolderTest.cs

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,125 @@
1-
using System;
21
using System.Linq;
32
using System.Threading.Tasks;
43
using Shouldly;
5-
using VimeoDotNet.Enums;
64
using VimeoDotNet.Models;
7-
using VimeoDotNet.Parameters;
85
using Xunit;
96

107
namespace VimeoDotNet.Tests
118
{
129

1310
public class FolderTest : BaseTest
1411
{
15-
private const int TotalFoldersCount = 7;
16-
private const int RootFoldersCount = 2;
17-
1812
[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()
2033
{
34+
const long userId = 2433258;
35+
MockHttpRequest(new RequestSettings
36+
{
37+
UrlSuffix = $"/users/{userId}/folders",
38+
ResponseJsonFile = "Folder.user-folder-list.json"
39+
});
2140
var client = CreateAuthenticatedClient();
22-
Paginated<Folder> folders = await client.GetUserFolders(null);
41+
var folders = await client.GetUserFolders(userId);
2342
folders.Total.ShouldBeGreaterThan(1);
24-
folders.Total.ShouldBe(TotalFoldersCount);
43+
folders.Total.ShouldBe(12);
2544
folders.PerPage.ShouldBe(25);
2645
folders.Data.Count.ShouldBeGreaterThan(1);
27-
folders.Data.Count.ShouldBeLessThanOrEqualTo(TotalFoldersCount);
46+
folders.Data.Count.ShouldBeLessThanOrEqualTo(12);
2847
AssertPagingNext(folders);
2948
folders.Paging.Previous.ShouldBeNull();
3049
}
3150

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+
3297
[Fact]
33-
public async Task ShouldCorrectlyGetRootItemsList()
98+
public async Task ShouldCorrectlyCreateFolder()
3499
{
35100
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");
46109
}
47110

48111
[Fact]
49-
public async Task ShouldCorrectlyGetFolderItemsList()
112+
public async Task ShouldCorrectlyDeleteFolder()
50113
{
114+
const long folderId = 15721704;
115+
MockHttpRequest(new RequestSettings
116+
{
117+
UrlSuffix = $"/me/projects/{folderId}",
118+
Method = RequestSettings.HttpMethod.Delete,
119+
StatusCode = 204
120+
});
51121
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);
56123
}
57124

58125
private static void AssertPagingNext<T>(Paginated<T> paginated) where T:class

0 commit comments

Comments
 (0)