public void Refresh_OfDelegateProperty_CallsNotifyChangeWhenViewModelInstanceHasChanged()
        {
            var oldChild = new ChildVM();
            var newChild = new ChildVM();

            VM.DelegatePropertyResult = oldChild;
            VM.Load(x => x.DelegateProperty);

            VM.DelegatePropertyResult = newChild;
            VM.OnChangeInvocations.Clear();

            VM.Refresh(x => x.DelegateProperty);

            var expectedArgs = ChangeArgs
                               .ViewModelPropertyChanged(
                RootVM.ClassDescriptor.DelegateProperty,
                ValueStage.ValidatedValue,
                oldChild,
                newChild)
                               .PrependViewModel(VM);

            DomainAssert.AreEqual(
                new[] { expectedArgs },
                VM.OnChangeInvocations
                );
        }
Exemple #2
0
 public void HandleChange(IBehaviorContext context, ChangeArgs args)
 {
     if (HandleChangeNext != null)
     {
         HandleChangeNext();
     }
 }
Exemple #3
0
 private void onChange(object source, ChangeArgs e)
 {
     if (changer != null)
     {
         changer(this, e);
     }
 }
Exemple #4
0
 public void Repeater(ChangeArgs args)
 {
     if (ChangeEvent != null)
     {
         ChangeEvent(args);
     }
 }
Exemple #5
0
        public void Refresh_CallsNotifyChange()
        {
            Behavior.Refresh(Context, new RefreshOptions());
            var expectedChangeArgs = ChangeArgs.PropertyChanged(Property, null);

            DomainAssert.AreEqual(new[] { expectedChangeArgs }, Context.NotifyChangeInvocations);
        }
        public void Changed(ChangeArgs args)
        {
            if (args.Type != ChangeType.PlayerChanged)
            {
                return;
            }

            switch (args.Type)
            {
            case ChangeType.PlayerChanged:
                var changedPlayerArgs = (SoccerPlayerArgs)args;
                var player            = changedPlayerArgs.PlayerValues;
                if (changedPlayerArgs.Column == ColumnName.IsCaptain)
                {
                    player.IsCaptain = (bool)Team.Squad.Find(p => p.Id == player.Id).IsCaptain.Value;
                }

                // TODO: Correct position group value to DB
                if (changedPlayerArgs.Column == ColumnName.Position)
                {
                    player.Position.Role = (PositionRole)Team.Squad.Find(p => p.Id == player.Id).Position.Value;
                }

                SquadRepository.UpdatePlayer(player);

                break;

            default:
                break;
            }
        }
 public void HandlePropertyChanged_ValidationFailed_ClearsValidationResult()
 {
     SetInvalidValue();
     Behavior.NextValue = "Source value";
     Behavior.HandlePropertyChanged(Context, ChangeArgs.PropertyChanged(Property, ValueStage.ValidatedValue));
     Assert.AreEqual(Behavior.NextValue, Behavior.GetValue(Context));
 }
 public static void AreEqual(ChangeArgs expected, ChangeArgs actual)
 {
     if (!AreEqualCore(expected, actual))
     {
         Assert.Fail("Expected {0} but was {1}.", expected, actual);
     }
 }
Exemple #9
0
 public void CallHandleChangeWith(ChangeArgs args)
 {
     Behavior.HandleChange(
         GetContext(),
         args
         );
 }
 public void Changed(ChangeArgs args)
 {
     if (args.Type == ChangeType.PlayerSelected || args.Type == ChangeType.PlayerChanged)
     {
         var playerArgs = (SoccerPlayerArgs)args;
         Player = new SoccerPlayerViewModel(playerArgs.PlayerValues, Collections, _changesManager);
     }
 }
        public void HandleChange_DescendantValidationStateChanged_PerformsViewModelValidation()
        {
            var args = ChangeArgs.ValidationResultChanged()
                       .PrependViewModel(VM)
                       .PrependViewModel(ViewModelStub.Build());

            Behavior.HandleChange(Context, args);
            Assert.AreEqual(HandleChangeNext + Validate + RevalidateNext, ActionLog);
        }
        public void ViewModelPropertyChanged_SetsChangeTypeAndChangedPathToProperty()
        {
            var property = PropertyStub.Build();
            var args     = ChangeArgs.ViewModelPropertyChanged(property, ValueStage.Value, null, null);

            Assert.AreEqual(ChangeType.PropertyChanged, args.ChangeType);
            Assert.AreEqual(ValueStage.Value, args.Stage);
            DomainAssert.AreEqual(Path.Empty.Append(property), args.ChangedPath);
        }
        public void ViewModelPropertyChanged_SetsOldAndNewItems()
        {
            var property = PropertyStub.Build();
            var newValue = ViewModelStub.Build();
            var args     = ChangeArgs.ViewModelPropertyChanged(property, ValueStage.ValidatedValue, null, newValue);

            CollectionAssert.AreEqual(new IViewModel[0], args.OldItems.ToArray());
            CollectionAssert.AreEqual(new IViewModel[] { newValue }, args.NewItems.ToArray());
        }
        public void HandleChange_DescendantPropertyChanged_PerformsViewModelValidation()
        {
            var args = ChangeArgs.PropertyChanged(PropertyStub.Of <string>(), null)
                       .PrependViewModel(VM)
                       .PrependViewModel(new ViewModelStub());

            Behavior.HandleChange(Context, args);
            Assert.AreEqual(HandleChangeNext + Validate + RevalidateNext, ActionLog);
        }
