public void DeleteCityTest() { var result = citiesController.DeleteCity(1); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(OkResult)); }
public async Task Given_A_City_Request_Verify_Service_Method_Are_Called_Once() { //Arrange var cityController = new CitiesController(_serviceCore.Object); _serviceCore.Setup(x => x.GetCityByNameAsync(It.IsAny <string>())); _serviceCore.Setup(x => x.AddCityAsync(It.IsAny <CityAddTransferModel>())); _serviceCore.Setup(x => x.UpdateCityAsync(It.IsAny <int>(), It.IsAny <CityUpdateTransferModel>())); _serviceCore.Setup(x => x.DeleteCityAsync(It.IsAny <int>())); _serviceCore.Setup(x => x.CityExistsAsync(It.IsAny <int>())).ReturnsAsync(true); //Act await cityController.GetCity("test"); await cityController.CreateCity(new CityAddTransferModel()); await cityController.UpdateCity(1, new CityUpdateTransferModel()); await cityController.DeleteCity(1); //Assert _serviceCore.Verify(x => x.GetCityByNameAsync(It.IsAny <string>()), Times.Once); _serviceCore.Verify(x => x.GetCityByNameAsync(It.IsAny <string>()), Times.Once); _serviceCore.Verify(x => x.AddCityAsync(It.IsAny <CityAddTransferModel>()), Times.Once); _serviceCore.Verify(x => x.UpdateCityAsync(It.IsAny <int>(), It.IsAny <CityUpdateTransferModel>()), Times.Once); _serviceCore.Verify(x => x.DeleteCityAsync(It.IsAny <int>()), Times.Once); }
public void DeleteCity() { var repo = new MockUnitOfWork(); var controller = new CitiesController(repo, _mapper); var citiyId = 0; repo.Cities.Add(_testData.Cities.FirstOrDefault(c => c.Id == citiyId)); var response = controller.DeleteCity(citiyId); Assert.IsType <NoContentResult>(response); Assert.Null(repo.Cities.SingleOrDefault(c => c.Id == citiyId)); }
public void DeleteCityResponseIsNotNull() { // Arrange controller = new CitiesController(mockUnitOfWork.Object); int id = 1; // Act controller.DeleteCity(id); // Assert mockUnitOfWork.Verify(i => i.CityRepository .Remove(mockUnitOfWork.Object.CityRepository.FindById(id)), Times.Once()); }
public async Task Given_A_Unsuccessfull_Delete_Request_ReturnsNotFound() { // Arrange _serviceCore.Setup(x => x.CityExistsAsync(It.IsAny <int>())).ReturnsAsync(false); _serviceCore.Setup(x => x.DeleteCityAsync(It.IsAny <int>())).ReturnsAsync(false); var controller = new CitiesController(_serviceCore.Object); // Act ActionResult actionResult = await controller.DeleteCity(1); // Assert Assert.IsInstanceOfType(actionResult, typeof(NotFoundObjectResult)); }