public async Task Post_ReturnsBadRequest_GivenNull() { // Arrange var mockRepo = new Mock <IService <Code> >(); var returning = "invalid"; var dbMock = GetCode(returning); mockRepo.Setup(x => x.Post(It.IsAny <Code>())) .Returns(dbMock); var controller = new CodesController(mockRepo.Object); // Act var result = await controller.Post(new CodeDTO(1, "Test One")); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task Post_ReturnsCodeDTO_GivenCodeDTO() { // Arrange var mockRepo = new Mock <IService <Code> >(); var dbMock = GetCode(); mockRepo.Setup(x => x.Post(It.IsAny <Code>())) .Returns(dbMock).Verifiable(); var controller = new CodesController(mockRepo.Object); // Act var result = await controller.Post(new CodeDTO(0, "Test One")); // Assert mockRepo.VerifyAll(); var okResult = Assert.IsType <OkObjectResult>(result); var returnCode = Assert.IsType <CodeDTO>(okResult.Value); Assert.Equal("Test One", returnCode.Name); }