forked from ddrilling/AsbCloudServer
Added EventServiceTest
This commit is contained in:
parent
87d7563ed3
commit
887cb493f2
47
AsbCloudWebApi.Tests/ServicesTests/EventServiceTest.cs
Normal file
47
AsbCloudWebApi.Tests/ServicesTests/EventServiceTest.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
|
using AsbCloudInfrastructure.Services;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudInfrastructure.Services;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Tests.ServicesTests;
|
||||||
|
|
||||||
|
public class EventServiceTest
|
||||||
|
{
|
||||||
|
private readonly AsbCloudDbContext context;
|
||||||
|
private readonly CacheDb cacheDb;
|
||||||
|
private readonly Mock<ITelemetryService> telemetryService;
|
||||||
|
|
||||||
|
public EventServiceTest()
|
||||||
|
{
|
||||||
|
context = TestHelpter.MakeTestContext();
|
||||||
|
cacheDb = new CacheDb();
|
||||||
|
telemetryService = new Mock<ITelemetryService>();
|
||||||
|
telemetryService.Setup(s => s.GetOrCreateTelemetryIdByUid(It.IsAny<string>()))
|
||||||
|
.Returns(1);
|
||||||
|
context.TelemetryEvents.RemoveRange(context.TelemetryEvents);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task It_should_save_two_telemetry_events()
|
||||||
|
{
|
||||||
|
var service = new EventService(context, cacheDb, telemetryService.Object);
|
||||||
|
|
||||||
|
var dtos = new List<EventDto>
|
||||||
|
{
|
||||||
|
new EventDto {Id = 1, IdCategory = 1, Message = "Test message 1"},
|
||||||
|
new EventDto {Id = 2, IdCategory = 1, Message = "Test message 2"}
|
||||||
|
};
|
||||||
|
|
||||||
|
await service.UpsertAsync("uid", dtos);
|
||||||
|
|
||||||
|
Assert.Equal(2, context.TelemetryEvents.Count());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user