public async Task ReturnResutViewWithProperModel_WhenValidOfferModelIsAndInvalidIdPassed() { int validOfferId = 1; var sale = new OfferCUViewModel { OfferID = validOfferId, ClientID = 1, DeadlineDate = new DateTime(2019, 5, 5), AddressID = 1, CityID = 1, CountryID = 1, ProductDiscount = 10, }; var sut = CreateController(); sut.ModelState.AddModelError("error", "error"); AddressService.Setup(x => x.GetAllAddressesAsync()).ReturnsAsync(new List <Address>()); CityService.Setup(x => x.GetAllCitiesAsync()).ReturnsAsync(new List <City>()); CountryService.Setup(x => x.GetAllCountriesAsync()).ReturnsAsync(new List <Country>()); ClientService.Setup(x => x.GetAllClientsAsync(It.IsAny <int>(), It.IsAny <int>(), "*")).ReturnsAsync(new List <Client>()); //Act var result = await sut.Edit(validOfferId, sale); //Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.IsInstanceOfType((result as ViewResult).Model, typeof(OfferCUViewModel)); AddressService.Verify(mock => mock.GetAllAddressesAsync(), Times.Once()); CityService.Verify(mock => mock.GetAllCitiesAsync(), Times.Once()); CountryService.Verify(mock => mock.GetAllCountriesAsync(), Times.Once()); ClientService.Verify(mock => mock.GetAllClientsAsync(It.IsAny <int>(), It.IsAny <int>(), "*"), Times.Once()); }
public async Task <IActionResult> Edit(int id, OfferCUViewModel offer) { if (id != offer.OfferID) { return(this.NotFound()); } if (this.ModelState.IsValid) { try { await this.offerService.UpdateOfferAsync( offer.OfferID, offer.ClientID, offer.ProductDiscount, offer.OrderDate, (offer.DeadlineDate - offer.OrderDate).Days, offer.DeliveryDate, offer.AddressID, offer.CityID, offer.CountryID); } catch (Exception ex) { this.ModelState.AddModelError("Error", ex.Message); } return(this.RedirectToAction(nameof(Index))); } this.ViewData["Clients"] = new SelectList(await this.clientService.GetAllClientsAsync(), "ClientID", "Name", offer.ClientID); this.ViewData["Addresses"] = new SelectList(await this.addressService.GetAllAddressesAsync(), "AddressID", "Name", offer.AddressID); this.ViewData["Cities"] = new SelectList(await this.cityService.GetAllCitiesAsync(), "CityID", "Name", offer.CityID); this.ViewData["Countries"] = new SelectList(await this.countryService.GetAllCountriesAsync(), "CountryID", "Name", offer.CountryID); return(this.View(offer)); }
public async Task ReturnProper_WhenValidOfferIdIsPassed() { int validOfferId = 1; var sale = new OfferCUViewModel { OfferID = validOfferId, ClientID = 1, OrderDate = new DateTime(2019, 5, 5), AddressID = 1, CityID = 1, CountryID = 1, ProductDiscount = 10, DeadlineDate = new DateTime(2019, 5, 5).AddDays(1), DeliveryDate = new DateTime(2019, 5, 5) }; var sut = CreateController(); sut.ModelState.ClearValidationState("error"); //Act var result = await sut.Edit(validOfferId, sale); //Assert Assert.IsInstanceOfType(result, typeof(RedirectToActionResult)); OfferService.Verify(mock => mock.UpdateOfferAsync(validOfferId, 1, 10, new DateTime(2019, 5, 5), 1, new DateTime(2019, 5, 5), 1, 1, 1), Times.Once()); AddressService.Verify(mock => mock.GetAllAddressesAsync(), Times.Never()); CityService.Verify(mock => mock.GetAllCitiesAsync(), Times.Never()); CountryService.Verify(mock => mock.GetAllCountriesAsync(), Times.Never()); ClientService.Verify(mock => mock.GetAllClientsAsync(It.IsAny <int>(), It.IsAny <int>(), "*"), Times.Never()); }
public async Task <IActionResult> Create(OfferCUViewModel offer) { if (this.ModelState.IsValid) { await this.offerService.CreateOfferAsync(offer.ClientID, offer.ProductDiscount, offer.DeadlineDate, offer.AddressID, offer.CityID, offer.CountryID); return(this.RedirectToAction(nameof(Index))); } this.ViewData["Clients"] = new SelectList(await this.clientService.GetAllClientsAsync(), "ClientID", "Name", offer.ClientID); this.ViewData["Addresses"] = new SelectList(await this.addressService.GetAllAddressesAsync(), "AddressID", "Name", offer.AddressID); this.ViewData["Cities"] = new SelectList(await this.cityService.GetAllCitiesAsync(), "CityID", "Name", offer.CityID); this.ViewData["Countries"] = new SelectList(await this.countryService.GetAllCountriesAsync(), "CountryID", "Name", offer.CountryID); return(this.View(offer)); }
public async Task ReturnNotFoundResult_WhenInvalidOfferIdIsPassed() { int invalidOfferId = 1; var sale = new OfferCUViewModel { OfferID = 2, ClientID = 1, DeadlineDate = new DateTime(2019, 5, 5), AddressID = 1, CityID = 1, CountryID = 1, ProductDiscount = 10, }; var sut = CreateController(); //Act var result = await sut.Edit(invalidOfferId, sale); //Assert Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }