├── README.md
├── .gitignore
├── Contentful.Net.CMA
├── Contentful.Net.CMA.csproj
├── XunitUtilities.cs
└── CMATests.cs
├── Contentful.Net.Integration
├── Contentful.Net.Integration.csproj
└── CDATests.cs
└── Contentful.Net.Integration.sln
/README.md:
--------------------------------------------------------------------------------
1 | # Contentful.Net.Integration
2 | Repository that runs integration tests for the .Net SDK.
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Bb]in/
2 | [Oo]bj/
3 | *.suo
4 | *.user
5 | *.userprefs
6 | _ReSharper.*
7 | *.ReSharper.user
8 | *.resharper.user
9 | .vs/
10 | .vscode/
11 | Backup/
12 | *.lock.json
13 | *.nuget.props
14 | *.nuget.targets
15 | *.orig
16 |
--------------------------------------------------------------------------------
/Contentful.Net.CMA/Contentful.Net.CMA.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.1
5 |
6 |
7 |
8 | 3.1.1
9 |
10 |
11 | 1.0.0-alpha-20161104-2
12 | All
13 |
14 |
15 | 15.6.0
16 |
17 |
18 | 2.3.1
19 |
20 |
21 | 2.3.1
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Contentful.Net.Integration/Contentful.Net.Integration.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.1
5 |
6 |
7 |
8 | 3.1.1
9 |
10 |
11 | 1.0.0-alpha-20161104-2
12 | All
13 |
14 |
15 | 15.6.0
16 |
17 |
18 | 2.3.1
19 |
20 |
21 | 2.3.1
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Contentful.Net.Integration.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.25928.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contentful.Net.Integration", "Contentful.Net.Integration\Contentful.Net.Integration.csproj", "{90A0AA3A-4542-4E99-8C12-B014311C171D}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contentful.Net.CMA", "Contentful.Net.CMA\Contentful.Net.CMA.csproj", "{D748747A-AD75-49BE-A935-0E18174795C9}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {90A0AA3A-4542-4E99-8C12-B014311C171D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {90A0AA3A-4542-4E99-8C12-B014311C171D}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {90A0AA3A-4542-4E99-8C12-B014311C171D}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {90A0AA3A-4542-4E99-8C12-B014311C171D}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {D748747A-AD75-49BE-A935-0E18174795C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {D748747A-AD75-49BE-A935-0E18174795C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {D748747A-AD75-49BE-A935-0E18174795C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {D748747A-AD75-49BE-A935-0E18174795C9}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Contentful.Net.CMA/XunitUtilities.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Xunit;
5 | using Xunit.Abstractions;
6 | using System.Reflection;
7 | using System.Linq;
8 | using Xunit.Sdk;
9 | using System.Collections.Concurrent;
10 |
11 | namespace Contentful.Net.CMA
12 | {
13 | public class OrderAttribute : Attribute
14 | {
15 | public int I { get; }
16 |
17 | public OrderAttribute(int i)
18 | {
19 | I = i;
20 | }
21 | }
22 |
23 | public class CustomTestCollectionOrderer : ITestCollectionOrderer
24 | {
25 | public const string TypeName = "Contentful.Net.CMA.CustomTestCollectionOrderer";
26 |
27 | public const string AssembyName = "Contentful.Net.CMA";
28 |
29 | public IEnumerable OrderTestCollections(
30 | IEnumerable testCollections)
31 | {
32 | return testCollections.OrderBy(GetOrder);
33 | }
34 |
35 | ///
36 | /// Test collections are not bound to a specific class, however they
37 | /// are named by default with the type name as a suffix. We try to
38 | /// get the class name from the DisplayName and then use reflection to
39 | /// find the class and OrderAttribute.
40 | ///
41 | private static int GetOrder(
42 | ITestCollection testCollection)
43 | {
44 | var i = testCollection.DisplayName.LastIndexOf(' ');
45 | if (i <= -1)
46 | return 0;
47 |
48 | var className = testCollection.DisplayName.Substring(i + 1);
49 | var type = Type.GetType(className);
50 | if (type == null)
51 | return 0;
52 |
53 | var attr = type.GetTypeInfo().GetCustomAttribute();
54 | return attr?.I ?? 0;
55 | }
56 | }
57 |
58 | public class CustomTestCaseOrderer : ITestCaseOrderer
59 | {
60 | public const string TypeName = "Contentful.Net.CMA.CustomTestCaseOrderer";
61 |
62 | public const string AssembyName = "Contentful.Net.CMA";
63 |
64 | public static readonly ConcurrentDictionary>
65 | QueuedTests = new ConcurrentDictionary>();
66 |
67 | public IEnumerable OrderTestCases(
68 | IEnumerable testCases)
69 | where TTestCase : ITestCase
70 | {
71 | return testCases.OrderBy(GetOrder);
72 | }
73 |
74 | private static int GetOrder(
75 | TTestCase testCase)
76 | where TTestCase : ITestCase
77 | {
78 | // Enqueue the test name.
79 | QueuedTests
80 | .GetOrAdd(
81 | testCase.TestMethod.TestClass.Class.Name,
82 | key => new ConcurrentQueue())
83 | .Enqueue(testCase.TestMethod.Method.Name);
84 |
85 | // Order the test based on the attribute.
86 | var attr = testCase.TestMethod.Method
87 | .ToRuntimeMethod()
88 | .GetCustomAttribute();
89 | return attr?.I ?? 0;
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Contentful.Net.Integration/CDATests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using Contentful.Core;
4 | using System.Net.Http;
5 | using Contentful.Core.Configuration;
6 | using System.Threading.Tasks;
7 | using Contentful.Core.Models;
8 | using System.Linq;
9 | using Contentful.Core.Search;
10 | using System.Threading;
11 |
12 | namespace Contentful.Net.Integration
13 | {
14 | public class ContentfulCDATests
15 | {
16 | private ContentfulClient _client;
17 |
18 | public ContentfulCDATests()
19 | {
20 | var httpClient = new HttpClient(new TestEndpointMessageHandler());
21 |
22 | _client = new ContentfulClient(httpClient, new ContentfulOptions()
23 | {
24 | DeliveryApiKey = "b4c0n73n7fu1",
25 | ManagementApiKey = "",
26 | SpaceId = "cfexampleapi",
27 | UsePreviewApi = false
28 | });
29 | }
30 |
31 | [Fact]
32 | public async Task GetAllEntries()
33 | {
34 | var entries = await _client.GetEntries();
35 |
36 | Assert.Equal(10, entries.Count());
37 | }
38 |
39 | [Fact]
40 | public async Task GetContentTypes()
41 | {
42 | var contentTypes = await _client.GetContentTypes();
43 |
44 | Assert.Equal(4, contentTypes.Count());
45 | }
46 |
47 | [Theory]
48 | [InlineData("cat", 8, "Meow.", "name")]
49 | [InlineData("1t9IbcfdCk6m04uISSsaIK", 2, null, "name")]
50 | [InlineData("dog", 3, "Bark!", "name")]
51 | public async Task GetContentTypeById(string id, int expectedFieldLength, string expectedDescription, string expectedDisplayField)
52 | {
53 | var contentType = await _client.GetContentType(id);
54 |
55 | Assert.Equal(expectedFieldLength, contentType.Fields.Count);
56 | Assert.Equal(expectedDescription, contentType.Description);
57 | Assert.Equal(expectedDisplayField, contentType.DisplayField);
58 | }
59 |
60 | [Theory]
61 | [InlineData("nyancat", "Nyan Cat", "rainbow")]
62 | [InlineData("happycat", "Happy Cat", "gray")]
63 | public async Task GetSpecificEntries(string id, string expectedName, string expectedColor)
64 | {
65 | var entry = await _client.GetEntry(id);
66 |
67 | Assert.Equal(expectedName, entry.name.ToString());
68 | Assert.Equal(expectedColor, entry.color.ToString());
69 | }
70 |
71 | [Fact]
72 | public async Task GetSpace()
73 | {
74 | var space = await _client.GetSpace();
75 |
76 | Assert.Equal("Contentful Example API", space.Name);
77 | Assert.Equal("cfexampleapi", space.SystemProperties.Id);
78 | Assert.Equal(2, space.Locales.Count);
79 | Assert.Equal("en-US", space.Locales.Single(c => c.Default).Code);
80 | }
81 |
82 | [Fact]
83 | public async Task GetAssets()
84 | {
85 | var assets = await _client.GetAssets();
86 |
87 | Assert.Equal(4, assets.Count());
88 | Assert.Contains(assets, c => c.Title == "Doge");
89 | Assert.Contains(assets, c => c.Title == "Happy Cat");
90 | Assert.Contains(assets, c => c.Title == "Nyan Cat");
91 | Assert.Contains(assets, c => c.Title == "Jake");
92 | }
93 |
94 | [Theory]
95 | [InlineData("1x0xpXu4pSGS4OukSyWGUK", "Doge" ,"nice picture")]
96 | [InlineData("happycat", "Happy Cat", null)]
97 | [InlineData("nyancat", "Nyan Cat", null)]
98 | [InlineData("jake", "Jake", null)]
99 | public async Task GetSpecificAsset(string id, string expectedTitle, string expectedDescription)
100 | {
101 | var asset = await _client.GetAsset(id);
102 |
103 | Assert.Equal(expectedTitle, asset.Title);
104 | Assert.Equal(expectedDescription, asset.Description);
105 | }
106 |
107 | [Fact]
108 | public async Task SyncInitial()
109 | {
110 | var res = await _client.SyncInitial(SyncType.Asset);
111 |
112 | Assert.Equal(4, res.Assets.Count());
113 | }
114 |
115 | [Fact]
116 | public async Task SyncInitialWithContentType()
117 | {
118 | var res = await _client.SyncInitial(SyncType.Entry, "cat");
119 |
120 | Assert.Equal(3, res.Entries.Count());
121 | }
122 |
123 | [Fact]
124 | public async Task SyncNextResult()
125 | {
126 | var res = await _client.SyncInitial(SyncType.Entry);
127 |
128 | var nextResult = await _client.SyncNextResult(res.NextSyncUrl);
129 |
130 | Assert.Empty(nextResult.Entries);
131 | }
132 |
133 | [Fact]
134 | public async Task GetEntriesByContentType()
135 | {
136 | var res = await _client.GetEntries(QueryBuilder.New.ContentTypeIs("cat"));
137 |
138 | Assert.Equal(3, res.Count());
139 | }
140 |
141 | [Fact]
142 | public async Task GetEntriesByField()
143 | {
144 | var res = await _client.GetEntries(QueryBuilder.New.FieldEquals("sys.id", "nyancat"));
145 |
146 | Assert.Single(res);
147 | Assert.Equal("rainbow", res.First().color.ToString());
148 | }
149 |
150 | [Fact]
151 | public async Task GetEntriesByFieldNotEquals()
152 | {
153 | var res = await _client.GetEntries(QueryBuilder.New.FieldDoesNotEqual("sys.id", "nyancat"));
154 |
155 | Assert.Equal(9, res.Count());
156 | }
157 |
158 | [Fact]
159 | public async Task GetEntriesByFieldAndType()
160 | {
161 | var res = await _client.GetEntries(QueryBuilder.New.ContentTypeIs("cat").FieldEquals("fields.color", "rainbow"));
162 |
163 | Assert.Single(res);
164 | Assert.Equal("rainbow", res.First().color.ToString());
165 | Assert.Equal("nyancat", res.First().sys.id.ToString());
166 | }
167 |
168 | [Fact]
169 | public async Task GetEntriesByFieldIncludes()
170 | {
171 | var res = await _client.GetEntries(QueryBuilder.New.FieldIncludes("sys.id", new[] { "nyancat", "jake" }));
172 |
173 | Assert.Equal(2, res.Count());
174 | Assert.Contains(res, c => c.color?.ToString() == "rainbow");
175 | Assert.Contains(res, c => c.name?.ToString() == "Jake");
176 | }
177 |
178 | [Fact]
179 | public async Task GetEntriesByFieldIncludesAndType()
180 | {
181 | var res = await _client.GetEntries(QueryBuilder.New
182 | .ContentTypeIs("cat").FieldIncludes("fields.color", new[] { "rainbow", "gray" }));
183 |
184 | Assert.Equal(2, res.Count());
185 | Assert.Equal("rainbow", res.Last().color.ToString());
186 | Assert.Equal("nyancat", res.Last().sys.id.ToString());
187 | Assert.Equal("gray", res.First().color.ToString());
188 | Assert.Equal("happycat", res.First().sys.id.ToString());
189 | }
190 |
191 | [Fact]
192 | public async Task GetEntriesByFieldExcludesAndType()
193 | {
194 | var res = await _client.GetEntries(QueryBuilder.New
195 | .ContentTypeIs("cat").FieldExcludes("fields.color", new[] { "rainbow", "gray" }));
196 |
197 | Assert.Single(res);
198 | Assert.Equal("orange", res.Last().color.ToString());
199 | Assert.Equal("garfield", res.Last().sys.id.ToString());
200 | }
201 |
202 | [Fact]
203 | public async Task GetEntriesByFieldExistsAndType()
204 | {
205 | var res = await _client.GetEntries(QueryBuilder.New
206 | .ContentTypeIs("cat").FieldExists("fields.color"));
207 |
208 | Assert.Equal(3, res.Count());
209 | }
210 |
211 | [Fact]
212 | public async Task GetEntriesByFieldLessThanOrEqualTo()
213 | {
214 | var res = await _client.GetEntries(QueryBuilder.New.FieldLessThanOrEqualTo("sys.createdAt", "2013-08-28"));
215 |
216 | Assert.Equal(5, res.Count());
217 | Assert.Contains(res, c => c.sys.id.ToString() == "nyancat");
218 | }
219 |
220 | [Fact]
221 | public async Task GetEntriesByFieldGreaterThanOrEqualTo()
222 | {
223 | var res = await _client.GetEntries(QueryBuilder.New.FieldGreaterThanOrEqualTo("sys.createdAt", "2013-08-28"));
224 |
225 | Assert.Equal(5, res.Count());
226 | Assert.DoesNotContain(res, c => c.sys.id.ToString() == "nyancat");
227 | }
228 |
229 | [Fact]
230 | public async Task GetEntriesByQuery()
231 | {
232 | var res = await _client.GetEntries(QueryBuilder.New.FullTextSearch("nyan"));
233 |
234 | Assert.Single(res);
235 | Assert.Contains(res, c => c.sys.id.ToString() == "nyancat");
236 | }
237 |
238 | [Fact]
239 | public async Task GetEntriesByFieldMatchesAndType()
240 | {
241 | var res = await _client.GetEntries(QueryBuilder.New
242 | .ContentTypeIs("cat").FieldMatches("fields.color", "rain"));
243 |
244 | Assert.Single(res);
245 | Assert.Equal("rainbow", res.Last().color.ToString());
246 | Assert.Equal("nyancat", res.Last().sys.id.ToString());
247 | }
248 |
249 | [Fact]
250 | public async Task GetEntriesByNearByAndType()
251 | {
252 | var res = await _client.GetEntries(QueryBuilder.New
253 | .ContentTypeIs("1t9IbcfdCk6m04uISSsaIK").InProximityOf("fields.center", "38,-122"));
254 |
255 | Assert.Equal(4, res.Count());
256 |
257 | Assert.Collection(res,
258 | (c) => Assert.Equal("San Francisco", c.name.ToString()),
259 | (c) => Assert.Equal("London", c.name.ToString()),
260 | (c) => Assert.Equal("Paris", c.name.ToString()),
261 | (c) => Assert.Equal("Berlin", c.name.ToString()));
262 | }
263 |
264 | [Fact]
265 | public async Task GetEntriesByWithinAreaAndType()
266 | {
267 | var res = await _client.GetEntries(QueryBuilder.New
268 | .ContentTypeIs("1t9IbcfdCk6m04uISSsaIK").WithinArea("fields.center", "40", "-124", "36", "-120"));
269 |
270 | Assert.Single(res);
271 |
272 | Assert.Collection(res,
273 | (c) => Assert.Equal("San Francisco", c.name.ToString()));
274 | }
275 |
276 | [Fact]
277 | public async Task GetEntriesAndOrder()
278 | {
279 | var res = await _client.GetEntries(QueryBuilder.New
280 | .OrderBy(SortOrderBuilder.New("sys.createdAt").Build()));
281 |
282 | Assert.Equal(10, res.Count());
283 | Assert.Equal("Nyan Cat", res.First().name.ToString());
284 | }
285 |
286 | [Fact]
287 | public async Task GetEntriesAndOrderReversed()
288 | {
289 | var res = await _client.GetEntries(QueryBuilder.New
290 | .OrderBy(SortOrderBuilder.New("sys.createdAt", SortOrder.Reversed).Build()));
291 |
292 | Assert.Equal(10, res.Count());
293 | Assert.Equal("San Francisco", res.First().name.ToString());
294 | }
295 |
296 | [Fact]
297 | public async Task GetEntriesAndOrderSeveral()
298 | {
299 | var res = await _client.GetEntries(QueryBuilder.New
300 | .OrderBy(SortOrderBuilder.New("sys.createdAt").ThenBy("sys.updatedAt").Build()));
301 |
302 | Assert.Equal(10, res.Count());
303 | Assert.Equal("Nyan Cat", res.First().name.ToString());
304 | }
305 |
306 | [Fact]
307 | public async Task GetEntriesAndLimit()
308 | {
309 | var res = await _client.GetEntries(QueryBuilder.New.Limit(3));
310 |
311 | Assert.Equal(3, res.Count());
312 | Assert.Equal(10, res.Total);
313 | }
314 |
315 | [Fact]
316 | public async Task GetEntriesAndSkip()
317 | {
318 | var res = await _client.GetEntries(QueryBuilder.New.Skip(3));
319 |
320 | Assert.Equal(7, res.Count());
321 | Assert.Equal(10, res.Total);
322 | }
323 |
324 | [Fact]
325 | public async Task GetEntriesAndInclude()
326 | {
327 | var res = await _client.GetEntries(QueryBuilder.New.Include(3));
328 |
329 | Assert.Equal(10, res.Count());
330 | Assert.Equal(10, res.Total);
331 | Assert.Equal(4, res.IncludedAssets.Count());
332 | }
333 |
334 | [Fact]
335 | public async Task GetEntriesByFieldLinking()
336 | {
337 | var res = await _client.GetEntries(QueryBuilder.New.ContentTypeIs("cat").FieldEquals("fields.bestFriend.sys.id", "nyancat"));
338 |
339 | Assert.Single(res);
340 | Assert.Equal("gray", res.First().color.ToString());
341 | }
342 |
343 | [Fact]
344 | public async Task GetEntriesByLinksToEntry()
345 | {
346 | var res = await _client.GetEntries(QueryBuilder.New.LinksToEntry("nyancat"));
347 |
348 | Assert.Single(res);
349 | Assert.Equal("gray", res.First().color.ToString());
350 | }
351 |
352 | [Fact]
353 | public async Task GetEntriesByLinksToAsset()
354 | {
355 | var res = await _client.GetEntries(QueryBuilder.New.LinksToAsset("nyancat"));
356 |
357 | Assert.Single(res);
358 | Assert.Equal("rainbow", res.First().color.ToString());
359 | }
360 |
361 | [Theory]
362 | [InlineData(MimeTypeRestriction.Image, 4)]
363 | [InlineData(MimeTypeRestriction.Archive, 0)]
364 | [InlineData(MimeTypeRestriction.Presentation, 0)]
365 | public async Task GetAssetsByMimeType(MimeTypeRestriction restriction, int expectedAssets)
366 | {
367 | var res = await _client.GetAssets(QueryBuilder.New.MimeTypeIs(restriction));
368 |
369 | Assert.Equal(expectedAssets, res.Count());
370 | }
371 |
372 | [Theory]
373 | [InlineData("en-US", "Nyan Cat")]
374 | [InlineData("tlh", "Nyan vIghro'")]
375 | public async Task GetEntryByLocale(string locale, string expectedName)
376 | {
377 | var res = await _client.GetEntry("nyancat", QueryBuilder.New.LocaleIs(locale));
378 |
379 | Assert.Equal(expectedName, res.name.ToString());
380 | Assert.Equal("rainbow", res.color.ToString());
381 | }
382 | }
383 |
384 | public class TestEndpointMessageHandler : HttpClientHandler
385 | {
386 | protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
387 | {
388 | if(Environment.GetEnvironmentVariable("CONTENTFUL_RUN_WITHOUT_PROXY") == "true")
389 | {
390 | return await base.SendAsync(request, cancellationToken);
391 | }
392 |
393 | var requestUrl = request.RequestUri.ToString();
394 |
395 | requestUrl = requestUrl
396 | .Replace("https://cdn.contentful.com/", "http://127.0.0.1:5000/");
397 |
398 | request.RequestUri = new Uri(requestUrl);
399 |
400 | return await base.SendAsync(request, cancellationToken);
401 | }
402 | }
403 | }
404 |
--------------------------------------------------------------------------------
/Contentful.Net.CMA/CMATests.cs:
--------------------------------------------------------------------------------
1 | using Contentful.Core;
2 | using Contentful.Core.Configuration;
3 | using Contentful.Core.Errors;
4 | using Contentful.Core.Models;
5 | using Contentful.Core.Models.Management;
6 | using Contentful.Net.CMA;
7 | using Newtonsoft.Json;
8 | using Newtonsoft.Json.Linq;
9 | using System;
10 | using System.Collections.Generic;
11 | using System.Linq;
12 | using System.Net.Http;
13 | using System.Text;
14 | using System.Threading;
15 | using System.Threading.Tasks;
16 | using Xunit;
17 |
18 | namespace Contentful.Net.Integration
19 | {
20 | [TestCaseOrderer("Contentful.Net.CMA.CustomTestCaseOrderer", "Contentful.Net.CMA")]
21 | public class ContentfulCMATests : IClassFixture
22 | {
23 | private ContentfulManagementClient _client;
24 | private string _spaceId = "";
25 | private string _contentTypeId = "contenttype";
26 | private string _roleId = "";
27 | private string _environmentId = "some-env";
28 |
29 | public ContentfulCMATests(SpaceFixture fixture)
30 | {
31 |
32 | var httpClient = new HttpClient(new TestEndpointMessageHandler());
33 | var managementToken = Environment.GetEnvironmentVariable("CONTENTFUL_ACCESS_TOKEN");
34 | _spaceId = fixture.SpaceId;
35 | _client = new ContentfulManagementClient(httpClient, new ContentfulOptions()
36 | {
37 | DeliveryApiKey = "123",
38 | ManagementApiKey = managementToken,
39 | SpaceId = fixture.SpaceId,
40 | UsePreviewApi = false
41 | });
42 |
43 | }
44 |
45 | [Fact]
46 | [Order(5)]
47 | public async Task GetASpace()
48 | {
49 | var space = await _client.GetSpace(_spaceId);
50 |
51 | Assert.Equal("dotnet-test-space", space.Name);
52 | }
53 |
54 | [Fact]
55 | [Order(10)]
56 | public async Task GetAllSpaces()
57 | {
58 | var spaces = await _client.GetSpaces();
59 |
60 | Assert.Contains(spaces, c => c.Name == "blog space");
61 | }
62 |
63 | [Fact]
64 | [Order(20)]
65 | public async Task UpdateSpaceName()
66 | {
67 | var space = await _client.UpdateSpaceName(_spaceId, "knuckleburger", 1);
68 | Assert.Equal("knuckleburger", space.Name);
69 | space.Name = "dotnet-test-space";
70 | space = await _client.UpdateSpaceName(space);
71 | Assert.Equal("dotnet-test-space", space.Name);
72 | }
73 |
74 | [Fact]
75 | [Order(25)]
76 | public async Task CreateContentType()
77 | {
78 | var contentType = new ContentType();
79 | contentType.SystemProperties = new SystemProperties()
80 | {
81 | Id = _contentTypeId
82 | };
83 | contentType.Name = "Cool content";
84 | contentType.Fields = new List()
85 | {
86 | new Field()
87 | {
88 | Name = "Field1",
89 | Id = "field1",
90 | @Type = "Text"
91 | },
92 | new Field()
93 | {
94 | Name = "Field2",
95 | Id = "field2",
96 | @Type = "Text"
97 | }
98 | };
99 |
100 | var contenttype = await _client.CreateOrUpdateContentType(contentType, _spaceId);
101 |
102 | Assert.Equal(2, contenttype.Fields.Count);
103 | }
104 |
105 | [Fact]
106 | [Order(30)]
107 | public async Task UpdateContentType()
108 | {
109 | var contentType = new ContentType();
110 | contentType.SystemProperties = new SystemProperties()
111 | {
112 | Id = _contentTypeId
113 | };
114 | contentType.Name = "Cool content changed";
115 | contentType.Fields = new List()
116 | {
117 | new Field()
118 | {
119 | Name = "Field1",
120 | Id = "field1",
121 | @Type = "Text"
122 | },
123 | new Field()
124 | {
125 | Name = "Field2",
126 | Id = "field2",
127 | @Type = "Text"
128 | }
129 | };
130 |
131 | var updatedContentType = await _client.CreateOrUpdateContentType(contentType, _spaceId, version: 1);
132 |
133 | Assert.Equal(2, updatedContentType.Fields.Count);
134 | Assert.Equal("Cool content changed", updatedContentType.Name);
135 | }
136 |
137 | [Fact]
138 | [Order(40)]
139 | public async Task GetContentType()
140 | {
141 | var contentType = await _client.GetContentType(_contentTypeId, _spaceId);
142 |
143 | Assert.Equal(_contentTypeId, contentType.SystemProperties.Id);
144 | }
145 |
146 | [Fact]
147 | [Order(50)]
148 | public async Task GetAllContentTypes()
149 | {
150 | //It seems we need to give the API a chance to catch up...
151 | Thread.Sleep(5000);
152 | var contentTypes = await _client.GetContentTypes();
153 |
154 | Assert.Single(contentTypes);
155 | }
156 |
157 | [Fact]
158 | [Order(60)]
159 | public async Task PublishContentType()
160 | {
161 | var contentType = await _client.ActivateContentType(_contentTypeId, 2);
162 |
163 | Assert.Equal(3, contentType.SystemProperties.Version);
164 | }
165 |
166 | [Fact]
167 | [Order(80)]
168 | public async Task CreateEntry()
169 | {
170 | var entry = new Entry();
171 |
172 | entry.SystemProperties = new SystemProperties()
173 | {
174 | Id = "entry1"
175 | };
176 |
177 | entry.Fields = new JObject
178 | (
179 | new JProperty("field1", new JObject(new JProperty("en-US", "bla"))),
180 | new JProperty("field2", new JObject(new JProperty("en-US", "blue")))
181 | );
182 |
183 | entry = await _client.CreateOrUpdateEntry(entry, contentTypeId: _contentTypeId);
184 |
185 | Assert.Equal("bla", entry.Fields.field1["en-US"].ToString());
186 | }
187 |
188 | [Fact]
189 | [Order(85)]
190 | public async Task CreateEntryWithoutId()
191 | {
192 | var entry = new Entry();
193 |
194 | entry.Fields = new JObject
195 | (
196 | new JProperty("field1", new JObject(new JProperty("en-US", "bla"))),
197 | new JProperty("field2", new JObject(new JProperty("en-US", "blue")))
198 | );
199 |
200 | entry = await _client.CreateEntry(entry, contentTypeId: _contentTypeId);
201 |
202 | Assert.Equal("bla", entry.Fields.field1["en-US"].ToString());
203 |
204 | await _client.DeleteEntry(entry.SystemProperties.Id, entry.SystemProperties.Version.Value);
205 | }
206 |
207 | [Fact]
208 | [Order(90)]
209 | public async Task GetAllEntries()
210 | {
211 | //It seems we need to give the API a chance to catch up...
212 | Thread.Sleep(10000);
213 | var entries = await _client.GetEntriesCollection();
214 |
215 | Assert.Single(entries);
216 | }
217 |
218 | [Fact]
219 | [Order(100)]
220 | public async Task GetEntry()
221 | {
222 | var entry = await _client.GetEntry("entry1");
223 |
224 | Assert.Equal(1, entry.SystemProperties.Version);
225 | Assert.Equal("bla", entry.Fields.field1["en-US"].ToString());
226 | }
227 |
228 | [Fact]
229 | [Order(110)]
230 | public async Task PublishEntry()
231 | {
232 | var entry = await _client.PublishEntry("entry1", 1);
233 |
234 | Assert.Equal(2, entry.SystemProperties.Version);
235 | Assert.Equal("bla", entry.Fields.field1["en-US"].ToString());
236 | }
237 |
238 | [Fact]
239 | [Order(120)]
240 | public async Task UnpublishEntry()
241 | {
242 | var entry = await _client.UnpublishEntry("entry1", 2);
243 |
244 | Assert.Equal(3, entry.SystemProperties.Version);
245 | Assert.Equal("bla", entry.Fields.field1["en-US"].ToString());
246 | }
247 |
248 | [Fact]
249 | [Order(130)]
250 | public async Task ArchiveEntry()
251 | {
252 | var entry = await _client.ArchiveEntry("entry1", 3);
253 |
254 | Assert.Equal(4, entry.SystemProperties.Version);
255 | Assert.Equal("bla", entry.Fields.field1["en-US"].ToString());
256 | }
257 |
258 | [Fact]
259 | [Order(140)]
260 | public async Task UnarchiveEntry()
261 | {
262 | var entry = await _client.UnarchiveEntry("entry1", 4);
263 |
264 | Assert.Equal(5, entry.SystemProperties.Version);
265 | Assert.Equal("bla", entry.Fields.field1["en-US"].ToString());
266 | }
267 |
268 | [Fact]
269 | [Order(145)]
270 | public async Task GetAssets()
271 | {
272 | var assets = await _client.GetAssetsCollection();
273 |
274 | Assert.Empty(assets);
275 |
276 | var publishedAssets = await _client.GetPublishedAssetsCollection();
277 |
278 | Assert.Empty(publishedAssets);
279 | }
280 |
281 | [Fact]
282 | [Order(150)]
283 | public async Task CreateAsset()
284 | {
285 | var asset = new ManagementAsset();
286 | asset.SystemProperties = new SystemProperties()
287 | {
288 | Id = "asset1"
289 | };
290 | asset.Title = new Dictionary()
291 | {
292 | { "en-US", "AssetMaster" }
293 | };
294 | asset.Files = new Dictionary
295 | {
296 | { "en-US", new File()
297 | {
298 | ContentType ="image/jpeg",
299 | FileName = "moby.png",
300 | UploadUrl = "https://robertlinde.se/assets/top/moby-top.png"
301 | }
302 | }
303 | };
304 |
305 | var createdAsset = await _client.CreateOrUpdateAsset(asset);
306 |
307 | Assert.Equal("AssetMaster", createdAsset.Title["en-US"]);
308 | }
309 |
310 | [Fact]
311 | [Order(155)]
312 | public async Task CreateAssetWithoutId()
313 | {
314 | var asset = new ManagementAsset();
315 |
316 | asset.Title = new Dictionary()
317 | {
318 | { "en-US", "AssetMaster" }
319 | };
320 | asset.Files = new Dictionary
321 | {
322 | { "en-US", new File()
323 | {
324 | ContentType ="image/jpeg",
325 | FileName = "moby.png",
326 | UploadUrl = "https://robertlinde.se/assets/top/moby-top.png"
327 | }
328 | }
329 | };
330 |
331 | var createdAsset = await _client.CreateAsset(asset);
332 |
333 | Assert.Equal("AssetMaster", createdAsset.Title["en-US"]);
334 | }
335 |
336 | [Fact]
337 | [Order(160)]
338 | public async Task GetAsset()
339 | {
340 | var asset = await _client.GetAsset("asset1");
341 |
342 | Assert.Equal("AssetMaster", asset.Title["en-US"]);
343 | }
344 |
345 | [Fact]
346 | [Order(170)]
347 | public async Task ProcessAsset()
348 | {
349 | await _client.ProcessAsset("asset1",1 , "en-US");
350 |
351 | Assert.True(true);
352 | }
353 |
354 | [Fact]
355 | [Order(180)]
356 | public async Task PublishAsset()
357 | {
358 | //Give processing a chance to finish...
359 | Thread.Sleep(5000);
360 | ManagementAsset asset = null;
361 |
362 | asset = await _client.PublishAsset("asset1", 2);
363 |
364 | Assert.Equal("AssetMaster", asset.Title["en-US"]);
365 | }
366 |
367 | [Fact]
368 | [Order(190)]
369 | public async Task UnpublishAsset()
370 | {
371 | var asset = await _client.UnpublishAsset("asset1", 3);
372 |
373 | Assert.Equal("AssetMaster", asset.Title["en-US"]);
374 | }
375 |
376 | [Fact]
377 | [Order(200)]
378 | public async Task ArchiveAsset()
379 | {
380 | var asset = await _client.ArchiveAsset("asset1", 4);
381 |
382 | Assert.Equal("AssetMaster", asset.Title["en-US"]);
383 | }
384 |
385 | [Fact]
386 | [Order(210)]
387 | public async Task UnarchiveAsset()
388 | {
389 | var asset = await _client.UnarchiveAsset("asset1", 5);
390 |
391 | Assert.Equal("AssetMaster", asset.Title["en-US"]);
392 | }
393 |
394 | [Fact]
395 | [Order(220)]
396 | public async Task GetLocales()
397 | {
398 | var locales = await _client.GetLocalesCollection();
399 |
400 | Assert.Equal(1, locales.Total);
401 | }
402 |
403 | [Fact]
404 | [Order(230)]
405 | public async Task CreateGetUpdateDeleteLocale()
406 | {
407 | var locale = new Locale();
408 | locale.Code = "c-sharp";
409 | locale.Name = "See Sharp";
410 | locale.FallbackCode = "en-US";
411 | locale.Optional = true;
412 | locale.ContentDeliveryApi = true;
413 | locale.ContentManagementApi = true;
414 |
415 | var createdLocale = await _client.CreateLocale(locale);
416 |
417 | Assert.Equal("c-sharp", createdLocale.Code);
418 |
419 | locale = await _client.GetLocale(createdLocale.SystemProperties.Id);
420 |
421 | Assert.Equal("See Sharp", locale.Name);
422 |
423 | locale.Name = "c#";
424 |
425 | locale = await _client.UpdateLocale(locale);
426 |
427 | Assert.Equal("c#", locale.Name);
428 |
429 | await _client.DeleteLocale(locale.SystemProperties.Id);
430 | }
431 |
432 | [Fact]
433 | [Order(240)]
434 | public async Task GetAllWebHooks()
435 | {
436 | var hooks = await _client.GetWebhooksCollection();
437 |
438 | Assert.Equal(0, hooks.Total);
439 | }
440 |
441 | [Fact]
442 | [Order(250)]
443 | public async Task CreateGetUpdateDeleteWebHook()
444 | {
445 | var webHook = new Webhook();
446 | webHook.Name = "Captain Hook";
447 | webHook.Url = "https://robertlinde.se";
448 | webHook.HttpBasicPassword = "Pass";
449 | webHook.HttpBasicUsername = "User";
450 | webHook.Headers = new List>();
451 | webHook.Headers.Add(new KeyValuePair("ben", "long"));
452 | webHook.Topics = new List()
453 | {
454 | "Entry.*"
455 | };
456 |
457 | var createdHook = await _client.CreateWebhook(webHook);
458 |
459 | Assert.Equal("Captain Hook", createdHook.Name);
460 |
461 | webHook.Name = "Dustin Hoffman";
462 | webHook.SystemProperties = new SystemProperties()
463 | {
464 | Id = createdHook.SystemProperties.Id
465 | };
466 |
467 | var updatedHook = await _client.CreateOrUpdateWebhook(webHook);
468 |
469 | Assert.Equal("Dustin Hoffman", updatedHook.Name);
470 |
471 | webHook = await _client.GetWebhook(updatedHook.SystemProperties.Id);
472 |
473 | Assert.Equal("Dustin Hoffman", webHook.Name);
474 |
475 | var calls = await _client.GetWebhookCallDetailsCollection(webHook.SystemProperties.Id);
476 |
477 | Assert.Empty(calls);
478 |
479 | await Assert.ThrowsAsync(async () => await _client.GetWebhookCallDetails("XXX", webHook.SystemProperties.Id));
480 |
481 | var health = await _client.GetWebhookHealth(webHook.SystemProperties.Id);
482 |
483 | await _client.DeleteWebhook(updatedHook.SystemProperties.Id);
484 | }
485 |
486 | [Fact]
487 | [Order(610)]
488 | public async Task GetApiKeys()
489 | {
490 | var keys = await _client.GetAllApiKeys();
491 |
492 | Assert.Equal(0, keys.Total);
493 | }
494 |
495 | [Fact]
496 | [Order(620)]
497 | public async Task CreateApiKey()
498 | {
499 | var createdKey = await _client.CreateApiKey("Keyport", "blahblah");
500 |
501 | Assert.Equal("Keyport", createdKey.Name);
502 | Assert.NotNull(createdKey.AccessToken);
503 | }
504 |
505 | [Fact]
506 | [Order(600)]
507 | public async Task DeleteEntry()
508 | {
509 | await _client.DeleteEntry("entry1", 1);
510 | }
511 |
512 | [Fact]
513 | [Order(610)]
514 | public async Task DeleteAsset()
515 | {
516 | await _client.DeleteAsset("asset1", 5);
517 | }
518 |
519 | [Fact]
520 | [Order(620)]
521 | public async Task GetExtensions()
522 | {
523 | var res = await _client.GetAllExtensions();
524 |
525 | Assert.Empty(res);
526 | }
527 |
528 | [Fact]
529 | [Order(630)]
530 | public async Task CreateExtension()
531 | {
532 | var extension = new UiExtension
533 | {
534 | Name = "Test",
535 | FieldTypes = new List { SystemFieldTypes.Boolean },
536 | Sidebar = false,
537 | Src = "https://robertlinde.se"
538 | };
539 |
540 | var res = await _client.CreateExtension(extension);
541 |
542 | Assert.Equal("Test", res.Name);
543 | }
544 |
545 | [Fact]
546 | [Order(640)]
547 | public async Task UpdateExtension()
548 | {
549 | var extension = new UiExtension
550 | {
551 | Name = "Test2",
552 | FieldTypes = new List { SystemFieldTypes.Boolean },
553 | Sidebar = false,
554 | Src = "https://robertlinde.se",
555 | SystemProperties = new SystemProperties
556 | {
557 | Id = "test"
558 | }
559 | };
560 |
561 | var res = await _client.CreateOrUpdateExtension(extension);
562 |
563 | Assert.Equal("Test2", res.Name);
564 | }
565 |
566 | [Fact]
567 | [Order(650)]
568 | public async Task GetExtension()
569 | {
570 | var res = await _client.GetExtension("test");
571 |
572 | Assert.Equal("Test2", res.Name);
573 | }
574 |
575 | [Fact]
576 | [Order(660)]
577 | public async Task DeleteExtension()
578 | {
579 | await _client.DeleteExtension("test");
580 | }
581 |
582 | [Fact]
583 | [Order(660)]
584 | public async Task GetOrganizations()
585 | {
586 | var res = await _client.GetOrganizations();
587 |
588 | Assert.NotEmpty(res);
589 | }
590 |
591 | [Fact]
592 | [Order(670)]
593 | public async Task GetEditorInterfaces()
594 | {
595 | var res = await _client.GetEditorInterface(_contentTypeId);
596 |
597 | Assert.Equal(2, res.Controls.Count);
598 | }
599 |
600 | [Fact]
601 | [Order(680)]
602 | public async Task UpdateEditorInterfaces()
603 | {
604 | var ei = await _client.GetEditorInterface(_contentTypeId);
605 |
606 | var res = await _client.UpdateEditorInterface(ei, _contentTypeId, ei.SystemProperties.Version.Value);
607 | Assert.Equal(2, res.Controls.Count);
608 | }
609 |
610 | [Fact]
611 | [Order(690)]
612 | public async Task GetRoles()
613 | {
614 | var res = await _client.GetAllRoles();
615 | _roleId = res.First().SystemProperties.Id;
616 | Assert.Equal(7, res.Count());
617 | }
618 |
619 | [Fact]
620 | [Order(700)]
621 | public async Task CreateRole()
622 | {
623 | var role = new Role
624 | {
625 | Name = "Some name",
626 | Description = "Some description",
627 | };
628 |
629 | await Assert.ThrowsAsync(async () => { await _client.CreateRole(role); });
630 | }
631 |
632 | [Fact]
633 | [Order(710)]
634 | public async Task GetRole()
635 | {
636 | var allroles = await _client.GetAllRoles();
637 | _roleId = allroles.First().SystemProperties.Id;
638 | var res = await _client.GetRole(_roleId);
639 |
640 | Assert.Equal(allroles.First().Name, res.Name);
641 | res.Name = "Author2";
642 |
643 | var updated = await _client.UpdateRole(res);
644 |
645 | await _client.DeleteRole(updated.SystemProperties.Id);
646 | }
647 |
648 | [Fact]
649 | [Order(720)]
650 | public async Task GetSnapshotsForContentType()
651 | {
652 | var snapshots = await _client.GetAllSnapshotsForContentType(_contentTypeId);
653 |
654 | var snapshot = await _client.GetSnapshotForContentType(snapshots.First().SystemProperties.Id, _contentTypeId);
655 |
656 | Assert.NotNull(snapshot);
657 | }
658 |
659 | [Fact]
660 | [Order(720)]
661 | public async Task GetSnapshotsForEntry()
662 | {
663 |
664 | var entry = new Entry();
665 |
666 | entry.Fields = new JObject
667 | (
668 | new JProperty("field1", new JObject(new JProperty("en-US", "bla"))),
669 | new JProperty("field2", new JObject(new JProperty("en-US", "blue")))
670 | );
671 |
672 | entry = await _client.CreateEntry(entry, contentTypeId: _contentTypeId);
673 |
674 | entry.Fields = new JObject
675 | (
676 | new JProperty("field1", new JObject(new JProperty("en-US", "bla2"))),
677 | new JProperty("field2", new JObject(new JProperty("en-US", "blue")))
678 | );
679 |
680 | entry = await _client.PublishEntry(entry.SystemProperties.Id, version: entry.SystemProperties.Version.Value);
681 |
682 | var snapshots = await _client.GetAllSnapshotsForEntry(entry.SystemProperties.Id);
683 |
684 | var snapshot = await _client.GetSnapshotForEntry(snapshots.First().SystemProperties.Id, entry.SystemProperties.Id);
685 |
686 | Assert.NotNull(snapshot);
687 |
688 | await _client.UnpublishEntry(entry.SystemProperties.Id, entry.SystemProperties.Version.Value);
689 |
690 | await _client.DeleteEntry(entry.SystemProperties.Id, entry.SystemProperties.Version.Value);
691 | }
692 |
693 | [Fact]
694 | [Order(720)]
695 | public async Task GetSpaceMemberships()
696 | {
697 | var sm = await _client.GetSpaceMemberships();
698 |
699 | Assert.NotEmpty(sm);
700 | }
701 |
702 | [Fact]
703 | [Order(730)]
704 | public async Task CreateSpaceMembership()
705 | {
706 | var newMembership = new SpaceMembership();
707 |
708 | newMembership.Admin = true;
709 |
710 | newMembership.User = new User()
711 | {
712 | SystemProperties = new SystemProperties()
713 | {
714 | Id = "4OyBmDxSpgUr9WWv0csvXG",
715 | LinkType = "User",
716 | Type = "Link"
717 | }
718 | };
719 |
720 | await Assert.ThrowsAsync(async () => await _client.CreateSpaceMembership(newMembership));
721 | }
722 |
723 | [Fact]
724 | [Order(720)]
725 | public async Task GetSpaceMembership()
726 | {
727 | var allMemberships = await _client.GetSpaceMemberships();
728 | var allroles = await _client.GetAllRoles();
729 |
730 | var singleMembership = await _client.GetSpaceMembership(allMemberships.First().SystemProperties.Id);
731 |
732 | singleMembership = await _client.UpdateSpaceMembership(singleMembership);
733 |
734 | await Assert.ThrowsAsync(async () => await _client.DeleteSpaceMembership("XXX"));
735 |
736 | Assert.NotNull(singleMembership);
737 | }
738 |
739 | [Fact]
740 | [Order(730)]
741 | public async Task GetAccessTokens()
742 | {
743 | var accessTokens = await _client.GetAllManagementTokens();
744 |
745 | Assert.NotEmpty(accessTokens);
746 | }
747 |
748 | [Fact]
749 | [Order(740)]
750 | public async Task CreateAccessToken()
751 | {
752 | var token = new ManagementToken
753 | {
754 | Name = "Token name",
755 | Scopes = new List {
756 | SystemManagementScopes.Manage
757 | }
758 | };
759 |
760 | var accessToken = await _client.CreateManagementToken(token);
761 |
762 | Assert.Equal("Token name", accessToken.Name);
763 |
764 | token = await _client.GetManagementToken(accessToken.SystemProperties.Id);
765 |
766 | await _client.RevokeManagementToken(accessToken.SystemProperties.Id);
767 | }
768 |
769 | [Fact]
770 | [Order(750)]
771 | public async Task GetCurrentUser()
772 | {
773 | var user = await _client.GetCurrentUser();
774 |
775 | Assert.NotNull(user);
776 | }
777 |
778 | [Fact]
779 | [Order(740)]
780 | public async Task GetEnvironments()
781 | {
782 | var envs = await _client.GetEnvironments();
783 |
784 | Assert.NotEmpty(envs);
785 | }
786 |
787 | [Fact]
788 | [Order(750)]
789 | public async Task CreateEnvironment()
790 | {
791 | var env = await _client.CreateEnvironment("useless");
792 |
793 | Assert.NotNull(env);
794 | }
795 |
796 | [Fact]
797 | [Order(760)]
798 | public async Task CreateEnvironmentById()
799 | {
800 | var env = await _client.CreateOrUpdateEnvironment(_environmentId, _environmentId);
801 |
802 | Assert.NotNull(env);
803 | }
804 |
805 | [Fact]
806 | [Order(770)]
807 | public async Task GetEnvironment()
808 | {
809 | var env = await _client.GetEnvironment(_environmentId);
810 |
811 | Assert.NotNull(env);
812 | }
813 |
814 | [Fact]
815 | [Order(780)]
816 | public async Task DeleteEnvironment()
817 | {
818 | var env = await _client.GetEnvironment(_environmentId);
819 | var count = 0;
820 | while(env.SystemProperties.Status.SystemProperties.Id != "ready" && count < 20)
821 | {
822 | Thread.Sleep(3000);
823 | env = await _client.GetEnvironment(_environmentId);
824 | count++;
825 | }
826 |
827 | await _client.DeleteEnvironment(_environmentId);
828 | }
829 |
830 | [Fact]
831 | [Order(900)]
832 | public async Task UnpublishContentType()
833 | {
834 | //It seems we need to give the API a chance to catch up...
835 | Thread.Sleep(2000);
836 | var contentTypes = await _client.GetActivatedContentTypes();
837 |
838 | Assert.Single(contentTypes);
839 | await _client.DeactivateContentType(_contentTypeId);
840 |
841 | contentTypes = await _client.GetActivatedContentTypes();
842 | Assert.Empty(contentTypes);
843 | }
844 |
845 | [Fact]
846 | [Order(920)]
847 | public async Task DeleteContentType()
848 | {
849 | await _client.DeleteContentType(_contentTypeId);
850 | }
851 |
852 | [Fact]
853 | [Order(1000)]
854 | public async Task DeleteSpace()
855 | {
856 | await _client.DeleteSpace(_spaceId);
857 | }
858 |
859 | }
860 |
861 | public class SpaceFixture : IDisposable
862 | {
863 | public string SpaceId { get; set; }
864 | private readonly ContentfulManagementClient _client;
865 | public SpaceFixture()
866 | {
867 | var httpClient = new HttpClient(new TestEndpointMessageHandler());
868 | var managementToken = Environment.GetEnvironmentVariable("CONTENTFUL_ACCESS_TOKEN");
869 | _client = new ContentfulManagementClient(httpClient, new ContentfulOptions()
870 | {
871 | DeliveryApiKey = "123",
872 | ManagementApiKey = managementToken,
873 | SpaceId = "123",
874 | UsePreviewApi = false
875 | });
876 |
877 | var space = _client.CreateSpace("dotnet-test-space", "en-US", organisation: "0w9KPTOuMqrBnj9GpkDAwF").Result;
878 |
879 | SpaceId = space.SystemProperties.Id;
880 | }
881 |
882 | public void Dispose()
883 | {
884 | try
885 | {
886 | _client.DeleteSpace(SpaceId);
887 | }
888 | catch(Exception)
889 | {
890 | //We don't really wanna do anything here,
891 | //just try to delete the space if it's left over for some reason
892 | }
893 | }
894 | }
895 |
896 | public class TestEndpointMessageHandler : HttpClientHandler
897 | {
898 | protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
899 | {
900 | if (Environment.GetEnvironmentVariable("CONTENTFUL_RUN_WITHOUT_PROXY") == "true")
901 | {
902 | return await base.SendAsync(request, cancellationToken);
903 | }
904 |
905 | var requestUrl = request.RequestUri.ToString();
906 |
907 | requestUrl = requestUrl
908 | .Replace("https://api.contentful.com/", "http://127.0.0.1:5000/");
909 |
910 | request.RequestUri = new Uri(requestUrl);
911 |
912 | return await base.SendAsync(request, cancellationToken);
913 | }
914 | }
915 | }
916 |
--------------------------------------------------------------------------------