public void Repopulate_SourceItemFound_AddsVM()
        {
            Assert.Inconclusive("Refactor");
            var context             = new ContextTestHelper(new EmployeeVM());
            var projectSource       = new Project();
            var projectVM           = new ProjectVM(projectSource);
            var additionalProjectVM = new ProjectVM(new Project());

            var lookupCollection = new[] { projectVM, additionalProjectVM };
            var sourceCollection = new[] { projectSource };

            var behavior = CreateBehavior(lookupCollection, sourceCollection);

            var collection = VMCollectionStub
                             .Of <ProjectVM>()
                             .WithOwner(context.VM)
                             .Build();

            throw new NotImplementedException();
            //behavior.GetValue(
            //behavior.Repopulate(context.Context, collection);

            //CollectionAssert.AreEquivalent(
            //   new[] { projectVM },
            //   collection
            //);
        }
 protected VMCollectionStub <TItemVM> CreateCollection(params TItemVM[] items)
 {
     return(VMCollectionStub
            .Of <TItemVM>()
            .WithItems(items)
            .WithOwner(CollectionOwner)
            .Build());
 }
Ejemplo n.º 3
0
        public void ItemsRemoved_SetsChangedPathToEmpty()
        {
            var collection = VMCollectionStub.Build();
            var oldItems   = new[] { ViewModelStub.Build() };
            var args       = ChangeArgs.ItemsRemoved(collection, oldItems);

            Assert.AreEqual(ChangeType.RemovedFromCollection, args.ChangeType);
            CollectionAssert.AreEqual(oldItems, args.OldItems.ToArray());
            Assert.IsFalse(args.NewItems.Any());
            DomainAssert.AreEqual(Path.Empty.Append(collection), args.ChangedPath);
        }
Ejemplo n.º 4
0
        public void ItemsAdded_SetsChangeTypeAndNewItemsAndChangedPathToCollection()
        {
            var collection = VMCollectionStub.Build();
            var newItems   = new[] { ViewModelStub.Build() };
            var args       = ChangeArgs.ItemsAdded(collection, newItems);

            Assert.AreEqual(ChangeType.AddedToCollection, args.ChangeType);
            CollectionAssert.AreEqual(newItems, args.NewItems.ToArray());
            Assert.IsFalse(args.OldItems.Any());
            DomainAssert.AreEqual(Path.Empty.Append(collection), args.ChangedPath);
        }
Ejemplo n.º 5
0
        public void Setup()
        {
            Behavior = new CollectionPropertyDescendantsValidatorBehavior <ViewModelStub>();

            ViewModelPropertyAccessor       = new ValueAccessorStub <IVMCollection <ViewModelStub> >();
            ViewModelPropertyAccessor.Value = VMCollectionStub.Build();

            var property = PropertyStub
                           .WithBehaviors(Behavior, Next, ViewModelPropertyAccessor)
                           .Of <string>();

            Context = CreateBehaviorContextFor(property);
        }
Ejemplo n.º 6
0
        public void HandleChange_WithItemsAddedOrRemovedFromOwnCollection_UpdatesCachedResults()
        {
            var owner = new TestVM();

            owner.MakePropertiesAndViewModelInvalid();
            var expected = owner.GetCurrentlySetupResults();

            //   F I R S T   A D D
            var firstNewItem = new ViewModelStub {
                ValidationResult = CreateValidationResult("First new item error")
            };

            var collectionChangeArgs = ChangeArgs
                                       .ItemsAdded(VMCollectionStub.Build(), new[] { firstNewItem })
                                       .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            expected.Descenants = firstNewItem.ValidationResult;
            AssertBehaviorResults(owner, expected);

            //   S E C O N D   A D D
            var secondNewItem = new ViewModelStub {
                ValidationResult = CreateValidationResult("Second new Item error")
            };

            collectionChangeArgs = ChangeArgs
                                   .ItemsAdded(VMCollectionStub.Build(), new[] { secondNewItem })
                                   .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            expected.Descenants = ValidationResult.Join(
                firstNewItem.ValidationResult,
                secondNewItem.ValidationResult
                );

            AssertBehaviorResults(owner, expected);

            //   R E M O V AL
            collectionChangeArgs = ChangeArgs
                                   .ItemsRemoved(VMCollectionStub.Build(), new[] { firstNewItem })
                                   .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            expected.Descenants = secondNewItem.ValidationResult;
            AssertBehaviorResults(owner, expected);
        }
