public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IDeviceService service = testServer.Host.Services.GetService(typeof(IDeviceService)) as IDeviceService; var model = new ApiDeviceServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), true, "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); CreateResponse <ApiDeviceServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.DeviceDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiDeviceServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public void MapServerRequestToResponse() { var mapper = new ApiDeviceServerModelMapper(); var model = new ApiDeviceServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiDeviceServerResponseModel response = mapper.MapServerRequestToResponse(1, model); response.Should().NotBeNull(); response.DateOfLastPing.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.IsActive.Should().Be(true); response.Name.Should().Be("A"); response.PublicId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IDeviceService, IDeviceRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Device>(null)); var service = new DeviceService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DeviceModelValidatorMock.Object, mock.DALMapperMockFactory.DALDeviceMapperMock, mock.DALMapperMockFactory.DALDeviceActionMapperMock); ApiDeviceServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void ByPublicId_Not_Exists() { var mock = new ServiceMockFacade <IDeviceService, IDeviceRepository>(); mock.RepositoryMock.Setup(x => x.ByPublicId(It.IsAny <Guid>())).Returns(Task.FromResult <Device>(null)); var service = new DeviceService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DeviceModelValidatorMock.Object, mock.DALMapperMockFactory.DALDeviceMapperMock, mock.DALMapperMockFactory.DALDeviceActionMapperMock); ApiDeviceServerResponseModel response = await service.ByPublicId(default(Guid)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.ByPublicId(It.IsAny <Guid>())); }