Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Contentstack.Management.Core.Tests.IntegrationTest
public class Contentstack001_LoginTest
{
private readonly IConfigurationRoot _configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

[TestMethod]
[DoNotParallelize]
public void Test001_Should_Return_Failuer_On_Wrong_Login_Credentials()
Expand Down Expand Up @@ -60,42 +59,34 @@ public void Test002_Should_Return_Failuer_On_Wrong_Async_Login_Credentials()

[TestMethod]
[DoNotParallelize]
public void Test003_Should_Return_Success_On_Async_Login()
public async System.Threading.Tasks.Task Test003_Should_Return_Success_On_Async_Login()
{
ContentstackClient client = new ContentstackClient();
var response = client.LoginAsync(Contentstack.Credential);

response.ContinueWith((t) =>

try
{
if (t.IsCompleted)
{
try
{
ContentstackResponse contentstackResponse = t.Result;
string loginResponse = contentstackResponse.OpenResponse();

Assert.IsNotNull(client.contentstackOptions.Authtoken);
Assert.IsNotNull(loginResponse);
}catch (Exception e)
{
Assert.Fail(e.Message);
}
ContentstackResponse contentstackResponse = await client.LoginAsync(Contentstack.Credential);
string loginResponse = contentstackResponse.OpenResponse();

}
});
Thread.Sleep(3000);
Assert.IsNotNull(client.contentstackOptions.Authtoken);
Assert.IsNotNull(loginResponse);

await client.LogoutAsync();
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}

[TestMethod]
[DoNotParallelize]
public void Test004_Should_Return_Success_On_Login()
{
string email = _configuration.GetSection("Contentstack:Credentials:Email").Value;
string password = _configuration.GetSection("Contentstack:Credentials:Password").Value;

try
{
ContentstackClient client = Contentstack.Client;
ContentstackClient client = new ContentstackClient();

ContentstackResponse contentstackResponse = client.Login(Contentstack.Credential);
string loginResponse = contentstackResponse.OpenResponse();

Expand All @@ -114,7 +105,10 @@ public void Test005_Should_Return_Loggedin_User()
{
try
{
ContentstackClient client = Contentstack.Client;
ContentstackClient client = new ContentstackClient();

client.Login(Contentstack.Credential);

ContentstackResponse response = client.GetUser();

var user = response.OpenJObjectResponse();
Expand All @@ -134,7 +128,10 @@ public async System.Threading.Tasks.Task Test006_Should_Return_Loggedin_User_Asy
{
try
{
ContentstackClient client = Contentstack.Client;
ContentstackClient client = new ContentstackClient();

await client.LoginAsync(Contentstack.Credential);

ContentstackResponse response = await client.GetUserAsync();

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

ContentstackClient client = Contentstack.Client;
ContentstackClient client = new ContentstackClient();

client.Login(Contentstack.Credential);

ContentstackResponse response = client.GetUser(collection);

var user = response.OpenJObjectResponse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Tests.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -96,15 +97,46 @@ public void Test005_Should_Update_Content_Type()
[DoNotParallelize]
public async System.Threading.Tasks.Task Test006_Should_Update_Async_Content_Type()
{
_multiPage.Title = "First Async";
ContentstackResponse response = await _stack.ContentType(_multiPage.Uid).UpdateAsync(_multiPage);
ContentTypeModel ContentType = response.OpenTResponse<ContentTypeModel>();
Assert.IsNotNull(response);
Assert.IsNotNull(ContentType);
Assert.IsNotNull(ContentType.Modelling);
Assert.AreEqual(_multiPage.Title, ContentType.Modelling.Title);
Assert.AreEqual(_multiPage.Uid, ContentType.Modelling.Uid);
Assert.AreEqual(_multiPage.Schema.Count, ContentType.Modelling.Schema.Count);
try
{
// Load the existing schema
_multiPage.Schema = Contentstack.serializeArray<List<Models.Fields.Field>>(Contentstack.Client.serializer, "contentTypeSchema.json");

// Add a new text field to the schema
var newTextField = new Models.Fields.TextboxField
{
Uid = "new_text_field",
DataType = "text",
DisplayName = "New Text Field",
FieldMetadata = new Models.Fields.FieldMetadata
{
Description = "A new text field added during async update test"
}
};
_multiPage.Schema.Add(newTextField);

// Update the content type with the modified schema
ContentstackResponse response = await _stack.ContentType(_multiPage.Uid).UpdateAsync(_multiPage);

if (response.IsSuccessStatusCode)
{
ContentTypeModel ContentType = response.OpenTResponse<ContentTypeModel>();
Assert.IsNotNull(response);
Assert.IsNotNull(ContentType);
Assert.IsNotNull(ContentType.Modelling);
Assert.AreEqual(_multiPage.Uid, ContentType.Modelling.Uid);
Assert.AreEqual(_multiPage.Schema.Count, ContentType.Modelling.Schema.Count);
Console.WriteLine($"Successfully updated content type with {ContentType.Modelling.Schema.Count} fields");
}
else
{
Assert.Fail($"Update failed with status {response.StatusCode}: {response.OpenResponse()}");
}
}
catch (Exception ex)
{
Assert.Fail($"Exception during async update: {ex.Message}");
}
}

[TestMethod]
Expand All @@ -121,7 +153,7 @@ public void Test007_Should_Query_Content_Type()

[TestMethod]
[DoNotParallelize]
public async System.Threading.Tasks.Task Test008_Should_Update_Async_Content_Type()
public async System.Threading.Tasks.Task Test008_Should_Query_Async_Content_Type()
{
ContentstackResponse response = await _stack.ContentType().Query().FindAsync();
ContentTypesModel ContentType = response.OpenTResponse<ContentTypesModel>();
Expand Down
Loading
Loading