예제 #1
0
        public void SearchItemsCommandTest()
        {
            var db = DataRepository.GetDataRepository;

            Assert.NotNull(db);
            var user        = db.Load <UserDetail>("steph");
            var userManager = new UserManager(db);

            UserManager.GetUserManager.LoginUser(user);


            var searchFilter = new SearchFilterOptions
            {
                User = UserManager.GetUserManager.CurrentUser(),
                SiteLocationEnabled             = false,
                SearchFilterEnabled             = true,
                SearchText                      = "Airway Kit",
                SelectEquipmentUnitsEnabled     = false,
                SelectItemStatusValuesEnabled   = false,
                SelectItemCategoryValuesEnabled = false
            };

            Assert.NotNull(searchFilter, nameof(SearchFilterOptions));
            var resultVM = new TestDetailsViewModel();

            Assert.NotNull(resultVM, nameof(TestDetailsViewModel));
            var onSelectionChangedCommand = new OnSelectionChangedCommand(resultVM);

            Assert.NotNull(onSelectionChangedCommand, nameof(OnSelectionChangedCommand));
            var searchResultViewModel = new SearchResultViewModel(onSelectionChangedCommand);

            Assert.NotNull(searchResultViewModel, nameof(SearchResultViewModel));
            var searchCmd = new SearchItemsCommand(QueryResultEntitySelector.ItemType, searchResultViewModel);

            Assert.NotNull(searchCmd, nameof(SearchItemsCommand));

            Assert.IsTrue(searchCmd.CanExecute(searchFilter));

            Assert.IsNull(resultVM.CurrentItem);                           // nothing selected to display details of
            Assert.That(searchResultViewModel.Items.Count, Is.EqualTo(0)); // no search results or empty search results
            searchCmd.Execute(searchFilter);
            searchCmd.WaitForSearchToComplete();
            Assert.That(searchResultViewModel.Items.Count, Is.GreaterThan(0));

            searchResultViewModel.SelectedItem = searchResultViewModel.Items.First();
            Assert.NotNull(searchResultViewModel.SelectedItem);
            Assert.NotNull(resultVM.CurrentItem);

            Assert.AreNotEqual(Guid.Empty, resultVM.CurrentItem.id);
            Assert.NotNull(resultVM.CurrentItem.entityType);
            Assert.NotNull(resultVM.CurrentItem.entity);
        }
예제 #2
0
        public void ReplaceItemCommand()
        {
            var db = DataRepository.GetDataRepository;

            Assert.NotNull(db);
            var user        = db.Load <UserDetail>("steph");
            var userManager = new UserManager(db);

            UserManager.GetUserManager.LoginUser(user);

            var cmd = new ReplaceItemCommand();

            Assert.NotNull(cmd, nameof(ReplaceItemCommand));

            var item = db.Load <ItemInstance>(SampleItemInstance);

            Assert.NotNull(item);
            // force known value
            item.status = db.ReferenceData[nameof(ItemStatus)].ByName <ItemStatus>("Available");
            db.Save(item);
            item = db.Load <ItemInstance>(SampleItemInstance);
            Assert.That(item.status.name, Is.EqualTo("Available"));

            Assert.IsTrue(cmd.CanExecute(item));
            cmd.Execute(item);
            Assert.That(item.status.name, Is.EqualTo("Out for Service"));

            // verify a new item created
            var searchFilter = new SearchFilterOptions
            {
                User = UserManager.GetUserManager.CurrentUser(),
                SiteLocationEnabled = false,
                SearchFilterEnabled = true,
                SearchText          = SampleItemNumber,
                ItemTypeMatching    = SearchFilterItemMatching.OnlyExact,
                //AllowItemsRemovedFromService = false, // required or query below may return old item instead of new one
                SelectEquipmentUnitsEnabled     = false,
                SelectItemStatusValuesEnabled   = false,
                SelectItemCategoryValuesEnabled = false
            };

            Assert.NotNull(searchFilter, nameof(SearchFilterOptions));
            var resultVM = new TestDetailsViewModel();

            Assert.NotNull(resultVM, nameof(TestDetailsViewModel));
            var onSelectionChangedCommand = new OnSelectionChangedCommand(resultVM);

            Assert.NotNull(onSelectionChangedCommand, nameof(OnSelectionChangedCommand));
            var searchResultViewModel = new SearchResultViewModel(onSelectionChangedCommand);

            Assert.NotNull(searchResultViewModel, nameof(SearchResultViewModel));
            var searchCmd = new SearchItemsCommand(QueryResultEntitySelector.ItemType, searchResultViewModel);

            Assert.NotNull(searchCmd, nameof(SearchItemsCommand));
            //var searchFilterOptionsViewModel = new SearchFilterOptionsViewModel(searchFilter, QueryResultEntitySelector.ItemInstance, searchResultViewModel);
            //Assert.NotNull(searchFilterOptionsViewModel);

            Assert.IsTrue(searchCmd.CanExecute(searchFilter));

            Assert.IsNull(resultVM.CurrentItem);                           // nothing selected to display details of
            Assert.That(searchResultViewModel.Items.Count, Is.EqualTo(0)); // no search results or empty search results
            searchCmd.Execute(searchFilter);
            searchCmd.WaitForSearchToComplete();
            Assert.That(searchResultViewModel.Items.Count, Is.GreaterThan(0));

            searchResultViewModel.SelectedItem = searchResultViewModel.Items.First();
            Assert.NotNull(searchResultViewModel.SelectedItem);
            Assert.NotNull(resultVM.CurrentItem);
            Assert.That(resultVM.CurrentItem.id, Is.Not.EqualTo(item.id));

            // delete new item and restore old item to Available
            var newItem = db.Load <ItemInstance>(resultVM.CurrentItem.id);

            Assert.That(newItem.status.name, Is.EqualTo("Available"));
            item.status             = db.ReferenceData[nameof(ItemStatus)].ByName <ItemStatus>("Available");
            item.removedServiceDate = null;
            db.Delete(newItem);
            Assert.IsFalse(db.Exists(newItem));
            db.Save(item);
            item = db.Load <ItemInstance>(SampleItemInstance);
            Assert.That(item.status.name, Is.EqualTo("Available"));
        }