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 }
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 }