Ejemplo n.º 7
0
        public void CollectionPopulated_SetsChangeTypeAndNewItemsAndChangedPathToCollection()
        {
            var collection = VMCollectionStub
                             .WithItems(ViewModelStub.Build())
                             .Build();

            var newItems = collection.ToArray();
            var oldItems = new[] { ViewModelStub.Build(), ViewModelStub.Build() };
            var args     = ChangeArgs.CollectionPopulated(collection, oldItems);

            Assert.AreEqual(ChangeType.CollectionPopulated, args.ChangeType);
            CollectionAssert.AreEqual(newItems, args.NewItems.ToArray());
            CollectionAssert.AreEqual(oldItems, args.OldItems.ToArray());
            DomainAssert.AreEqual(Path.Empty.Append(collection), args.ChangedPath);
        }
Ejemplo n.º 8
0
        public void HandleChange_WithItemsAddedOrRemovedFromDescendantCollection_DoesNotUpdateCachedResults()
        {
            var owner = new TestVM();

            var newItem = new ViewModelStub {
                ValidationResult = CreateValidationResult("Irrelevant item error")
            };

            var collectionChangeArgs = ChangeArgs
                                       .ItemsAdded(VMCollectionStub.Build(), new[] { newItem })
                                       .PrependViewModel(ViewModelStub.Build())
                                       .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            AssertBehaviorResults(owner, ExpectedResults.AllValid);
        }
Ejemplo n.º 9
0
            public ItemInCollectionSetup(StringBuilder log)
            {
                ItemExecutor            = new ValidationExecutorStub();
                CollectionOwnerExecutor = new ValidationExecutorStub();

                ItemProperty = PropertyStub
                               .WithBehaviors(new RevalidationBehaviorSpy(log))
                               .Build();

                Item = ViewModelStub
                       .WithBehaviors(ItemExecutor, new RevalidationBehaviorSpy(log))
                       .WithProperties(ItemProperty)
                       .Build();

                var collectionOwner = ViewModelStub
                                      .WithBehaviors(CollectionOwnerExecutor)
                                      .Build();

                Collection = VMCollectionStub
                             .WithItems(Item)
                             .WithOwner(collectionOwner)
                             .Build();
            }
Ejemplo n.º 10
0
        public void HandleChange_WithItemsAddedToOwnCollection_UpdatesBehaviorOfParentViewModel()
        {
            var parent = new TestVM();
            var owner  = new TestVM();

            parent.MakePropertiesAndViewModelInvalid();
            owner.Kernel.Parents.Add(parent);

            var newItem = new ViewModelStub {
                ValidationResult = CreateValidationResult("New item error")
            };

            var collectionChangeArgs = ChangeArgs
                                       .ItemsAdded(VMCollectionStub.Build(), new[] { newItem })
                                       .PrependViewModel(owner);

            owner.CallHandleChangeWith(collectionChangeArgs);

            var expectedParentResult = parent.GetCurrentlySetupResults();

            expectedParentResult.Descenants = newItem.ValidationResult;
            AssertBehaviorResults(parent, expectedParentResult);
        }
Ejemplo n.º 11
0
        public void NotifyChange_CallsHandlePropertyChangedBehaviorOnlyIfOwnPropertyHasChanged()
        {
            var mock = new PropertyChangedMock();

            var property = PropertyStub
                           .WithBehaviors(mock)
                           .Build();

            var vm = ViewModelStub
                     .WithProperties(property)
                     .Build();

            var context = vm.GetContext();

            var args = ChangeArgs.PropertyChanged(property, ValueStage.ValidatedValue);

            context.NotifyChange(args);
            Assert.IsTrue(mock.PropertyChangedWasCalled);

            mock.PropertyChangedWasCalled = false;
            args = ChangeArgs
                   .PropertyChanged(property, ValueStage.ValidatedValue)
                   .PrependViewModel(ViewModelStub.Build());
            context.NotifyChange(args);
            Assert.IsFalse(mock.PropertyChangedWasCalled);

            mock.PropertyChangedWasCalled = false;
            args = ChangeArgs.ValidationResultChanged(property, ValueStage.Value);
            context.NotifyChange(args);
            Assert.IsFalse(mock.PropertyChangedWasCalled);

            mock.PropertyChangedWasCalled = false;
            args = ChangeArgs.ItemsAdded(VMCollectionStub.Build(), new[] { ViewModelStub.Build() });
            context.NotifyChange(args);
            Assert.IsFalse(mock.PropertyChangedWasCalled);
        }
Ejemplo n.º 12
0
 private IVMCollection CreateCollection()
 {
     return(VMCollectionStub.Build());
 }
 protected static IVMCollection <ItemVM> CreateCollection()
 {
     return(VMCollectionStub.Build <ItemVM>());
 }