public async void GetBuildingById_BuildingNotExists_NotFoundResult() { int id = 1; var mockBuildingRepo = new Mock <IRepositoryAsync <Building> >(); //mockBuildingRepo.Setup(repo => repo.FindAsync(id)) // .ReturnsAsync(null); var controller = new BuildingController(null, mockBuildingRepo.Object); // Act var result = await controller.GetBuildingById(id); // Assert var NotFoundResult = Assert.IsType <NotFoundResult>(result); Assert.Equal(StatusCodes.Status404NotFound, NotFoundResult.StatusCode); }
public async void GetBuildingById_ReturnsBuilding_OKObjectResult() { // Arrange int id = 1; var mockBuildingRepo = new Mock <IRepositoryAsync <Building> >(); mockBuildingRepo.Setup(repo => repo.FindAsync(id)) .ReturnsAsync(new Building { Name = "Test", Id = id }); var controller = new BuildingController(null, mockBuildingRepo.Object); // Act var result = await controller.GetBuildingById(id) as ObjectResult; // Assert var OkResult = Assert.IsType <OkObjectResult>(result); var building = Assert.IsAssignableFrom <Building>(result.Value); Assert.Equal(1, building.Id); Assert.Equal("Test", building.Name); }