public async Task Get_ReturnsNotFound_GivenNull() { // Arrange var mockRepo = new Mock <IService <Code> >(); var returning = "invalid"; var dbMock = GetCode(returning); mockRepo.Setup(x => x.Get(It.IsAny <int>())).Returns(dbMock); var controller = new CodesController(mockRepo.Object); // Act var result = await controller.Get(1); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task Get_ReturnsCodeDTO_GivenCode() { // Arrange var mockRepo = new Mock <IService <Code> >(); var dbMock = GetCode(); mockRepo.Setup(x => x.Get(It.IsAny <int>())).Returns(dbMock); var controller = new CodesController(mockRepo.Object); // Act var result = await controller.Get(1); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnCode = Assert.IsType <CodeDTO>(okResult.Value); Assert.Equal("Test One", returnCode.Name); }
public async Task Get_ReturnsEmptyListCodeDTO_GivenEmptyList() { // Arrange var mockRepo = new Mock <IService <Code> >(); var returning = "empty"; var dbMock = GetCodes(returning); mockRepo.Setup(x => x.Get()).Returns(dbMock); var controller = new CodesController(mockRepo.Object); // Act var result = await controller.Get(); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnCodes = Assert.IsType <List <CodeDTO> >(okResult.Value); Assert.Empty(returnCodes); }
public async Task Get_ReturnsListCodeDTO_GivenListCode() { // Arrange var mockRepo = new Mock <IService <Code> >(); var dbMock = GetCodes(); mockRepo.Setup(x => x.Get()).Returns(dbMock); var controller = new CodesController(mockRepo.Object); // Act var result = await controller.Get(); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnCodes = Assert.IsType <List <CodeDTO> >(okResult.Value); Assert.Equal(2, returnCodes.Count); Assert.Equal("Test One", returnCodes[0].Name); Assert.Equal("Test Two", returnCodes.FindLast(x => x.Name == "Test Two").Name); }