Exemple #15
0
        public void HandleChange_WithPropertyChangedOfOwnViewModelProperty_UpdatesCachedResults()
        {
            var owner = new TestVM();

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

            //   S E T   C H I L D
            var firstChild = new ViewModelStub {
                ValidationResult = CreateValidationResult("First child error")
            };

            var propertyChangedArgs = ChangeArgs
                                      .ViewModelPropertyChanged(
                owner.SecondProperty,
                ValueStage.ValidatedValue,
                oldValue: null,
                newValue: firstChild)
                                      .PrependViewModel(owner);

            owner.CallHandleChangeWith(propertyChangedArgs);

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

            //   C H A N G E   C H I L D
            var secondChild = new ViewModelStub {
                ValidationResult = CreateValidationResult("Second child error")
            };

            propertyChangedArgs = ChangeArgs
                                  .ViewModelPropertyChanged(
                owner.SecondProperty,
                ValueStage.ValidatedValue,
                oldValue: firstChild,
                newValue: secondChild)
                                  .PrependViewModel(owner);

            owner.CallHandleChangeWith(propertyChangedArgs);

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

            //   S E T   C H I L D   T O   N U L L
            propertyChangedArgs = ChangeArgs
                                  .ViewModelPropertyChanged(
                owner.SecondProperty,
                ValueStage.ValidatedValue,
                oldValue: secondChild,
                newValue: null)
                                  .PrependViewModel(owner);

            owner.CallHandleChangeWith(propertyChangedArgs);

            expected.Descenants = ValidationResult.Valid;
            AssertBehaviorResults(owner, expected);
        }
        public void GetValueOfPopulatedCollection_Initially_RaisesChangeWithInitialPopulationReason()
        {
            Assert.AreEqual(0, VM.OnChangeInvocations.Count);
            VM.Load(x => x.PopulatedCollection);

            ChangeArgs args = VM.OnChangeInvocations.SingleOrDefault();

            Assert.IsNotNull(args);
            Assert.AreEqual(InitialPopulationChangeReason.Instance, args.Reason);
        }
Exemple #17
0
        public void NotifyChange_WithValidationResultChangeForOwnViewModel_CallsValidationResultChanged()
        {
            VMInterface.NotifyChange(ChangeArgs
                                     .ValidationResultChanged()
                                     .PrependViewModel(VM)
                                     );

            Assert.IsTrue(VM.OnValidationStateChangedWasCalled);
            Assert.IsNull(VM.LastOnValidationStateChangedInvocation);
        }
Exemple #18
0
        public void ItemRemoved_CallsNotifyChange()
        {
            var removedItem = CreateItem("Removed item");

            Collection = CreateCollection();

            HandleItemRemoved(removedItem);

            AssertChangeArgs(ChangeArgs.ItemsRemoved(Collection, new[] { removedItem }));
        }
Exemple #19
0
        public void NotifyChange_WithPropertyChangeForOwnProperty_CallsOnPropertyChanged()
        {
            var property = PropertyStub.Build();

            VMInterface.NotifyChange(ChangeArgs
                                     .PropertyChanged(property, ValueStage.DisplayValue)
                                     .PrependViewModel(VM)
                                     );

            Assert.AreEqual(property, VM.LastOnPropertyChangedInvocation);
        }
Exemple #20
0
        public void NotifyChange_WithValidationResultChangeForOwnProperty_CallsValidationResultChanged()
        {
            var property = PropertyStub.Build();

            VMInterface.NotifyChange(ChangeArgs
                                     .ValidationResultChanged(property, ValueStage.Value)
                                     .PrependViewModel(VM)
                                     );

            Assert.AreEqual(property, VM.LastOnValidationStateChangedInvocation);
        }
        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);
        }
        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);
        }
