persistence/DD.Persistence.Repository.Test/SetpointRepositoryShould.cs

57 lines
1.6 KiB
C#

using DD.Persistence.Database.Model;
using DD.Persistence.Repository.Repositories;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace DD.Persistence.Repository.Test;
public class SetpointRepositoryShould : IClassFixture<RepositoryTestFixture>
{
private readonly RepositoryTestFixture fixture;
private readonly PersistencePostgresContext context;
private readonly SetpointRepository sut;
public SetpointRepositoryShould(RepositoryTestFixture fixture)
{
this.fixture = fixture;
context = fixture.GetDbContext();
sut = new SetpointRepository(context);
}
[Fact]
public async Task ReturnValueKindNumber()
{
var id = Guid.NewGuid();
var value = GetJsonFromObject(22);
await sut.Add(id, value, Guid.NewGuid(), CancellationToken.None);
var t = fixture.dbContainer.GetConnectionString();
//act
var result = await sut.GetCurrent([id], CancellationToken.None);
//assert
result.ShouldNotBeNull();
result.ShouldNotBeEmpty();
var setpoint = result.First();
setpoint.Value.ShouldNotBeNull();
setpoint
.Value.ShouldBeOfType<JsonElement>()
.ValueKind.ShouldBe(JsonValueKind.Number);
}
private JsonElement GetJsonFromObject(object value)
{
var jsonString = JsonSerializer.Serialize(value);
var doc = JsonDocument.Parse(jsonString);
return doc.RootElement;
}
}