Skip to content

Commit 3c5622a

Browse files
authored
Merge pull request #116 from contentstack/fix/DX-3614
Fix: Fixed and Add Unit And Integration Test
2 parents bf58e1a + 9ca3b74 commit 3c5622a

File tree

16 files changed

+2759
-109
lines changed

16 files changed

+2759
-109
lines changed

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace Contentstack.Management.Core.Tests.IntegrationTest
1515
public class Contentstack001_LoginTest
1616
{
1717
private readonly IConfigurationRoot _configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
18-
1918
[TestMethod]
2019
[DoNotParallelize]
2120
public void Test001_Should_Return_Failuer_On_Wrong_Login_Credentials()
@@ -60,42 +59,34 @@ public void Test002_Should_Return_Failuer_On_Wrong_Async_Login_Credentials()
6059

6160
[TestMethod]
6261
[DoNotParallelize]
63-
public void Test003_Should_Return_Success_On_Async_Login()
62+
public async System.Threading.Tasks.Task Test003_Should_Return_Success_On_Async_Login()
6463
{
6564
ContentstackClient client = new ContentstackClient();
66-
var response = client.LoginAsync(Contentstack.Credential);
67-
68-
response.ContinueWith((t) =>
65+
66+
try
6967
{
70-
if (t.IsCompleted)
71-
{
72-
try
73-
{
74-
ContentstackResponse contentstackResponse = t.Result;
75-
string loginResponse = contentstackResponse.OpenResponse();
76-
77-
Assert.IsNotNull(client.contentstackOptions.Authtoken);
78-
Assert.IsNotNull(loginResponse);
79-
}catch (Exception e)
80-
{
81-
Assert.Fail(e.Message);
82-
}
68+
ContentstackResponse contentstackResponse = await client.LoginAsync(Contentstack.Credential);
69+
string loginResponse = contentstackResponse.OpenResponse();
8370

84-
}
85-
});
86-
Thread.Sleep(3000);
71+
Assert.IsNotNull(client.contentstackOptions.Authtoken);
72+
Assert.IsNotNull(loginResponse);
73+
74+
await client.LogoutAsync();
75+
}
76+
catch (Exception e)
77+
{
78+
Assert.Fail(e.Message);
79+
}
8780
}
8881

