public void Can_add_pricelist()
        {
            // create ViewModelsFactory ( it should be resolve all view models for the test)
            var overviewVmFactory = new TestCatalogViewModelFactory <IPriceListOverviewStepViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));

            // create Item using EntityFactory
            var entityFactory = new CatalogEntityFactory();
            var item          = entityFactory.CreateEntity <Pricelist>();

            // create Wizard main class. Constructor of the class creates wizard steps with help vmFactory
            var createPriceListViewModel = new CreatePriceListViewModel(overviewVmFactory, item);

            // IsValid of wizard step should be false at the begin.
            Assert.False(createPriceListViewModel.AllRegisteredSteps[0].IsValid);

            var step = createPriceListViewModel.AllRegisteredSteps[0] as PriceListOverviewStepViewModel;

            step.InitializeForOpen();
            step.InnerItem.Name = "New test PriceList";
            Assert.Null(step.AllAvailableCurrencies);
            step.InnerItem.Currency = "USD";
            Assert.True(step.IsValid);
            createPriceListViewModel.PrepareAndSave();

            var priceListRepositoryFactory = new DSRepositoryFactory <IPricelistRepository, DSCatalogClient, CatalogEntityFactory>(ServManager.GetUri(ServiceNameEnum.Catalog));

            using (var repository = priceListRepositoryFactory.GetRepositoryInstance())
            {
                var checkItem = repository.Pricelists.Where(x => x.Name == "New test PriceList").FirstOrDefault();
                Assert.NotNull(checkItem);
            }
        }
        public void Can_create_catalogviewmodel_in_wizardmode()
        {
            var vmFactory = new TestCatalogViewModelFactory <ICatalogOverviewStepViewModel>(
                ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));

            var repositoryFactory =
                new DSRepositoryFactory <ICatalogRepository, DSCatalogClient, CatalogEntityFactory>(
                    ServManager.GetUri(ServiceNameEnum.Catalog));

            //create item using entity factory
            var entityFactory = new CatalogEntityFactory();
            var item          = entityFactory.CreateEntity <Catalog>();

            var createViewModel   = new CreateCatalogViewModel(vmFactory, item);
            var overviewViewModel = createViewModel.AllRegisteredSteps[0] as ViewModelDetailAndWizardBase <Catalog>;

            overviewViewModel.InitializeForOpen();

            //check the default values in stepViewModel
            Assert.False(createViewModel.AllRegisteredSteps[0].IsValid);

            // step 1
            //fill the properties for the first step
            overviewViewModel.InnerItem.CatalogId = "TestCatalog";
            overviewViewModel.InnerItem.Name      = "TestName";
            overviewViewModel.InnerItem.CatalogLanguages.Add(new CatalogLanguage()
            {
                Language  = "ru-ru",
                CatalogId = overviewViewModel.InnerItem.CatalogId
            });
            overviewViewModel.InnerItem.DefaultLanguage = "ru-ru";

            Assert.True(createViewModel.AllRegisteredSteps[0].IsValid);

            // final actions: save
            createViewModel.PrepareAndSave();

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                var itemFromDb = repository.Catalogs.Where(s => s.CatalogId == item.CatalogId).OfType <Catalog>().Expand(x => x.CatalogLanguages).SingleOrDefault();

                Assert.NotNull(itemFromDb);
                Assert.True(itemFromDb.Name == "TestName");
                Assert.True(itemFromDb.DefaultLanguage == "ru-ru");
                Assert.True(itemFromDb.CatalogLanguages.Any(x => x.Language == "ru-ru"));
            }
        }
        public void Can_create_categoryviewmodel_in_wizardmode()
        {
            var repositoryFactory =
                new DSRepositoryFactory <ICatalogRepository, DSCatalogClient, CatalogEntityFactory>(ServManager.GetUri(ServiceNameEnum.Catalog));

            const string catalogId      = "testcatalog";
            var          catalogBuilder = CatalogBuilder.BuildCatalog(catalogId);
            var          catalog        = catalogBuilder.GetCatalog() as Catalog;

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                repository.Add(catalog);
                repository.UnitOfWork.Commit();
            }

            var propertiesVmFactory = new TestCatalogViewModelFactory <ICategoryPropertiesStepViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));
            var overviewVmFactory   = new TestCatalogViewModelFactory <ICategoryOverviewStepViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));

            //create item using entity factory
            var entityFactory = new CatalogEntityFactory();
            var item          = entityFactory.CreateEntity <Category>();

            item.CatalogId = catalogId;
            item.Catalog   = catalog;

            var createViewModel   = new CreateCategoryViewModel(propertiesVmFactory, overviewVmFactory, item);
            var overviewViewModel = createViewModel.AllRegisteredSteps[0] as CategoryViewModel;

            overviewViewModel.InitializeForOpen();
            var propertyValuesViewModel = createViewModel.AllRegisteredSteps[1] as CategoryViewModel;

            propertyValuesViewModel.InitializeForOpen();

            //check the default values in stepViewModel
            Assert.False(createViewModel.AllRegisteredSteps[0].IsValid);
            Assert.True(createViewModel.AllRegisteredSteps[1].IsValid);

            // step 1
            //fill the properties for the first step
            overviewViewModel.InnerItem.Name = "TestName";
            overviewViewModel.InnerItem.Code = "TestCode";
            var propertySet = overviewViewModel.AvailableCategoryTypes.First();

            overviewViewModel.InnerItem.PropertySet   = propertySet;
            overviewViewModel.InnerItem.PropertySetId = propertySet.PropertySetId;

            Assert.True(createViewModel.AllRegisteredSteps[0].IsValid);

            // step 2
            //fill the values for the property values step
            propertyValuesViewModel.PropertiesAndValues[0].Value = new CategoryPropertyValue()
            {
                ShortTextValue = "short text",
                Name           = propertyValuesViewModel.PropertiesAndValues[0].Property.Name,
                ValueType      = propertyValuesViewModel.PropertiesAndValues[0].Property.PropertyValueType
            };
            propertyValuesViewModel.InnerItem.CategoryPropertyValues.Add((CategoryPropertyValue)propertyValuesViewModel.PropertiesAndValues[0].Value);

            Assert.True(createViewModel.AllRegisteredSteps[1].IsValid);

            // final actions: save
            propertyValuesViewModel.InnerItem.Catalog = null;
            createViewModel.PrepareAndSave();

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                var itemFromDb = repository.Categories.Where(s => s.CategoryId == item.CategoryId).OfType <Category>().ExpandAll().SingleOrDefault();

                Assert.NotNull(itemFromDb);
                Assert.True(itemFromDb.Name == "TestName");
                Assert.True(itemFromDb.CategoryPropertyValues.Any(x => x.ShortTextValue == "short text"));
            }
        }
        public void Can_delete_pricelist()
        {
            #region Init parameters for PriceListHomeViewModel

            var priceListRepositoryFactory =
                new DSRepositoryFactory <IPricelistRepository, DSCatalogClient, CatalogEntityFactory>(
                    ServManager.GetUri(ServiceNameEnum.Catalog));
            IAuthenticationContext authenticationContext = new TestAuthenticationContext();
            var navigationManager = new TestNavigationManager();

            // create ViewModelsFactory ( it should be resolve all view models for the test)
            var itemVmFactory = new TestCatalogViewModelFactory <IPriceListViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog),
                                                                                      ServManager.GetUri(ServiceNameEnum.AppConfig));

            var wizardVmFactory = new TestCatalogViewModelFactory <ICreatePriceListViewModel>(ServManager.GetUri(ServiceNameEnum.Catalog),
                                                                                              ServManager.GetUri(ServiceNameEnum.AppConfig));

            // create Item using EntityFactory
            var entityFactory = new CatalogEntityFactory();

            #endregion

            #region Add price list to DB

            using (var repository = priceListRepositoryFactory.GetRepositoryInstance())
            {
                var pricelist = entityFactory.CreateEntity <Pricelist>();
                pricelist.Name     = "Test price (Can_delete_pricelist)";
                pricelist.Currency = "USD";

                repository.Add(pricelist);
                repository.UnitOfWork.Commit();
            }

            #endregion

            #region VM test

            var priceListHomeViewModel = new PriceListHomeViewModel(entityFactory, itemVmFactory, wizardVmFactory,
                                                                    priceListRepositoryFactory, authenticationContext,
                                                                    navigationManager, null);
            priceListHomeViewModel.InitializeForOpen();

            Thread.Sleep(3000);             // waiting for InitializeForOpen to finish in background thread

            priceListHomeViewModel.CommonConfirmRequest.Raised += DeletePriceListConfirmation;
            priceListHomeViewModel.ListItemsSource.MoveCurrentToFirst();
            var item          = priceListHomeViewModel.ListItemsSource.CurrentItem as VirtualListItem <IPriceListViewModel>;
            var itemsToDelete = new List <VirtualListItem <IPriceListViewModel> >()
            {
                item
            };
            priceListHomeViewModel.ItemDeleteCommand.Execute(itemsToDelete);

            Thread.Sleep(1000);            // waiting for ItemDeleteCommand to finish in background thread

            #endregion

            #region Check

            using (var repository = priceListRepositoryFactory.GetRepositoryInstance())
            {
                var checkItem = repository.Pricelists.Where(x => x.Name == "Test price (Can_delete_pricelist)").SingleOrDefault();
                Assert.Null(checkItem);
            }

            #endregion
        }