Exemple #23
0
        public void NotifyChange_WithPropertyChangeForDescendantViewModel_DoesNothing()
        {
            VMInterface.NotifyChange(ChangeArgs
                                     .ValidationResultChanged()
                                     .PrependViewModel(ViewModelStub.Build())
                                     .PrependViewModel(VM)
                                     );

            Assert.IsNull(VM.LastOnPropertyChangedInvocation);
            Assert.IsNull(VM.LastOnValidationStateChangedInvocation);
        }
Exemple #24
0
        public void NotifyChange_ForOwnProperty_RaisesPropertyChangedForErrorProperty()
        {
            var counter = new PropertyChangedCounter(VM, "Error");

            VMInterface.NotifyChange(ChangeArgs
                                     .ValidationResultChanged()
                                     .PrependViewModel(VM)
                                     );

            counter.AssertOneRaise();
        }
Exemple #25
0
        public void Refresh(IBehaviorContext context, RefreshOptions options)
        {
            context.NotifyChange(
                ChangeArgs.PropertyChanged(
                    _property,
                    ValueStage.ValidatedValue,
                    RefreshReason.Create(options.ExecuteRefreshDependencies)
                    )
                );

            this.RefreshNext(context, options);
        }
Exemple #26
0
        public override void NotifyPropertyChanged(IBehaviorContext context, ValueStage stage, TValue oldValue, TValue newValue)
        {
            var args = ChangeArgs.ViewModelPropertyChanged(
                _property,
                stage,
                oldValue,
                newValue,
                reason: null
                );

            context.NotifyChange(args);
        }
Exemple #27
0
        public void ItemInserted_CallsNotifyChange()
        {
            var insertedItem = CreateItem("Inserted item");

            Collection = CreateCollection(insertedItem);

            HandleItemInserted(insertedItem);

            AssertChangeArgs(
                ChangeArgs.ItemsAdded(Collection, newItems: new[] { insertedItem })
                );
        }
        public void Changed(ChangeArgs args)
        {
            if (args.Type != ChangeType.PlayerAdded && args.Type != ChangeType.PlayerChanged && args.Type != ChangeType.PlayerDeleted)
            {
                return;
            }

            switch (args.Type)
            {
            case ChangeType.PlayerAdded:
                var addedPlayerArgs = (SoccerPlayerArgs)args;
                TeamDetails.Squad.Add(new SoccerPlayerViewModel(addedPlayerArgs.PlayerValues, Collections, _changesManager));
                SetTeamSquadDetails();
                break;

            case ChangeType.PlayerChanged:
                var changedPlayerArgs = (SoccerPlayerArgs)args;
                var player            = TeamDetails.Squad.Find(p => p.Id == changedPlayerArgs.PlayerValues.Id);

                if (changedPlayerArgs.Column == ColumnName.IsCaptain && changedPlayerArgs.PlayerValues.IsCaptain)
                {
                    if (TeamDetails.Squad.Exists(p => (bool)p.IsCaptain.Value))
                    {
                        TeamDetails.Squad.Find(p => (bool)p.IsCaptain.Value).IsCaptain.SetValueToBinding(false);
                    }
                    player.IsCaptain.SetValueToBinding(changedPlayerArgs.PlayerValues.IsCaptain);
                    TeamDetails.Captain = player;
                }

                if (changedPlayerArgs.Column == ColumnName.Position)
                {
                    player.Position.SetValueToBinding(changedPlayerArgs.PlayerValues.Position.Role);
                    SetTeamSquadDetails();
                }

                break;

            case ChangeType.PlayerDeleted:
                var deletedPlayerArgs = (SoccerPlayerArgs)args;
                var deletedPlayer     = TeamDetails.Squad.Find(p => p.Id == deletedPlayerArgs.PlayerValues.Id);
                if ((bool)deletedPlayer.IsCaptain.Value)
                {
                    TeamDetails.Captain = null;
                }
                TeamDetails.Squad.Remove(deletedPlayer);
                SetTeamSquadDetails();
                break;

            default:
                break;
            }
        }
Exemple #29
0
        public static void HandlePropertyChangedNext(
            this Behavior behavior,
            IBehaviorContext context,
            ChangeArgs args
            )
        {
            IHandlePropertyChangedBehavior next;

            if (behavior.TryGetBehavior(out next))
            {
                next.HandlePropertyChanged(context, args);
            }
        }
Exemple #30
0
        public void UpdateValidationResult_AsPropertyBehavior_CallsNotifyChangeWithCorrectArgs()
        {
            SetupForProperty(ValueStage.DisplayValue);

            var oldResult = CreateValidationResult("New result");

            Manager.UpdateValidationResult(Context, oldResult);

            DomainAssert.AreEqual(
                ChangeArgs.ValidationResultChanged(Property, ValueStage.DisplayValue),
                Context.NotifyChangeInvocations.LastOrDefault()
                );
        }