Skip to content

Commit d5b673c

Browse files
authored
Merge pull request #87 from contentstack/feat/DX-3047
Feat-DX- 3047: Added Support for Nested Global Field for CRUD Operation
2 parents 8eaafd0 + 56990d7 commit d5b673c

18 files changed

+2159
-158
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Changelog
2+
## [v0.3.0](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.3.0)
3+
- Feat
4+
- Bulk Operations:
5+
- Added Support for the bulk operations of Publish, Unpublish, Delete, Workflow Update, addRelease Items, Update Release Items, Job-Status both sync and async methods
6+
- Nested Global Fields:
7+
Added the support for the nested global fields for all the CRUD Operations
8+
19
# Changelog
210
## [v0.2.0](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.2.0)
311
- Fix
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using AutoFixture;
6+
using Contentstack.Management.Core.Models;
7+
using Contentstack.Management.Core.Models.Fields;
8+
using Contentstack.Management.Core.Queryable;
9+
using Contentstack.Management.Core.Tests.Model;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
12+
namespace Contentstack.Management.Core.Tests.IntegrationTest
13+
{
14+
[TestClass]
15+
public class Contentstack008_NestedGlobalFieldTest
16+
{
17+
private Stack _stack;
18+
19+
[TestInitialize]
20+
public void Initialize()
21+
{
22+
StackResponse response = StackResponse.getStack(Contentstack.Client.serializer);
23+
_stack = Contentstack.Client.Stack(response.Stack.APIKey);
24+
}
25+
26+
private ContentModelling CreateReferencedGlobalFieldModel()
27+
{
28+
return new ContentModelling
29+
{
30+
Title = "Referenced Global Field",
31+
Uid = "referenced_global_field",
32+
Description = "A global field that will be referenced by another global field",
33+
Schema = new List<Field>
34+
{
35+
new TextboxField
36+
{
37+
DisplayName = "Title",
38+
Uid = "title",
39+
DataType = "text",
40+
Mandatory = true,
41+
Unique = true,
42+
FieldMetadata = new FieldMetadata
43+
{
44+
Default = "true"
45+
}
46+
},
47+
new TextboxField
48+
{
49+
DisplayName = "Description",
50+
Uid = "description",
51+
DataType = "text",
52+
Mandatory = false,
53+
FieldMetadata = new FieldMetadata
54+
{
55+
Description = "A description field"
56+
}
57+
}
58+
}
59+
};
60+
}
61+
62+
private ContentModelling CreateNestedGlobalFieldModel()
63+
{
64+
return new ContentModelling
65+
{
66+
Title = "Nested Global Field Test",
67+
Uid = "nested_global_field_test",
68+
Description = "Test nested global field for .NET SDK",
69+
Schema = new List<Field>
70+
{
71+
new TextboxField
72+
{
73+
DisplayName = "Single Line Textbox",
74+
Uid = "single_line",
75+
DataType = "text",
76+
Mandatory = false,
77+
Multiple = false,
78+
Unique = false,
79+
FieldMetadata = new FieldMetadata
80+
{
81+
Description = "",
82+
DefaultValue = "",
83+
Version = 3
84+
}
85+
},
86+
new GlobalFieldReference
87+
{
88+
DisplayName = "Global Field Reference",
89+
Uid = "global_field_reference",
90+
DataType = "global_field",
91+
ReferenceTo = "referenced_global_field",
92+
Mandatory = false,
93+
Multiple = false,
94+
Unique = false,
95+
NonLocalizable = false,
96+
FieldMetadata = new FieldMetadata
97+
{
98+
Description = "Reference to another global field"
99+
}
100+
}
101+
},
102+
GlobalFieldRefs = new List<GlobalFieldRefs>
103+
{
104+
new GlobalFieldRefs
105+
{
106+
Uid = "referenced_global_field",
107+
OccurrenceCount = 1,
108+
IsChild = true,
109+
Paths = new List<string> { "schema.1" }
110+
}
111+
}
112+
};
113+
}
114+
115+
[TestMethod]
116+
[DoNotParallelize]
117+
public void Test001_Should_Create_Referenced_Global_Field()
118+
{
119+
var referencedGlobalFieldModel = CreateReferencedGlobalFieldModel();
120+
ContentstackResponse response = _stack.GlobalField().Create(referencedGlobalFieldModel);
121+
GlobalFieldModel globalField = response.OpenTResponse<GlobalFieldModel>();
122+
123+
Assert.IsNotNull(response);
124+
Assert.IsNotNull(globalField);
125+
Assert.IsNotNull(globalField.Modelling);
126+
Assert.AreEqual(referencedGlobalFieldModel.Title, globalField.Modelling.Title);
127+
Assert.AreEqual(referencedGlobalFieldModel.Uid, globalField.Modelling.Uid);
128+
Assert.AreEqual(referencedGlobalFieldModel.Schema.Count, globalField.Modelling.Schema.Count);
129+
}
130+
131+
[TestMethod]
132+
[DoNotParallelize]
133+
public void Test002_Should_Create_Nested_Global_Field()
134+
{
135+
var nestedGlobalFieldModel = CreateNestedGlobalFieldModel();
136+
ContentstackResponse response = _stack.GlobalField().Create(nestedGlobalFieldModel);
137+
GlobalFieldModel globalField = response.OpenTResponse<GlobalFieldModel>();
138+
139+
Assert.IsNotNull(response);
140+
Assert.IsNotNull(globalField);
141+
Assert.IsNotNull(globalField.Modelling);
142+
Assert.AreEqual(nestedGlobalFieldModel.Title, globalField.Modelling.Title);
143+
Assert.AreEqual(nestedGlobalFieldModel.Uid, globalField.Modelling.Uid);
144+
Assert.AreEqual(nestedGlobalFieldModel.Schema.Count, globalField.Modelling.Schema.Count);
145+
146+
}
147+
148+
[TestMethod]
149+
[DoNotParallelize]
150+
public void Test003_Should_Fetch_Nested_Global_Field()
151+
{
152+
153+
ContentstackResponse response = _stack.GlobalField("nested_global_field_test").Fetch();
154+
GlobalFieldModel globalField = response.OpenTResponse<GlobalFieldModel>();
155+
156+
Assert.IsNotNull(response);
157+
Assert.IsNotNull(globalField);
158+
Assert.IsNotNull(globalField.Modelling);
159+
Assert.AreEqual("nested_global_field_test", globalField.Modelling.Uid);
160+
161+
Assert.IsTrue(globalField.Modelling.Schema.Count >= 2);
162+
}
163+
164+
[TestMethod]
165+
[DoNotParallelize]
166+
public async Task Test004_Should_Fetch_Async_Nested_Global_Field()
167+
{
168+
169+
ContentstackResponse response = await _stack.GlobalField("nested_global_field_test").FetchAsync();
170+
GlobalFieldModel globalField = response.OpenTResponse<GlobalFieldModel>();
171+
172+
Assert.IsNotNull(response);
173+
Assert.IsNotNull(globalField);
174+
Assert.IsNotNull(globalField.Modelling);
175+
Assert.AreEqual("nested_global_field_test", globalField.Modelling.Uid);
176+
}
177+
178+
[TestMethod]
179+
[DoNotParallelize]
180+
public void Test005_Should_Update_Nested_Global_Field()
181+
{
182+
var updateModel = new ContentModelling
183+
{
184+
Title = "Updated Nested Global Field",
185+
Uid = "nested_global_field_test",
186+
Description = "Updated description for nested global field",
187+
Schema = CreateNestedGlobalFieldModel().Schema,
188+
GlobalFieldRefs = CreateNestedGlobalFieldModel().GlobalFieldRefs
189+
};
190+
191+
ContentstackResponse response = _stack.GlobalField("nested_global_field_test").Update(updateModel);
192+
GlobalFieldModel globalField = response.OpenTResponse<GlobalFieldModel>();
193+
194+
Assert.IsNotNull(response);
195+
Assert.IsNotNull(globalField);
196+
Assert.IsNotNull(globalField.Modelling);
197+
Assert.AreEqual(updateModel.Title, globalField.Modelling.Title);
198+
Assert.AreEqual("nested_global_field_test", globalField.Modelling.Uid);
199+
}
200+
201+
[TestMethod]
202+
[DoNotParallelize]
203+
public async Task Test006_Should_Update_Async_Nested_Global_Field()
204+
{
205+
var updateModel = new ContentModelling
206+
{
207+
Title = "Updated Async Nested Global Field",
208+
Uid = "nested_global_field_test",
209+
Description = "Updated async description for nested global field",
210+
Schema = CreateNestedGlobalFieldModel().Schema,
211+
GlobalFieldRefs = CreateNestedGlobalFieldModel().GlobalFieldRefs
212+
};
213+
214+
ContentstackResponse response = await _stack.GlobalField("nested_global_field_test").UpdateAsync(updateModel);
215+
GlobalFieldModel globalField = response.OpenTResponse<GlobalFieldModel>();
216+
217+
Assert.IsNotNull(response);
218+
Assert.IsNotNull(globalField);
219+
Assert.IsNotNull(globalField.Modelling);
220+
Assert.AreEqual(updateModel.Title, globalField.Modelling.Title);
221+
Assert.AreEqual("nested_global_field_test", globalField.Modelling.Uid);
222+
}
223+
224+
[TestMethod]
225+
[DoNotParallelize]
226+
public void Test007_Should_Query_Nested_Global_Fields()
227+
{
228+
229+
ContentstackResponse response = _stack.GlobalField().Query().Find();
230+
GlobalFieldsModel globalFields = response.OpenTResponse<GlobalFieldsModel>();
231+
232+
Assert.IsNotNull(response);
233+
Assert.IsNotNull(globalFields);
234+
Assert.IsNotNull(globalFields.Modellings);
235+
Assert.IsTrue(globalFields.Modellings.Count >= 1);
236+
237+
var nestedGlobalField = globalFields.Modellings.Find(gf => gf.Uid == "nested_global_field_test");
238+
Assert.IsNotNull(nestedGlobalField);
239+
Assert.AreEqual("nested_global_field_test", nestedGlobalField.Uid);
240+
}
241+
242+
[TestMethod]
243+
[DoNotParallelize]
244+
public void Test009_Should_Delete_Referenced_Global_Field()
245+
{
246+
// This has been used to avoid tthe confirmation prompt during deletion in case the global field is referenced
247+
var parameters = new ParameterCollection();
248+
parameters.Add("force", "true");
249+
ContentstackResponse response = _stack.GlobalField("referenced_global_field").Delete(parameters);
250+
251+
Assert.IsNotNull(response);
252+
}
253+
254+
[TestMethod]
255+
[DoNotParallelize]
256+
public void Test008_Should_Delete_Nested_Global_Field()
257+
{
258+
ContentstackResponse response = _stack.GlobalField("nested_global_field_test").Delete();
259+
Assert.IsNotNull(response);
260+
}
261+
262+
263+
}
264+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"title": "nested_global_field_test",
3+
"uid": "nested_gf_test",
4+
"description": "Test nested global field for .NET SDK",
5+
"schema": [
6+
{
7+
"data_type": "text",
8+
"display_name": "Single Line Textbox",
9+
"uid": "single_line",
10+
"field_metadata": {
11+
"description": "",
12+
"default_value": "",
13+
"version": 3
14+
},
15+
"format": "",
16+
"error_messages": {
17+
"format": ""
18+
},
19+
"mandatory": false,
20+
"multiple": false,
21+
"non_localizable": false,
22+
"unique": false
23+
},
24+
{
25+
"data_type": "global_field",
26+
"display_name": "Global Field Reference",
27+
"reference_to": "referenced_global_field",
28+
"field_metadata": {
29+
"description": "Reference to another global field"
30+
},
31+
"uid": "global_field_reference",
32+
"mandatory": false,
33+
"multiple": false,
34+
"non_localizable": false,
35+
"unique": false
36+
}
37+
],
38+
"global_field_refs": [
39+
{
40+
"uid": "referenced_global_field",
41+
"occurrence_count": 1,
42+
"isChild": true,
43+
"paths": [
44+
"schema.1"
45+
]
46+
}
47+
]
48+
}

0 commit comments

Comments
 (0)