private static PropertyViewModel MapViewModel(Domain.Models.Property property, string userId) { var buyerAcceptedOffer = property.Offers?.Where(o => o.UserId == userId && o.Status == OfferStatus.Accepted) .Select(o => new AcceptedOfferViewModel() { Id = o.Id, Offer = o.Amount }).SingleOrDefault(); var buyerBookedViewing = property.Viewings?.Where(v => v.UserId == userId && v.ViewingDate > DateTime.Now) .Select(v => new BookViewingViewModel() { Id = v.Id, ViewingDate = v.ViewingDate, IsConfirmed = v.ViewingStatus == ViewingStatus.Confirmed }).SingleOrDefault(); return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, BuyerOfferAccepted = buyerAcceptedOffer, // TODO: Ensure only one offer is accepted for a property at any time. BuyerBookedViewing = buyerBookedViewing // TODO: Ensure only one viewing is allowed at any one time. }); }
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 BuildShouldReturnBookViewingViewModelWithValidViewingDate() { // Arrange var builder = new BookViewingViewModelBuilder(_context); var viewingsProperty1 = new List <Viewing> { new Viewing { ViewingDate = DateTime.Now }, new Viewing { ViewingDate = DateTime.Now.AddDays(1) } }; var property = new Domain.Models.Property { Id = 5000, StreetName = "Smith Street", Description = "", IsListedForSale = true }; _context.Properties.Find(property.Id).Returns(property); // Act var viewModel = builder.Build(property.Id); // Assert Assert.That(viewModel.ViewingDate, Is.AtMost(DateTime.Now)); }
public void HandleShouldAddViewingToProperty() { // Arrange var userId = Guid.NewGuid().ToString(); var bookViewingCommand = new BookViewingCommand() { PropertyId = 1, ViewingDate = DateTime.Now, UserId = userId }; var property = new Domain.Models.Property { Id = 1, Description = "Test Property" }; _context.Properties.Find(1).Returns(property); // Act _bookViewingHandler.Handle(bookViewingCommand); // Assert var testProperty = _context.Properties.Find(1); Assert.That(testProperty.Viewings.Count, Is.EqualTo(1)); Assert.That(testProperty.Viewings.First().UserId, Is.EqualTo(userId)); Assert.That(testProperty.Viewings.First().ViewingDate, Is.EqualTo(bookViewingCommand.ViewingDate)); Assert.That(testProperty.Viewings.First().ViewingStatus, Is.EqualTo(ViewingStatus.Pending)); }
public void Handle(CreatePropertyCommand command) { var property = new Domain.Models.Property { PropertyType = command.PropertyType, StreetName = command.StreetName, Description = command.Description, NumberOfBedrooms = command.NumberOfBedrooms }; property.SellerUserId = command.SellerUserId; _context.Properties.Add(property); _context.SaveChanges(); }
public void HandleShouldUpdatePropertyToBeListedForSale() { // Arrange var command = new ListPropertyCommand { PropertyId = 1 }; var property = new Domain.Models.Property { Description = "Test Property", IsListedForSale = false, }; _properties.Find(1).Returns(property); // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Find(1); _context.Received(1).SaveChanges(); Assert.True(property.IsListedForSale); }