public void Can_create_contentpublishingviewmodel_in_editmode_hardmode() { var repositoryFactory = new DSRepositoryFactory <IDynamicContentRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var storeRepositoryFactory = new DSRepositoryFactory <IStoreRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var countryRepositoryFactory = new DSRepositoryFactory <ICountryRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var appConfigRepositoryFactory = new DSRepositoryFactory <IAppConfigRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var searchCategoryVmFactory = new TestDynamicContentViewModelFactory <ISearchCategoryViewModel>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var navigationManager = new TestNavigationManager(); DynamicContentPlace[] contentPlaces; DynamicContentItem[] contentItems; using (var repository = repositoryFactory.GetRepositoryInstance()) { contentPlaces = TestContentPlacesBuilder.BuildContentPlaces().GetPlaces().ToArray(); contentItems = TestContentItemsBuilder.BuildsContentItems().GetItems().ToArray(); RepositoryHelper.AddItemToRepository(repository, contentItems.AsEnumerable()); RepositoryHelper.AddItemToRepository(repository, contentPlaces.AsEnumerable()); } //create fake innerItem var entityFactory = new DynamicContentEntityFactory(); var item = TestContentPublishingBuilder.BuildDynamicContentPublishingGroup() .WithContentItems(contentItems.Take(1).ToArray()) .WithContentPlaces(contentPlaces.Take(1).ToArray()) .GetContentPublishingGroup(); using (var repository = repositoryFactory.GetRepositoryInstance()) { RepositoryHelper.AddItemToRepository(repository, item); } var detailViewModel = new ContentPublishingItemViewModel(appConfigRepositoryFactory, countryRepositoryFactory, searchCategoryVmFactory, repositoryFactory, entityFactory, storeRepositoryFactory, navigationManager, item); Assert.NotNull(detailViewModel); detailViewModel.InitializeForOpen(); detailViewModel.InnerItem.Name = "EditName"; //edit 2 step detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Remove(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Remove(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); //edit 3 step detailViewModel.InnerItemDynamicContent.Add(contentItems[2]); detailViewModel.InnerItemDynamicContent.Remove(contentItems[2]); detailViewModel.InnerItemDynamicContent.Add(contentItems[2]); detailViewModel.InnerItemDynamicContent.Remove(contentItems[2]); //edit 4 step var expressionViewModel = detailViewModel.ExpressionElementBlock.ExpressionViewModel; detailViewModel.ExpressionElementBlock.Children[0] = TestContentPublishingExpressionBuilder.BuildContentPublishingExpressionBuilder( detailViewModel.ExpressionElementBlock.Children[0]) .AddCartTotalElement(expressionViewModel).AddConditionAddOrBlock(expressionViewModel).GetChild(); Assert.True(detailViewModel.IsValid); detailViewModel.SaveWithoutUIChanges(); //check the item from db using (var repository = repositoryFactory.GetRepositoryInstance()) { var itemFromDb = repository.PublishingGroups.Where( pg => pg.DynamicContentPublishingGroupId == detailViewModel.InnerItem.DynamicContentPublishingGroupId) .Expand(pg => pg.ContentItems).Expand(pg => pg.ContentPlaces).SingleOrDefault(); Assert.NotNull(itemFromDb); Assert.True(itemFromDb.ContentItems.Count == 1); Assert.True(itemFromDb.ContentPlaces.Count == 2); Assert.True(itemFromDb.Name == "EditName"); Assert.NotNull(itemFromDb.ConditionExpression); Assert.NotNull(itemFromDb.PredicateVisualTreeSerialized); } }
public void Can_create_contentpublishingviewmodel_in_editmode_hardmode() { var repositoryFactory = new DSRepositoryFactory<IDynamicContentRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var storeRepositoryFactory = new DSRepositoryFactory<IStoreRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var countryRepositoryFactory = new DSRepositoryFactory<ICountryRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var appConfigRepositoryFactory = new DSRepositoryFactory<IAppConfigRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var searchCategoryVmFactory = new TestDynamicContentViewModelFactory<ISearchCategoryViewModel>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var navigationManager = new TestNavigationManager(); DynamicContentPlace[] contentPlaces; DynamicContentItem[] contentItems; using (var repository = repositoryFactory.GetRepositoryInstance()) { contentPlaces = TestContentPlacesBuilder.BuildContentPlaces().GetPlaces().ToArray(); contentItems = TestContentItemsBuilder.BuildsContentItems().GetItems().ToArray(); RepositoryHelper.AddItemToRepository(repository, contentItems.AsEnumerable()); RepositoryHelper.AddItemToRepository(repository, contentPlaces.AsEnumerable()); } //create fake innerItem var entityFactory = new DynamicContentEntityFactory(); var item = TestContentPublishingBuilder.BuildDynamicContentPublishingGroup() .WithContentItems(contentItems.Take(1).ToArray()) .WithContentPlaces(contentPlaces.Take(1).ToArray()) .GetContentPublishingGroup(); using (var repository = repositoryFactory.GetRepositoryInstance()) { RepositoryHelper.AddItemToRepository(repository, item); } var detailViewModel = new ContentPublishingItemViewModel(appConfigRepositoryFactory, countryRepositoryFactory, searchCategoryVmFactory, repositoryFactory, entityFactory, storeRepositoryFactory, navigationManager, item); Assert.NotNull(detailViewModel); detailViewModel.InitializeForOpen(); detailViewModel.InnerItem.Name = "EditName"; //edit 2 step detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Remove(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Remove(contentPlaces[1]); detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); //edit 3 step detailViewModel.InnerItemDynamicContent.Add(contentItems[2]); detailViewModel.InnerItemDynamicContent.Remove(contentItems[2]); detailViewModel.InnerItemDynamicContent.Add(contentItems[2]); detailViewModel.InnerItemDynamicContent.Remove(contentItems[2]); //edit 4 step var expressionViewModel = detailViewModel.ExpressionElementBlock.ExpressionViewModel; detailViewModel.ExpressionElementBlock.Children[0] = TestContentPublishingExpressionBuilder.BuildContentPublishingExpressionBuilder( detailViewModel.ExpressionElementBlock.Children[0]) .AddCartTotalElement(expressionViewModel).AddConditionAddOrBlock(expressionViewModel).GetChild(); Assert.True(detailViewModel.IsValid); detailViewModel.SaveWithoutUIChanges(); //check the item from db using (var repository = repositoryFactory.GetRepositoryInstance()) { var itemFromDb = repository.PublishingGroups.Where( pg => pg.DynamicContentPublishingGroupId == detailViewModel.InnerItem.DynamicContentPublishingGroupId) .Expand(pg => pg.ContentItems).Expand(pg => pg.ContentPlaces).SingleOrDefault(); Assert.NotNull(itemFromDb); Assert.True(itemFromDb.ContentItems.Count == 1); Assert.True(itemFromDb.ContentPlaces.Count == 2); Assert.True(itemFromDb.Name == "EditName"); Assert.NotNull(itemFromDb.ConditionExpression); Assert.NotNull(itemFromDb.PredicateVisualTreeSerialized); } }
public void Can_create_contentpublishingviewmodel_in_editmode_simpleacenarios() { var repositoryFactory = new DSRepositoryFactory <IDynamicContentRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var storeRepositoryFactory = new DSRepositoryFactory <IStoreRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var countryRepositoryFactory = new DSRepositoryFactory <ICountryRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var appConfigRepositoryFactory = new DSRepositoryFactory <IAppConfigRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var searchCategoryVmFactory = new TestDynamicContentViewModelFactory <ISearchCategoryViewModel>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var navigationManager = new TestNavigationManager(); DynamicContentPlace[] contentPlaces; DynamicContentItem[] contentItems; using (var repository = repositoryFactory.GetRepositoryInstance()) { contentPlaces = TestContentPlacesBuilder.BuildContentPlaces().GetPlaces().ToArray(); contentItems = TestContentItemsBuilder.BuildsContentItems().GetItems().ToArray(); RepositoryHelper.AddItemToRepository(repository, contentPlaces.AsEnumerable()); RepositoryHelper.AddItemToRepository(repository, contentItems.AsEnumerable()); } //create fake innerItem var entityFactory = new DynamicContentEntityFactory(); var item = TestContentPublishingBuilder.BuildDynamicContentPublishingGroup() .WithContentItems(contentItems) .WithContentPlaces(contentPlaces) .GetContentPublishingGroup(); using (var repository = repositoryFactory.GetRepositoryInstance()) { RepositoryHelper.AddItemToRepository(repository, item); } var detailViewModel = new ContentPublishingItemViewModel(appConfigRepositoryFactory, countryRepositoryFactory, searchCategoryVmFactory, repositoryFactory, entityFactory, storeRepositoryFactory, navigationManager, item); Assert.NotNull(detailViewModel); detailViewModel.InitializeForOpen(); //edit properties in detail viewmodel detailViewModel.InnerItem.Name = string.Empty; detailViewModel.InnerItem.Description = "EditDescription"; detailViewModel.InnerItem.Priority = 23; detailViewModel.InnerItemDynamicContent.Clear(); detailViewModel.InnerItemDynamicContent.Add(contentItems[1]); detailViewModel.InnerItemContentPlaces.Clear(); detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); detailViewModel.InnerItem.Name = "EditName"; Assert.True(detailViewModel.IsValid); detailViewModel.SaveWithoutUIChanges(); using (var repository = repositoryFactory.GetRepositoryInstance()) { var itemFromDb = repository.PublishingGroups.Where( pg => pg.DynamicContentPublishingGroupId == detailViewModel.InnerItem.DynamicContentPublishingGroupId) .Expand(pg => pg.ContentItems).Expand(pg => pg.ContentPlaces).SingleOrDefault(); Assert.NotNull(itemFromDb); Assert.True(itemFromDb.ContentItems[0].DynamicContentItemId == contentItems[1].DynamicContentItemId); Assert.True(itemFromDb.ContentPlaces[0].DynamicContentPlaceId == contentPlaces[1].DynamicContentPlaceId); Assert.True(itemFromDb.Name == "EditName"); } }
public void Can_create_contentpublishingviewmodel_in_editmode_simpleacenarios() { var repositoryFactory = new DSRepositoryFactory<IDynamicContentRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var storeRepositoryFactory = new DSRepositoryFactory<IStoreRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var countryRepositoryFactory = new DSRepositoryFactory<ICountryRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var appConfigRepositoryFactory = new DSRepositoryFactory<IAppConfigRepository, DSDynamicContentClient, DynamicContentEntityFactory>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var searchCategoryVmFactory = new TestDynamicContentViewModelFactory<ISearchCategoryViewModel>( ServManager.GetUri(ServiceNameEnum.DynamicContent)); var navigationManager = new TestNavigationManager(); DynamicContentPlace[] contentPlaces; DynamicContentItem[] contentItems; using (var repository = repositoryFactory.GetRepositoryInstance()) { contentPlaces = TestContentPlacesBuilder.BuildContentPlaces().GetPlaces().ToArray(); contentItems = TestContentItemsBuilder.BuildsContentItems().GetItems().ToArray(); RepositoryHelper.AddItemToRepository(repository, contentPlaces.AsEnumerable()); RepositoryHelper.AddItemToRepository(repository, contentItems.AsEnumerable()); } //create fake innerItem var entityFactory = new DynamicContentEntityFactory(); var item = TestContentPublishingBuilder.BuildDynamicContentPublishingGroup() .WithContentItems(contentItems) .WithContentPlaces(contentPlaces) .GetContentPublishingGroup(); using (var repository = repositoryFactory.GetRepositoryInstance()) { RepositoryHelper.AddItemToRepository(repository, item); } var detailViewModel = new ContentPublishingItemViewModel(appConfigRepositoryFactory, countryRepositoryFactory, searchCategoryVmFactory, repositoryFactory, entityFactory, storeRepositoryFactory, navigationManager, item); Assert.NotNull(detailViewModel); detailViewModel.InitializeForOpen(); //edit properties in detail viewmodel detailViewModel.InnerItem.Name = string.Empty; detailViewModel.InnerItem.Description = "EditDescription"; detailViewModel.InnerItem.Priority = 23; detailViewModel.InnerItemDynamicContent.Clear(); detailViewModel.InnerItemDynamicContent.Add(contentItems[1]); detailViewModel.InnerItemContentPlaces.Clear(); detailViewModel.InnerItemContentPlaces.Add(contentPlaces[1]); detailViewModel.InnerItem.Name = "EditName"; Assert.True(detailViewModel.IsValid); detailViewModel.SaveWithoutUIChanges(); using (var repository = repositoryFactory.GetRepositoryInstance()) { var itemFromDb = repository.PublishingGroups.Where( pg => pg.DynamicContentPublishingGroupId == detailViewModel.InnerItem.DynamicContentPublishingGroupId) .Expand(pg => pg.ContentItems).Expand(pg => pg.ContentPlaces).SingleOrDefault(); Assert.NotNull(itemFromDb); Assert.True(itemFromDb.ContentItems[0].DynamicContentItemId == contentItems[1].DynamicContentItemId); Assert.True(itemFromDb.ContentPlaces[0].DynamicContentPlaceId == contentPlaces[1].DynamicContentPlaceId); Assert.True(itemFromDb.Name == "EditName"); } }