public async Task EditAsyncThrowsWhenTheInputModelIsNull() { // Arrange var mapperMock = new Mock <IMapper>(); var repositoryMock = new Mock <IDeletableEntityRepository <City> >(); var citiesService = new CitiesService(repositoryMock.Object, mapperMock.Object); // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { // Act await citiesService.EditAsync("validId", null, new ImageInputModel()); }); }
public async Task EdidAsyncSetsTheNewPropertiesAndSavesTheResult( string name, string description, string countryId, string newName, string newDescription, string newCountryId, bool imageNull, string imageSource, string newImageSource) { // Arrange AutoMapperConfig.RegisterMappings(typeof(Test).Assembly, typeof(ErrorViewModel).Assembly); var saved = true; var city = new City() { Name = name, Description = description, CountryId = countryId, Image = new Image() { Source = imageSource, }, }; var citiesList = new List <City>() { new City(), city, new City(), new City(), new City(), }; var repositoryMock = new Mock <IDeletableEntityRepository <City> >(); repositoryMock.Setup(x => x.All()) .Returns(citiesList.AsQueryable()); repositoryMock.Setup(x => x.SaveChangesAsync()) .Callback(() => { saved = true; }); var citiesService = new CitiesService(repositoryMock.Object, AutoMapperConfig.MapperInstance); var cityEditModel = new CityInputModel() { Name = newName, Description = newDescription, CountryId = newCountryId, }; var imageEditModel = new ImageInputModel() { Source = newImageSource, }; if (imageNull) { imageEditModel = null; } // Act await citiesService.EditAsync(city.Id, cityEditModel, imageEditModel); // Assert Assert.True(saved); Assert.Equal(newName, city.Name); Assert.Equal(newDescription, city.Description); Assert.Equal(newCountryId, city.CountryId); var actualImage = city.Image; if (imageNull) { Assert.Equal(imageSource, actualImage.Source); } else { Assert.Equal(newImageSource, actualImage.Source); } }