public ViewResult Search(SearchViewModel viewModel)
        {
            viewModel.Properties = UnitOfWork.GetRepository<Property>().Get();

            var stateService = new PropertyStateService(UnitOfWork);
            var propertyStates = viewModel.States
                .Select(pair => stateService.GetState(pair.Key, pair.Value))
                .Where(propertyState => propertyState != null)
                .ToList();

            var searchService = new SearchService(UnitOfWork);
            viewModel.Packages = searchService.FindPackageWithSamePropertyStates(propertyStates);

            return View(viewModel);
        }
        public void SearchPost_NotAllPropertySpecified_PackageFound()
        {
            // Arrange
            var viewModel = new SearchViewModel();
            viewModel.States = new Dictionary<int, string> {{1, ""}, {2, "state4"}};

            // Act
            var result = _controller.Search(viewModel);

            // Assert
            var model = (SearchViewModel) result.Model;
            model.Packages.Single().ID.Should().Be(2);
        }
        public void SearchPost_NoMatchedPackages_NoPackageFound()
        {
            // Arrange
            var viewModel = new SearchViewModel();
            viewModel.States = new Dictionary<int, string> {{1, "state1"}, {2, "state4"}};

            // Act
            var result = _controller.Search(viewModel);

            // Assert
            var model = (SearchViewModel) result.Model;
            model.Packages.Should().BeEmpty();
        }
        public void SearchPost_ManyMatchedPackages_AllMatchedPackagesFound()
        {
            // Arrange
            var property = _unitOfWork.GetRepository<Property>().GetByID(1);
            var state1 = property.States.First();
            var state2 = property.States.Last();
            var newPackage = new ContentPackage
                             {ID = 3, PropertyStates = new Collection<PropertyState> {state1, state2}};
            state1.ContentPackages.Add(newPackage);
            state2.ContentPackages.Add(newPackage);
            _unitOfWork.GetRepository<ContentPackage>().Insert(newPackage);

            var viewModel = new SearchViewModel();
            viewModel.States = new Dictionary<int, string> {{1, "state1"}, {2, ""}};

            // Act
            var result = _controller.Search(viewModel);

            // Assert
            var model = (SearchViewModel) result.Model;
            model.Packages.Should().HaveCount(2);
        }
 public ViewResult Search()
 {
     var viewModel = new SearchViewModel();
     viewModel.Properties = UnitOfWork.GetRepository<Property>().Get();
     return View(viewModel);
 }