Exemplo n.º 1
0
        public ActionResult SearchTabsPost(TabsViewModel viewModel)
        {
            var dic = new RouteValueDictionary()
                          {
                              {"tabkey", viewModel.TabKey},
                              {"tabid", viewModel.TabId},
                              {"MetalFilter", viewModel.MetalFilter},
                              {"OrderByPrice", viewModel.OrderByPrice},
                              {"itemsperpage", viewModel.ItemsPerPage}

                          };

            var counter = 0;
            if (viewModel.CustomFilters != null)
            {
                foreach (var filterValue in viewModel.CustomFilters)
                {
                    //TODO do tis strongly typed with reflaction
                    dic.Add("CustomFilters" + "[" + counter.ToString() + "].Value", filterValue.Value);
                    dic.Add("CustomFilters" + "[" + counter.ToString() + "].Name", filterValue.Name);
                    counter++;
                }
                dic.Add("page", 1);
            }
            else
            {
                dic.Add("page",viewModel.Page);
            }

            return RedirectToRoute("Tabs",dic );
        }
Exemplo n.º 2
0
        public ViewResult SearchTabs(TabsViewModel viewModel)
        {
            XDocument tabsource = xmlSourceFactory.TabSource();

            TabsViewModelBuilder modelBuilder = new TabsViewModelBuilder(viewModel, tabsource, tabsRepository, jewelRepository, fileSystem);

            viewModel = modelBuilder.Build();
            viewModel.PathBarItems = pathBarGenerator.GenerateUsing<TabsPathBarResolver, ITabsViewModel>(viewModel);

            return View("PresentTabs",viewModel);
        }
        public void Build_IfGivenATabKeyWithSpecialTebsReturnIsShowTabsToFalse()
        {
            //Arrange
            var jewelryRepository = MockRepository.GenerateMock<IJewelRepository>();
            var tabsRepository = CreateStubTabsRepository(TabKey);
            var fileSystem = FakeFileSystem.MediaFileSystemForItemNumber("0101-15001");

            var viewModel = new TabsViewModel();
            viewModel.TabKey = TAB_KEY;
            viewModel.TabId = SPECIAL_TABID1;

            var  tabsViewModelBuilder = new TabsViewModelBuilder(viewModel, xmldoc_specialtab, tabsRepository, jewelryRepository, fileSystem);
            viewModel = tabsViewModelBuilder.Build();

            //Act

            viewModel.IsShowTabs.Should().BeFalse();
            //Assert
        }
        public void Build_IfGivenAViewModelWithNoMetalFilterSetToDefaultOf1()
        {
            //Arrange
            var jewelryRepository = MockRepository.GenerateMock<IJewelRepository>();
            var tabsRepository = CreateStubTabsRepository(TabKey);
            var fileSystem = FakeFileSystem.MediaFileSystemForItemNumber("0101-15001");

            var viewModel = new TabsViewModel();
            viewModel.TabKey = TAB_KEY;
            viewModel.TabId = TAB_ID1;

            TabsViewModelBuilder tabsViewModelBuilder = new TabsViewModelBuilder(viewModel, xmldoc_regular3tabs, tabsRepository, jewelryRepository, fileSystem);
            viewModel = tabsViewModelBuilder.Build();

            //Act

            var tabsContainers = viewModel.JewelryInTabContainersCollection;

            //Assert
            tabsContainers.Should().OnlyContain(x => x.Metal == "White Gold 18K");
        }
        private TabsViewModelBuilder CreateDefaultTabsViewModelBuilderWithAllMetalFilter()
        {
            var settingManager = new FakeSettingManager();
            var tabsRepository = CreateStubTabsRepository(TabKey);
            var jewelryRepository = new FakeJewelRepository(settingManager);

            var fileSystem = FakeFileSystem.MediaFileSystemForItemNumber("0101-15421");

            var model = new TabsViewModel()
                            {
                                MetalFilter = JewelMediaType.All,
                                TabKey = TabKey,
                                TabId = TabID1

                            };

            TabsViewModelBuilder tabsViewModelBuilder = new TabsViewModelBuilder(model, xmldoc_regular3tabs,
                                                                                 tabsRepository, jewelryRepository, fileSystem);
            return tabsViewModelBuilder;
        }
        public void OrderBy_ShouldOrderByLowToHighWhenDefaultOrderingIsUsed()
        {
            //Arrange
            var jewelryRepository = MockRepository.GenerateMock<IJewelRepository>();
            var tabsRepository = CreateStubTabsRepository(TabKey);
            var fileSystem = FakeFileSystem.MediaFileSystemForItemNumber("0101-15001");

            var orderBy = new DynamicOrderBy("price","asc");

            jewelryRepository.Expect(x => x.OrderJewelryItemsBy(Arg<DynamicOrderBy>.Is.Equal(orderBy))).Repeat.Once();

            var viewModel = new TabsViewModel();
            viewModel.TabKey = TAB_KEY;
            viewModel.TabId = TAB_ID1;
            viewModel.MetalFilter = JewelMediaType.WhiteGold;

            var tabsViewModelBuilder = new TabsViewModelBuilder(viewModel, xmldoc_regular3tabs, tabsRepository, jewelryRepository,fileSystem);
            tabsViewModelBuilder.Build();

            //Act
            //Assert
            jewelryRepository.VerifyAllExpectations();
        }
        public void Build_ShouldPassTheCurrentValueOfTheGeneralFilterToTheViewModelForPresistance()
        {
            //Arrange

            //Arrange
            var jewelryRepository = MockRepository.GenerateMock<IJewelRepository>();
            var tabsRepository = CreateStubTabsRepository(TabKey);
            var fileSystem = FakeFileSystem.MediaFileSystemForItemNumber("0101-15001");

            var viewModel = new TabsViewModel
                                {
                                    TabKey = TAB_KEY,
                                    TabId = TAB_ID1,
                                    CustomFilters = new List<CustomTabFilterViewModel>
                                                        {
                                                            new CustomTabFilterViewModel()
                                                                {
                                                                    Name = "gemstone-center-stone",
                                                                    Value = (int) GemstoneCenterStoneFilterValues.Ruby
                                                                }
                                                        }
                                };

            var tabsViewModelBuilder = new TabsViewModelBuilder(viewModel, xmldoc_tabswithgeneralfilter, tabsRepository,
                                                                    jewelryRepository, fileSystem);

            //Act
            var result = tabsViewModelBuilder.Build();
            //Assert
            result.CustomFilters[0].Value.Should().Be(1);
        }
        public void Build_ShouldNotAddAFilterThatIsSetToDoNothing()
        {
            //Arrange
            var jewelryRepository = MockRepository.GenerateMock<IJewelRepository>();
            var tabsRepository = CreateStubTabsRepository(TabKey);
            var fileSystem = FakeFileSystem.MediaFileSystemForItemNumber("0101-15001");

            jewelryRepository.Expect(x => x.AddFilterList(Arg<List<DynamicSQLWhereObject>>
                                                              .Matches(
                                                                  m =>
                                                                  m[0].IsDoingNothing
                                                              ))).Repeat.Once();

            var viewModel = new TabsViewModel();
            viewModel.TabKey = TAB_KEY;
            viewModel.TabId = TAB_ID1;

            viewModel.CustomFilters = new List<CustomTabFilterViewModel>
                                          {
                                              new CustomTabFilterViewModel()
                                                  {
                                                      Name = "gemstone-center-stone",
                                                      Value = (int)GemstoneCenterStoneFilterValues.All

                                                  }
                                          };

            var tabsViewModelBuilder = new TabsViewModelBuilder(viewModel, xmldoc_tabswithgeneralfilter, tabsRepository,
                                                                    jewelryRepository, fileSystem);

            //Act
            tabsViewModelBuilder.Build();
            //Assert
            jewelryRepository.VerifyAllExpectations();
        }
        public void PresentTabs_ShouldReturntheRightNumberOfItemsAfterMetalWhiteGoldFilter()
        {
            //Arrange

            var tabKey = "diamond-rings";
            var tabId = "engagement-rings";

            var xmlSource = new XmlSourceFactory();
            var tabsRepository = new TabsRepository(xmlSource);
            var jewelryRepository = new JewelRepository(new SettingManager());
            var fileSystem = new FileSystem();
            var pathBarGenerator = MockRepository.GenerateStub<IPathBarGenerator>();

            var mapper = MockRepository.GenerateStub<IMappingEngine>();

            TabsController controller = new TabsController(tabsRepository, jewelryRepository, fileSystem, xmlSource,pathBarGenerator, mapper);

            var viewModel = new TabsViewModel();
            viewModel.TabKey = tabKey;
            viewModel.TabId = tabId;
            viewModel.MetalFilter = JewelMediaType.WhiteGold;

            //Act

            var resultview = controller.SearchTabs(viewModel);

            //Assert
            var model = resultview.Model as TabsViewModel;

            model.JewelryInTabContainersCollection.Should().HaveCount(9).And.OnlyContain(x=> x.PictureURL.Contains("wg"));
        }