public void BuildShouldReturnPropertiesWithMatchingDescriptionsWhenSearchTermIsProvided() { // Arrange var builder = new PropertiesViewModelBuilder(_context); var properties = new List <Models.Property> { new Models.Property { StreetName = "", Description = "Great location", IsListedForSale = true }, new Models.Property { StreetName = "", Description = "Town house", IsListedForSale = true } }; var mockSet = Substitute.For <IDbSet <Models.Property> >() .Initialize(properties.AsQueryable()); _context.Properties.Returns(mockSet); var command = new FindPropertyCommand { Search = "Town" }; // Act var viewModel = builder.Build(command); // Assert Assert.That(viewModel.Properties.Count, Is.EqualTo(1)); Assert.That(viewModel.Properties.All(p => p.Description.Contains("Town"))); }
public ActionResult Index(FindPropertyCommand command) { var builder = new PropertiesViewModelBuilder(this._context); var viewModel = builder.Build(command); return(this.View(viewModel)); }
public PropertiesViewModel Build(FindPropertyCommand query) { var properties = this._context.Properties .Where(p => p.IsListedForSale); if (!string.IsNullOrWhiteSpace(query.Search)) { properties = properties.Where(x => x.StreetName.Contains(query.Search) || x.Description.Contains(query.Search)); } return(new PropertiesViewModel { Properties = properties .ToList() .Select(MapViewModel) .ToList(), Search = query.Search }); }