8982
[TestMethod]
9083
[DoNotParallelize]
9184
public void Test004_Should_Return_Success_On_Login()
9285
{
93-
string email = _configuration.GetSection("Contentstack:Credentials:Email").Value;
94-
string password = _configuration.GetSection("Contentstack:Credentials:Password").Value;
95-
9686
try
9787
{
98-
ContentstackClient client = Contentstack.Client;
88+
ContentstackClient client = new ContentstackClient();
89+
9990
ContentstackResponse contentstackResponse = client.Login(Contentstack.Credential);
10091
string loginResponse = contentstackResponse.OpenResponse();
10192

@@ -114,7 +105,10 @@ public void Test005_Should_Return_Loggedin_User()
114105
{
115106
try
116107
{
117-
ContentstackClient client = Contentstack.Client;
108+
ContentstackClient client = new ContentstackClient();
109+
110+
client.Login(Contentstack.Credential);
111+
118112
ContentstackResponse response = client.GetUser();
119113

120114
var user = response.OpenJObjectResponse();
@@ -134,7 +128,10 @@ public async System.Threading.Tasks.Task Test006_Should_Return_Loggedin_User_Asy
134128
{
135129
try
136130
{
137-
ContentstackClient client = Contentstack.Client;
131+
ContentstackClient client = new ContentstackClient();
132+
133+
await client.LoginAsync(Contentstack.Credential);
134+
138135
ContentstackResponse response = await client.GetUserAsync();
139136

140137
var user = response.OpenJObjectResponse();
@@ -160,7 +157,10 @@ public void Test007_Should_Return_Loggedin_User_With_Organizations_detail()
160157
ParameterCollection collection = new ParameterCollection();
161158
collection.Add("include_orgs_roles", true);
162159

163-
ContentstackClient client = Contentstack.Client;
160+
ContentstackClient client = new ContentstackClient();
161+
162+
client.Login(Contentstack.Credential);
163+
164164
ContentstackResponse response = client.GetUser(collection);
165165

166166
var user = response.OpenJObjectResponse();

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack012_ContentTypeTest.cs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using Contentstack.Management.Core.Models;
34
using Contentstack.Management.Core.Tests.Model;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -96,15 +97,46 @@ public void Test005_Should_Update_Content_Type()
9697
[DoNotParallelize]
9798
public async System.Threading.Tasks.Task Test006_Should_Update_Async_Content_Type()
9899
{
99-
_multiPage.Title = "First Async";
100-
ContentstackResponse response = await _stack.ContentType(_multiPage.Uid).UpdateAsync(_multiPage);
101-
ContentTypeModel ContentType = response.OpenTResponse<ContentTypeModel>();
102-
Assert.IsNotNull(response);
103-
Assert.IsNotNull(ContentType);
104-
Assert.IsNotNull(ContentType.Modelling);
105-
Assert.AreEqual(_multiPage.Title, ContentType.Modelling.Title);
106-
Assert.AreEqual(_multiPage.Uid, ContentType.Modelling.Uid);
107-
Assert.AreEqual(_multiPage.Schema.Count, ContentType.Modelling.Schema.Count);
100+
try
101+
{
102+
// Load the existing schema
103+
_multiPage.Schema = Contentstack.serializeArray<List<Models.Fields.Field>>(Contentstack.Client.serializer, "contentTypeSchema.json");
104+
105+
// Add a new text field to the schema
106+
var newTextField = new Models.Fields.TextboxField
107+
{
108+
Uid = "new_text_field",
109+
DataType = "text",
110+
DisplayName = "New Text Field",
111+
FieldMetadata = new Models.Fields.FieldMetadata
112+
{
113+
Description = "A new text field added during async update test"
114+
}
115+
};
116+
_multiPage.Schema.Add(newTextField);
117+
118+
// Update the content type with the modified schema
119+
ContentstackResponse response = await _stack.ContentType(_multiPage.Uid).UpdateAsync(_multiPage);
120+
121+
if (response.IsSuccessStatusCode)
122+
{
123+
ContentTypeModel ContentType = response.OpenTResponse<ContentTypeModel>();
124+
Assert.IsNotNull(response);
125+
Assert.IsNotNull(ContentType);
126+
Assert.IsNotNull(ContentType.Modelling);
127+
Assert.AreEqual(_multiPage.Uid, ContentType.Modelling.Uid);
128+
Assert.AreEqual(_multiPage.Schema.Count, ContentType.Modelling.Schema.Count);
129+
Console.WriteLine($"Successfully updated content type with {ContentType.Modelling.Schema.Count} fields");
130+
}
131+
else
132+
{
133+
Assert.Fail($"Update failed with status {response.StatusCode}: {response.OpenResponse()}");
134+
}
135+
}
136+
catch (Exception ex)
137+
{
138+
Assert.Fail($"Exception during async update: {ex.Message}");
139+
}
108140
}
109141

110142
[TestMethod]
@@ -121,7 +153,7 @@ public void Test007_Should_Query_Content_Type()
121153

122154
[TestMethod]
123155
[DoNotParallelize]
124-
public async System.Threading.Tasks.Task Test008_Should_Update_Async_Content_Type()
156+
public async System.Threading.Tasks.Task Test008_Should_Query_Async_Content_Type()
125157
{
126158
ContentstackResponse response = await _stack.ContentType().Query().FindAsync();
127159
ContentTypesModel ContentType = response.OpenTResponse<ContentTypesModel>();

0 commit comments

Comments
 (0)