public async Task Test_AddOffer_ShouldAddOffer() { var offer = new EditOfferDTO { Title = "NewlyAdded" }; var context = await GetContext(); var offerRepo = new DbRepository <Offer>(context); var offerService = new OfferService(offerRepo); int result = await offerService.EditOffer(offer); Assert.Equal(5, context.Offers.CountAsync().Result); Assert.Contains("NewlyAdded", context.Offers.Select(p => p.Title).ToArray()); }
public async Task Test_EditOffer_ShouldUpdateOffer() { var context = await GetContext(); var offerRepo = new DbRepository <Offer>(context); var offerService = new OfferService(offerRepo); var editDto = new EditOfferDTO { Id = 72, Title = "Edited offer" }; int id = await offerService.EditOffer(editDto); var offers = context.Offers.ToArray(); var editedOfferTitle = offerService.GetTitleById(id); Assert.Equal("Edited offer", context.Offers .SingleOrDefault(p => p.Id == id) .Title); }
public async Task <int> EditOffer(EditOfferDTO edit) { var offer = this.offers.All().FirstOrDefault(p => p.Id == edit.Id); offer.ImageUrl = edit.ImageUrl; if (edit.Price != null) { offer.Price = edit.Price; } offer.Address = edit.Address; offer.Description = edit.Description; offer.SubjectId = edit.SubjectNameId; offer.Title = edit.Title; int result = await this.offers.SaveChangesAsync(); return(edit.Id); }