public void HandlerShouldAddOffer() { // Arrange var command = new MakeOfferCommand { PropertyId = 1 }; // Act _handler.Handle(command); // Assert var property = _context.Properties.First(); Assert.IsNotEmpty(property.Offers); }
public void HandleShouldAddOfferToProperty() { // Arrange var offerCommand = new MakeOfferCommand() { PropertyId = 1, UserId = Guid.NewGuid().ToString(), Offer = 1 }; var command = new ListPropertyCommand { PropertyId = 1 }; var property = new Domain.Models.Property { Id = 1, Description = "Test Property" }; _context.Properties.Find(1).Returns(property); // Act _offerHandler.Handle(offerCommand); // Assert var testProperty = _context.Properties.Find(1); Assert.That(testProperty.Offers.Count, Is.EqualTo(1)); Assert.That(testProperty.Offers.First().UserId, Is.EqualTo(offerCommand.UserId)); Assert.That(testProperty.Offers.First().Amount, Is.EqualTo(offerCommand.Offer)); }
public void HandleShouldAddOffer() { // Arrange var command = new MakeOfferCommand { PropertyId = 1, BuyerUserId = "111", Offer = 1000, }; var property = new Models.Property { Description = "Test Property", IsListedForSale = true, Id = 1, }; _properties.Find(1).Returns(property); // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Find(1); _context.Received(1).SaveChanges(); Assert.AreNotEqual(property.Offers, null); }
public ActionResult MakeOffer(MakeOfferCommand command) { var handler = new MakeOfferCommandHandler(_context); handler.Handle(command); return(RedirectToAction("Index")); }
public ActionResult MakeOffer(MakeOfferCommand command) { var handler = new MakeOfferCommandHandler(this._context); command.BuyerUserId = this.User.Identity.GetUserId(); handler.Handle(command); return(this.RedirectToAction("Index")); }
public ActionResult MakeOffer(MakeOfferCommand command) { var handler = new MakeOfferCommandHandler(_context); string buyerId = User.Identity.GetUserId(); handler.Handle(command, buyerId); return(RedirectToAction("Index")); }
public ActionResult MakeOffer(MakeOfferCommand command) { command.BuyerUserId = UserId; var handler = new MakeOfferCommandHandler(Context); handler.Handle(command); return(RedirectToAction("Index")); }
public ActionResult MakeOffer(MakeOfferCommand command) { //todo: come up with more elegant way of handling this command.BuyerUserId = User.Identity.GetUserId(); var handler = new MakeOfferCommandHandler(_context); handler.Handle(command); return(RedirectToAction("Index")); }
public ActionResult MakeOffer(MakeOfferCommand command) { var handler = new MakeOfferCommandHandler(_context); // Add the user id of the buyer making the offer. command.UserId = User.Identity.GetUserId(); handler.Handle(command); return(RedirectToAction("Index")); }
public ActionResult MakeOffer(MakeOfferCommand command) { // Set the BuyerUserId before calling the command handler command.BuyerUserId = User.Identity.GetUserId(); var handler = new MakeOfferCommandHandler(_context); handler.Handle(command); return(RedirectToAction("Index")); }
public ActionResult MakeOffer(MakeOfferCommand command) { try { if (ModelState.IsValid) { var handler = new MakeOfferCommandHandler(_context); command.BuyerUserId = User.Identity.GetUserId(); if (!handler.Handle(command)) { ModelState.AddModelError("", "You already placed an offer."); } else { return(RedirectToAction("Index")); } } } catch (Exception ex) { ModelState.AddModelError("", "Adding offer failed."); } var property = _context.Properties.Find(command.PropertyId); MakeOfferViewModel model = new MakeOfferViewModel { PropertyId = property.Id, PropertyType = property.PropertyType, StreetName = property.StreetName, Offer = property.SuggestedAskingPrice }; PropertiesViewModel m = new PropertiesViewModel { Search = "", Properties = new System.Collections.Generic.List <PropertyViewModel> { new PropertyViewModel { Id = property.Id, PropertyType = property.PropertyType, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, IsListedForSale = property.IsListedForSale, SuggestedAskingPrice = property.SuggestedAskingPrice } } }; return(View("Index", m)); }
public void OfferIsCreatedAndItsDataIsCorrect() { // Arrange var command = new MakeOfferCommand { BuyerUserId = "1", Offer = 1, PropertyId = 1 }; // Act _handler.Handle(command); // Assert _context.Received(1).SaveChanges(); var property = _context.Properties.FirstOrDefault(p => p.Id == 1); Assert.True(property.Offers != null); Assert.True(property.Offers.Count > 0); Assert.True(property.Offers.ElementAt(0).Amount == 1); Assert.True(property.Offers.ElementAt(0).BuyerUserId == "1"); }
public void HandleShouldAddOffer() { var property = new Models.Property { Description = "Test Property", IsListedForSale = false }; _properties.Find(1).Returns(property); var command = new MakeOfferCommand(); command.PropertyId = 1; command.Offer = 9999; command.BuyerUserId = "Test Buyer"; _handler.Handle(command); _context.Properties.Received(1).Find(1); _context.Received(1).SaveChanges(); Assert.True(property.Offers.Count == 1); Assert.True(property.Offers.First().Amount == 9999); Assert.True(property.Offers.First().BuyerUserId == "Test Buyer"); }