Setpoint API #1
@ -17,9 +17,9 @@ public abstract class BaseIntegrationTest : IClassFixture<WebAppFactoryFixture>,
|
|||||||
|
|
||||||
protected BaseIntegrationTest(WebAppFactoryFixture factory)
|
protected BaseIntegrationTest(WebAppFactoryFixture factory)
|
||||||
{
|
{
|
||||||
//scope = factory.Services.CreateScope();
|
scope = factory.Services.CreateScope();
|
||||||
|
|
||||||
//dbContext = scope.ServiceProvider.GetRequiredService<PersistenceDbContext>();
|
dbContext = scope.ServiceProvider.GetRequiredService<PersistenceDbContext>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
17
Persistence.IntegrationTests/Clients/ISetpointClient.cs
Normal file
17
Persistence.IntegrationTests/Clients/ISetpointClient.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Persistence.Models;
|
||||||
|
using Refit;
|
||||||
|
|
||||||
|
namespace Persistence.IntegrationTests.Clients
|
||||||
|
{
|
||||||
|
public interface ISetpointClient
|
||||||
|
{
|
||||||
|
[Post("/api/Setpoint/history")]
|
||||||
|
|||||||
|
Task<IApiResponse<IEnumerable<SetpointValueDto>>> GetHistoryAsync(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment);
|
||||||
|
|
||||||
|
[Post("/api/Setpoint/log")]
|
||||||
|
Task<IApiResponse<Dictionary<Guid, IEnumerable<SetpointLogDto>>>> GetLogAsync(IEnumerable<Guid> setpoitKeys);
|
||||||
|
|
||||||
|
[Post("/api/Setpoint/save")]
|
||||||
|
Task<IApiResponse<int>> SaveAsync(Guid setpointKey, object newValue);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Persistence.IntegrationTests.Clients;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Persistence.IntegrationTests.Controllers
|
||||||
|
{
|
||||||
|
public class SetpointControllerTest : BaseIntegrationTest
|
||||||
|
{
|
||||||
|
private ISetpointClient client;
|
||||||
|
private class TestObject
|
||||||
|
{
|
||||||
|
public string? value1 { get; set; }
|
||||||
|
public int value2 { get; set; }
|
||||||
|
public double value3 { get; set; }
|
||||||
|
}
|
||||||
|
public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||||
|
{
|
||||||
|
client = factory.GetHttpClient<ISetpointClient>(string.Empty);
|
||||||
|
}
|
||||||
on.nemtina
commented
Эту строчку лучше убрать, а в интерфейсе ISetpointClient прописать так:
Эту строчку лучше убрать, а в интерфейсе ISetpointClient прописать так:
```
private const string BaseRoute = "/api/setpoint";
[Post($"{BaseRoute}/current")]
Task<IApiResponse<IEnumerable<SetpointValueDto>>> GetCurrent(IEnumerable<Guid> setpointKeys);```
|
|||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetHistoryAsync_returns_success()
|
||||||
|
{
|
||||||
|
//arrange
|
||||||
|
var setpointKeys = new List<Guid>()
|
||||||
|
{
|
||||||
|
Guid.NewGuid(),
|
||||||
|
Guid.NewGuid()
|
||||||
|
};
|
||||||
|
var historyMoment = DateTimeOffset.Now.ToUniversalTime();
|
||||||
|
|
||||||
|
//act
|
||||||
|
var response = await client.GetHistoryAsync(setpointKeys, historyMoment);
|
||||||
|
|
||||||
|
//assert
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetLogAsync_returns_success()
|
||||||
|
{
|
||||||
|
//arrange
|
||||||
|
var setpointKeys = new List<Guid>()
|
||||||
|
{
|
||||||
|
Guid.NewGuid(),
|
||||||
|
Guid.NewGuid()
|
||||||
|
};
|
||||||
|
|
||||||
|
//act
|
||||||
|
var response = await client.GetLogAsync(setpointKeys);
|
||||||
|
|
||||||
|
//assert
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SaveAsync_returns_success()
|
||||||
|
{
|
||||||
|
//arrange
|
||||||
|
var setpointKey = Guid.NewGuid();
|
||||||
|
var setpointValue = new TestObject()
|
||||||
|
{
|
||||||
|
value1 = "1",
|
||||||
|
value2 = 2,
|
||||||
|
value3 = 3.3
|
||||||
|
};
|
||||||
|
|
||||||
|
//act
|
||||||
|
var response = await client.SaveAsync(setpointKey, setpointValue);
|
||||||
|
|
||||||
|
//assert
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Persistence.API\Persistence.API.csproj" />
|
<ProjectReference Include="..\Persistence.API\Persistence.API.csproj" />
|
||||||
|
<ProjectReference Include="..\Persistence.Database.Postgres\Persistence.Database.Postgres.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -8,6 +8,7 @@ using Persistence.API;
|
|||||||
using Refit;
|
using Refit;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Persistence.Database.Postgres;
|
||||||
|
|
||||||
namespace Persistence.IntegrationTests;
|
namespace Persistence.IntegrationTests;
|
||||||
public class WebAppFactoryFixture : WebApplicationFactory<Startup>
|
public class WebAppFactoryFixture : WebApplicationFactory<Startup>
|
||||||
@ -51,7 +52,7 @@ public class WebAppFactoryFixture : WebApplicationFactory<Startup>
|
|||||||
var scopedServices = scope.ServiceProvider;
|
var scopedServices = scope.ServiceProvider;
|
||||||
var dbContext = scopedServices.GetRequiredService<PersistenceDbContext>();
|
var dbContext = scopedServices.GetRequiredService<PersistenceDbContext>();
|
||||||
|
|
||||||
//dbContext.Database.EnsureCreatedAndMigrated();
|
dbContext.Database.EnsureCreatedAndMigrated();
|
||||||
//dbContext.Deposits.AddRange(Data.Defaults.Deposits);
|
//dbContext.Deposits.AddRange(Data.Defaults.Deposits);
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
});
|
});
|
||||||
|
@ -60,9 +60,8 @@ namespace Persistence.Repository.Repositories
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
var t = ex.Message;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
on.nemtina
commented
Можно так: Created = DateTimeOffset.UtcNow Можно так: Created = DateTimeOffset.UtcNow
|
|||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user
Заголовки методов запроса должны соответствовать тем, что в контроллере (там часть нужно поменять с post на get)