test: Legacy.Client getestet und erfolgreich abgeschlossen, alle erforderlichen Tests bestanden

This commit is contained in:
Developer 02
2024-07-29 13:46:30 +02:00
parent d35b638c74
commit d937383c78
7 changed files with 221 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DigitalData.Core.Legacy.Client;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.Core.Legacy.Tests.Client
{
[TestClass]
public class BaseHttpClientServiceTests
{
private BaseHttpClientService _service;
[ClassInitialize]
public static void ClassSetUp(TestContext context)
{
ServiceFactory.Services
.AddHttpClientService("https://jsonplaceholder.typicode.com/todos")
.BuildServiceProvider();
}
[TestInitialize]
public void SetUp()
{
_service = ServiceFactory.Provide<BaseHttpClientService>();
}
[TestMethod]
public async Task FetchJsonAsync_ShouldReturnJsonResponseAsDynamic()
{
// Act
var expectedUserId = (int)await _service.FetchAsync("/1", sendWithCookie: false, saveCookie: false)
.ThenAsync(res => res.Json())
.ThenAsync(todo => todo.userId);
// Assert
Assert.AreEqual(1, expectedUserId, "The userId of the fetched JSON object should be 1.");
}
[TestMethod]
public async Task FetchJsonAsync_ShouldReturnJsonResponse()
{
// Act
var expectedUserId = await _service.FetchAsync("/1", sendWithCookie: false, saveCookie: false)
.ThenAsync(res => res.Json<Todo>())
.ThenAsync(todo => todo.UserId);
// Assert
Assert.AreEqual(1, expectedUserId, "The userId of the fetched JSON object should be 1.");
}
}
public class Todo
{
public int UserId { get; set; }
public int Id { get; set; }
public string Title { get; set; }
public bool Completed { get; set; }
}
}