public void GetCity_ShouldReturnCorrectCity() { Guid guid = new Guid("c42ae80e-346f-4a4d-b4d9-2834c762a27f");//city1 var response = controller.GetCity(guid); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var city = response.Content.ReadAsAsync <City>().Result; Assert.AreEqual(guid, city.Id); Assert.AreEqual("city1", city.CityName); }
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 GetCity_NoEF_ReturnsNotFound() { var controller = new CitiesController(_mockCityInfoRepository.Object, _mockMongoRepository.Object, _mockLogger.Object, _mockMailService.Object); var result = controller.GetCity(1); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public async Task GetCity_ReturnsOk() { var controller = new CitiesController(); var result = await controller.GetCity(1); Assert.IsType <OkObjectResult>(result); }
public void GetCityReturnOkObjectResult() { var sut = new CitiesController(); ActionResult response = sut.GetCity(1); Assert.IsType <OkObjectResult>(response); }
public void GetCityReturnNotFound() { var sut = new CitiesController(); ActionResult response = sut.GetCity(4); Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundResult>(response); }
public async void GetCity() { #region Arrange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "WorldCities") .Options; var storeOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(options, storeOptions)) { context.Add(new City() { Id = 1, Name = "TestCity1", CountryId = 1, Lat = 1, Lon = 1, Country = new Country() { Id = 1, Name = "TestCountry1", ISO2 = "AB", ISO3 = "ABC" } }); context.SaveChanges(); } City city_existing = null; City city_notExisting = null; #endregion #region Act using (var context = new ApplicationDbContext(options, storeOptions)) { var controller = new CitiesController(context); city_existing = (await controller.GetCity(1)).Value; city_notExisting = (await controller.GetCity(2)).Value; } #endregion #region Assert Assert.True(city_existing != null && city_notExisting == null); #endregion }
public async void GetCity() { #region Arrange //Define the required assets var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "WorldCities") .Options; var storeOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(options, storeOptions)) { context.Add(new City() { Id = 1, CountryId = 1, Lat = 1, Lon = 1, Name = "TestCity1" }); context.SaveChanges(); } City city_existing = null; City city_notExisting = null; #endregion #region Act //Invoke the test using (var context = new ApplicationDbContext(options, storeOptions)) { var controller = new CitiesController(context); city_existing = (await controller.GetCity(1)).Value; city_notExisting = (await controller.GetCity(2)).Value; } #endregion #region Assert //Verify that conditions are met. Assert.NotNull(city_existing); Assert.Null(city_notExisting); #endregion }
public async Task GetCity_ReturnObjectDeserialilzableToCityObject() { var controller = new CitiesController(); var result = await controller.GetCity(1) as OkObjectResult; var city = result.Value as City; Assert.IsType <City>(city); }
public async Task GetCity_ReturnsCorrectCity() { var controller = new CitiesController(); var result = await controller.GetCity(1) as OkObjectResult; var city = result.Value as City; Assert.Equal(1, city.Id); }
public void GetCityReturnACity() { var sut = new CitiesController(); OkObjectResult response = sut.GetCity(1) as OkObjectResult; CityDTO city = response.Value as CityDTO; Assert.NotNull(response); Assert.Equal(200, response.StatusCode); Assert.Equal("New York City", city.Name); }
public void GetCity_Should_Resolve_Dependency_And_Return_Not_Found() { var mockedRepo = new Mock <ICitiesRepository>(); mockedRepo.Setup(f => f.GetCity(It.IsAny <int>())).Returns((City)null); var controller = new CitiesController(mockedRepo.Object); var actionResult = controller.GetCity(111); var result = actionResult as NotFoundResult; Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public void GetCityResponseIsNotNull() { // Arrange controller = new CitiesController(mockUnitOfWork.Object); int id = 1; // Act var result = controller.GetCity(id); // Assert Assert.IsNotNull(result); mockUnitOfWork.Verify(i => i.CityRepository.FindById(id), Times.Once()); }
public async void GetCiyShouldReturnCity() { //Arrange var storeOptions = Options.Create(new OperationalStoreOptions()); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "WorldCitiesDb").Options; using (var context = new ApplicationDbContext(options, storeOptions)) { context.Add(new City() { Id = 1, CountryId = 1, Lat = 1, Lon = 1, Name = "Test City" }); context.SaveChanges(); } City city_existing = null; City city_notExisting = null; //Act using (var context = new ApplicationDbContext(options, storeOptions)) { var controller = new CitiesController(context); city_existing = (await controller.GetCity(1)).Value; city_notExisting = (await controller.GetCity(10)).Value; } //Assert Assert.NotNull(city_existing); Assert.Null(city_notExisting); }
public async void GetCity() { #region Arrange var logger = Mock.Of <ILogger <CitiesController> >(); var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "WorldCities").Options; using (var context = new ApplicationDbContext(options)) { context.Add(new City() { Id = 1, CountryId = 1, Lat = 1, Lon = 1, Name = "TestCity1" }); context.SaveChanges(); } City city_existing = null; City city_notExisting = null; #endregion #region Act using (var context = new ApplicationDbContext(options)) { var controller = new CitiesController(context, logger); city_existing = (await controller.GetCity(1)).Value; city_notExisting = (await controller.GetCity(2)).Value; } #endregion #region Assert Assert.NotNull(city_existing); Assert.Null(city_notExisting); #endregion }
public void GetCity() { //Arrange var repo = new MockUnitOfWork(); var controller = new CitiesController(repo, _mapper); var city1 = _testData.Cities.First(); var city2 = _testData.Cities.Last(); controller.PostCity(city1); controller.PostCity(city2); //Act var response = controller.GetCity(city2.Id, false); // Assert var responseObjectResult = response as ObjectResult; Assert.Equal(200, responseObjectResult.StatusCode); }
public async Task Given_A_Valid_City_Request_ReturnsOK() { // Arrange _serviceCore.Setup(x => x.GetCityByNameAsync(It.IsAny <string>())) .ReturnsAsync(new List <CityTransferModel>() { new CityTransferModel() { Name = "CityName" } }); var controller = new CitiesController(_serviceCore.Object); // Act var response = await controller.GetCity("CityName"); // Assert Assert.IsInstanceOfType(response, typeof(OkObjectResult)); }
public void GetCity_Should_Resolve_Dependency_And_Return_City() { var mockedRepo = new Mock <ICitiesRepository>(); var city = new City() { Id = 1, Name = "Sydney" }; mockedRepo.Setup(f => f.GetCity(It.IsAny <int>())).Returns(city); var controller = new CitiesController(mockedRepo.Object); var actionResult = controller.GetCity(111); var result = actionResult as OkNegotiatedContentResult <City>; Assert.IsNotNull(result); var resultCity = result.Content as City; Assert.IsTrue(resultCity.Name == "Sydney"); }
public void GetCity_ReturnsOk() { //set up Moq to return a city var cityInfoRepo = new Mock <ICityInfoRepository>(); cityInfoRepo.Setup(r => r.GetCity(It.IsAny <int>())) .Returns(new City { Id = 1, Name = "Test City", Description = "Test Description" }); //call GetCity var controller = new CitiesController(cityInfoRepo.Object, _mockMongoRepository.Object, _mockLogger.Object, _mockMailService.Object); var result = controller.GetCity(1); //cast the response to the correct type - each type has different properties Assert.IsInstanceOfType(result, typeof(OkObjectResult)); var responseDto = ((OkObjectResult)result).Value as CityDto; Assert.AreEqual(1, responseDto.Id, "wrong id"); Assert.AreEqual("Test City", responseDto.Name, "wrong name"); Assert.AreEqual("Test Description", responseDto.Description, "wrong description"); }