2024-11-18 11:32:57 +05:00
|
|
|
|
using System.Net;
|
2024-11-21 14:50:36 +05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Persistence.Client;
|
|
|
|
|
using Persistence.Client.Clients;
|
2024-11-18 11:32:57 +05:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Persistence.IntegrationTests.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class SetpointControllerTest : BaseIntegrationTest
|
|
|
|
|
{
|
2024-11-21 14:50:36 +05:00
|
|
|
|
private ISetpointClient setpointClient;
|
2024-11-18 11:32:57 +05:00
|
|
|
|
private class TestObject
|
|
|
|
|
{
|
|
|
|
|
public string? value1 { get; set; }
|
2024-11-18 15:05:12 +05:00
|
|
|
|
public int? value2 { get; set; }
|
2024-11-18 11:32:57 +05:00
|
|
|
|
}
|
|
|
|
|
public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory)
|
|
|
|
|
{
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var scope = factory.Services.CreateScope();
|
2024-11-25 10:09:38 +05:00
|
|
|
|
var persistenceClientFactory = scope.ServiceProvider
|
|
|
|
|
.GetRequiredService<PersistenceClientFactory>();
|
2024-11-21 14:50:36 +05:00
|
|
|
|
|
2024-11-25 10:09:38 +05:00
|
|
|
|
setpointClient = persistenceClientFactory.GetClient<ISetpointClient>();
|
2024-11-18 11:32:57 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2024-11-18 15:05:12 +05:00
|
|
|
|
public async Task GetCurrent_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var setpointKeys = new List<Guid>()
|
|
|
|
|
{
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
Guid.NewGuid()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//act
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var response = await setpointClient.GetCurrent(setpointKeys);
|
2024-11-18 15:05:12 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.Empty(response.Content);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetCurrent_AfterSave_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var setpointKey = await Save();
|
|
|
|
|
|
|
|
|
|
//act
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var response = await setpointClient.GetCurrent([setpointKey]);
|
2024-11-20 15:29:58 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.NotEmpty(response.Content);
|
|
|
|
|
Assert.Equal(response.Content.FirstOrDefault()?.Key, setpointKey);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 15:05:12 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetHistory_returns_success()
|
2024-11-18 11:32:57 +05:00
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var setpointKeys = new List<Guid>()
|
|
|
|
|
{
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
Guid.NewGuid()
|
|
|
|
|
};
|
2024-11-20 15:29:58 +05:00
|
|
|
|
var historyMoment = DateTimeOffset.UtcNow;
|
2024-11-18 11:32:57 +05:00
|
|
|
|
|
|
|
|
|
//act
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var response = await setpointClient.GetHistory(setpointKeys, historyMoment);
|
2024-11-18 11:32:57 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
2024-11-18 15:05:12 +05:00
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.Empty(response.Content);
|
2024-11-18 11:32:57 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetHistory_AfterSave_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var setpointKey = await Save();
|
|
|
|
|
var historyMoment = DateTimeOffset.UtcNow;
|
|
|
|
|
historyMoment = historyMoment.AddDays(1);
|
|
|
|
|
|
|
|
|
|
//act
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var response = await setpointClient.GetHistory([setpointKey], historyMoment);
|
2024-11-20 15:29:58 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.NotEmpty(response.Content);
|
|
|
|
|
Assert.Equal(response.Content.FirstOrDefault()?.Key, setpointKey);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 11:32:57 +05:00
|
|
|
|
[Fact]
|
2024-11-18 15:05:12 +05:00
|
|
|
|
public async Task GetLog_returns_success()
|
2024-11-18 11:32:57 +05:00
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var setpointKeys = new List<Guid>()
|
|
|
|
|
{
|
|
|
|
|
Guid.NewGuid(),
|
|
|
|
|
Guid.NewGuid()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//act
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var response = await setpointClient.GetLog(setpointKeys);
|
2024-11-18 11:32:57 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
2024-11-18 15:05:12 +05:00
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.Empty(response.Content);
|
2024-11-18 11:32:57 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2024-11-20 15:29:58 +05:00
|
|
|
|
public async Task GetLog_AfterSave_returns_success()
|
2024-11-18 11:32:57 +05:00
|
|
|
|
{
|
|
|
|
|
//arrange
|
2024-11-20 15:29:58 +05:00
|
|
|
|
var setpointKey = await Save();
|
2024-11-18 11:32:57 +05:00
|
|
|
|
|
|
|
|
|
//act
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var response = await setpointClient.GetLog([setpointKey]);
|
2024-11-18 11:32:57 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
2024-11-20 15:29:58 +05:00
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.NotEmpty(response.Content);
|
|
|
|
|
Assert.Equal(response.Content.FirstOrDefault().Value.FirstOrDefault()?.Key, setpointKey);
|
2024-11-18 11:32:57 +05:00
|
|
|
|
}
|
2024-11-18 15:05:12 +05:00
|
|
|
|
|
|
|
|
|
[Fact]
|
2024-11-20 15:29:58 +05:00
|
|
|
|
public async Task Save_returns_success()
|
2024-11-18 15:05:12 +05:00
|
|
|
|
{
|
2024-11-20 15:29:58 +05:00
|
|
|
|
await Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<Guid> Save()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
2024-11-18 15:05:12 +05:00
|
|
|
|
var setpointKey = Guid.NewGuid();
|
|
|
|
|
var setpointValue = new TestObject()
|
|
|
|
|
{
|
|
|
|
|
value1 = "1",
|
|
|
|
|
value2 = 2
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-20 15:29:58 +05:00
|
|
|
|
//act
|
2024-11-21 14:50:36 +05:00
|
|
|
|
var response = await setpointClient.Save(setpointKey, setpointValue);
|
2024-11-20 15:29:58 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
|
|
|
|
|
return setpointKey;
|
2024-11-18 15:05:12 +05:00
|
|
|
|
}
|
2024-11-18 11:32:57 +05:00
|
|
|
|
}
|
|
|
|
|
}
|