public async Task AddPersonAsync_WithCorrectInput_ReturnsOk() { var mockLogger = Mock.Of <ILogger <MaintenanceController> >(); var mockFaceClientService = new Mock <IFaceClientService>(); mockFaceClientService .Setup(service => service.CreatePersonAsync(It.IsNotNull <string>(), It.IsNotNull <string>())) .Returns(() => Task.FromResult(new Cloud.Models.Person { PersonId = $"{Guid.NewGuid()}" })); var dto = new NewPersonDto { FaceUrl = $"http://www.google.com", Name = $"{Guid.NewGuid()}" }; var controller = new MaintenanceController(mockFaceClientService.Object, mockLogger); var actionResult = await controller.AddPersonAsync(dto); Assert.NotNull(actionResult); var okObjectResult = Assert.IsAssignableFrom <OkObjectResult>(actionResult); var person = Assert.IsAssignableFrom <Cloud.Models.Person>(okObjectResult.Value); person.Should().NotBeNull(); person.PersonId.Should().NotBeNullOrWhiteSpace(); }
public async Task AddPersonAsync_WithMissingInput_ReturnsBadRequest() { var mockLogger = Mock.Of <ILogger <MaintenanceController> >(); var mockFaceClientService = Mock.Of <IFaceClientService>(); var controller = new MaintenanceController(mockFaceClientService, mockLogger); var actionResult = await controller.AddPersonAsync(null); Assert.NotNull(actionResult); Assert.IsAssignableFrom <BadRequestObjectResult>(actionResult); }
public async Task AddPersonAsync_WithFaceClientServiceFault_ThrowsException() { var mockLogger = Mock.Of <ILogger <MaintenanceController> >(); var mockFaceClientService = new Mock <IFaceClientService>(); mockFaceClientService .Setup(service => service.CreatePersonAsync(It.IsNotNull <string>(), It.IsNotNull <string>())) .Throws <NotImplementedException>(); var dto = new NewPersonDto { FaceUrl = $"http://www.google.com", Name = $"{Guid.NewGuid()}" }; var controller = new MaintenanceController(mockFaceClientService.Object, mockLogger); await Assert.ThrowsAsync <NotImplementedException>(async() => { await controller.AddPersonAsync(dto); }); }