-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentstack017_TaxonomyTest.cs
More file actions
125 lines (110 loc) · 4.91 KB
/
Contentstack017_TaxonomyTest.cs
File metadata and controls
125 lines (110 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Threading.Tasks;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Tests.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Contentstack.Management.Core.Tests.IntegrationTest
{
[TestClass]
public class Contentstack017_TaxonomyTest
{
private static string _taxonomyUid;
private Stack _stack;
private TaxonomyModel _createModel;
[TestInitialize]
public void Initialize()
{
StackResponse response = StackResponse.getStack(Contentstack.Client.serializer);
_stack = Contentstack.Client.Stack(response.Stack.APIKey);
if (_taxonomyUid == null)
_taxonomyUid = "taxonomy_integration_test_" + Guid.NewGuid().ToString("N").Substring(0, 8);
_createModel = new TaxonomyModel
{
Uid = _taxonomyUid,
Name = "Taxonomy Integration Test",
Description = "Description for taxonomy integration test"
};
}
[TestMethod]
[DoNotParallelize]
public void Test001_Should_Create_Taxonomy()
{
ContentstackResponse response = _stack.Taxonomy().Create(_createModel);
Assert.IsTrue(response.IsSuccessStatusCode, $"Create failed: {response.OpenResponse()}");
var wrapper = response.OpenTResponse<TaxonomyResponseModel>();
Assert.IsNotNull(wrapper?.Taxonomy);
Assert.AreEqual(_createModel.Uid, wrapper.Taxonomy.Uid);
Assert.AreEqual(_createModel.Name, wrapper.Taxonomy.Name);
Assert.AreEqual(_createModel.Description, wrapper.Taxonomy.Description);
}
[TestMethod]
[DoNotParallelize]
public void Test002_Should_Fetch_Taxonomy()
{
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Fetch();
Assert.IsTrue(response.IsSuccessStatusCode, $"Fetch failed: {response.OpenResponse()}");
var wrapper = response.OpenTResponse<TaxonomyResponseModel>();
Assert.IsNotNull(wrapper?.Taxonomy);
Assert.AreEqual(_taxonomyUid, wrapper.Taxonomy.Uid);
Assert.IsNotNull(wrapper.Taxonomy.Name);
}
[TestMethod]
[DoNotParallelize]
public void Test003_Should_Query_Taxonomies()
{
ContentstackResponse response = _stack.Taxonomy().Query().Find();
Assert.IsTrue(response.IsSuccessStatusCode, $"Query failed: {response.OpenResponse()}");
var wrapper = response.OpenTResponse<TaxonomiesResponseModel>();
Assert.IsNotNull(wrapper?.Taxonomies);
Assert.IsTrue(wrapper.Taxonomies.Count >= 0);
}
[TestMethod]
[DoNotParallelize]
public void Test004_Should_Update_Taxonomy()
{
var updateModel = new TaxonomyModel
{
Name = "Taxonomy Integration Test Updated",
Description = "Updated description"
};
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Update(updateModel);
Assert.IsTrue(response.IsSuccessStatusCode, $"Update failed: {response.OpenResponse()}");
var wrapper = response.OpenTResponse<TaxonomyResponseModel>();
Assert.IsNotNull(wrapper?.Taxonomy);
Assert.AreEqual("Taxonomy Integration Test Updated", wrapper.Taxonomy.Name);
Assert.AreEqual("Updated description", wrapper.Taxonomy.Description);
}
[TestMethod]
[DoNotParallelize]
public async Task Test005_Should_Fetch_Taxonomy_Async()
{
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).FetchAsync();
Assert.IsTrue(response.IsSuccessStatusCode, $"FetchAsync failed: {response.OpenResponse()}");
var wrapper = response.OpenTResponse<TaxonomyResponseModel>();
Assert.IsNotNull(wrapper?.Taxonomy);
Assert.AreEqual(_taxonomyUid, wrapper.Taxonomy.Uid);
}
[TestMethod]
[DoNotParallelize]
public void Test006_Should_Delete_Taxonomy()
{
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Delete();
Assert.IsTrue(response.IsSuccessStatusCode, $"Delete failed: {response.OpenResponse()}");
}
[TestMethod]
[DoNotParallelize]
public void Test007_Should_Throw_When_Fetch_NonExistent_Taxonomy()
{
Assert.ThrowsException<ContentstackErrorException>(() =>
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Fetch());
}
[TestMethod]
[DoNotParallelize]
public void Test008_Should_Throw_When_Delete_NonExistent_Taxonomy()
{
Assert.ThrowsException<ContentstackErrorException>(() =>
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Delete());
}
}
}