public void CallAddCityOnCityServiceWIthExpectedCity() { // Arrange var countryService = new Mock <ICountryService>(); var airlineService = new Mock <IAirlineService>(); var flightService = new Mock <IFlightService>(); var mappingService = new Mock <IMappingService>(); var cityService = new Mock <ICityService>(); var airportService = new Mock <IAirportService>(); var jobService = new Mock <IJobService>(); var adminController = new AdminController(countryService.Object, mappingService.Object, cityService.Object, airlineService.Object, airportService.Object, flightService.Object, jobService.Object); var cityViewModel = new CityViewModel() { Id = 1 }; var city = new City() { Id = 1 }; mappingService.Setup(m => m.Map <City>(cityViewModel)).Returns(city); // Act adminController.AddCity(cityViewModel); // Assert cityService.Verify(c => c.AddCity(city), Times.Once); }
public async Task WhenCityObject_IsNull_ReturnsBadRequest() { // Arrange CityDTO cityDTO = null; // Act var result = (ObjectResult)await _adminController.AddCity(cityDTO); // Assert Assert.AreEqual((int)HttpStatusCode.BadRequest, result.StatusCode); }
public void CallMapOnMappingServiceOnExpectedCountries() { // Arrange var countryService = new Mock <ICountryService>(); var airlineService = new Mock <IAirlineService>(); var flightService = new Mock <IFlightService>(); var mappingService = new Mock <IMappingService>(); var cityService = new Mock <ICityService>(); var airportService = new Mock <IAirportService>(); var jobService = new Mock <IJobService>(); var adminController = new AdminController(countryService.Object, mappingService.Object, cityService.Object, airlineService.Object, airportService.Object, flightService.Object, jobService.Object); var countries = new List <Country>() { new Country() { Id = 1, Name = "First" }, new Country() { Id = 2, Name = "Second" }, new Country() { Id = 3, Name = "Third" } }; countryService.Setup(c => c.GetAllCountries()).Returns(countries); var countryViewModel = new CountryViewModel() { Id = 1, Name = "Name" }; mappingService.Setup(m => m.Map <CountryViewModel>(It.IsAny <Country>())).Returns(countryViewModel); // Act adminController.AddCity(); // Assert foreach (var country in countries) { mappingService.Verify(m => m.Map <CountryViewModel>(country), Times.Once); } }
public void CallGetAllCountriesOnCountryService() { // Arrange var countryService = new Mock <ICountryService>(); var airlineService = new Mock <IAirlineService>(); var flightService = new Mock <IFlightService>(); var mappingService = new Mock <IMappingService>(); var cityService = new Mock <ICityService>(); var airportService = new Mock <IAirportService>(); var jobService = new Mock <IJobService>(); var adminController = new AdminController(countryService.Object, mappingService.Object, cityService.Object, airlineService.Object, airportService.Object, flightService.Object, jobService.Object); // Act adminController.AddCity(); // Assert countryService.Verify(c => c.GetAllCountries(), Times.Once); }
public void Admin_AddCity_NullValuePassing() { //Arrange AdminController adminController = new AdminController() { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } } }; CityDetails city = new CityDetails(); //Act var response = adminController.AddCity(city); //Assert Assert.AreEqual(HttpStatusCode.Conflict, response.StatusCode); }
public void Admin_AddCity_WrongDetails() { //Arrange AdminController adminController = new AdminController() { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } } }; CityDetails city = new CityDetails(); city.cityName = "Nasik"; //Same City that is already been added in the database //Act var response = adminController.AddCity(city); //Assert Assert.AreEqual(HttpStatusCode.Conflict, response.StatusCode); }
public void Admin_AddCity_CorrectDetails() { //Arrange CityDetails city = new CityDetails(); AdminController adminController = new AdminController() { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } } }; city.cityName = "Nasik"; //Act var response = adminController.AddCity(city); //Assert Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); }