public void ModelIsChanged_ViewModelRaisesNotifications()
        {
            var simpleModel        = new SimpleEditableModel();
            var mockMessageService = new FakeMessageService();

            var  rootObject = CreateRootObject();
            var  screenObjectViewModel = new TestEditableScreenSimpleObjectViewModel(mockMessageService, simpleModel);
            bool wasDirtyRaised = false, wasCancelChangesRaised = false;

            screenObjectViewModel.PropertyChanged += (sender, args) =>
            {
                switch (args.PropertyName)
                {
                case "IsDirty":
                    wasDirtyRaised = true;
                    break;

                case "CanCancelChanges":
                    wasCancelChangesRaised = true;
                    break;
                }
            };
            rootObject.ActivateItem(screenObjectViewModel);
            simpleModel.Name = DataGenerator.ValidName;

            wasDirtyRaised.Should().BeTrue();
            wasCancelChangesRaised.Should().BeTrue();
        }
Ejemplo n.º 2
0
        public void ModelIsChanged_ViewModelRaisesNotifications()
        {
            var simpleModel = new SimpleEditableModel();

            var  rootObject = new TestEditableObjectViewModel(simpleModel);
            bool wasDirtyRaised = false, wasCancelChangesRaised = false;

            rootObject.PropertyChanged += (sender, args) =>
            {
                switch (args.PropertyName)
                {
                case "IsDirty":
                    wasDirtyRaised = true;
                    break;

                case "CanCancelChanges":
                    wasCancelChangesRaised = true;
                    break;
                }
            };
            simpleModel.Name = DataGenerator.ValidName;

            wasDirtyRaised.Should().BeTrue();
            wasCancelChangesRaised.Should().BeTrue();
        }
Ejemplo n.º 3
0
 public CompositeEditableModel(string location, IEnumerable <SimpleEditableModel> simpleCollection)
 {
     Location = location;
     _person  = new SimpleEditableModel();
     foreach (var simpleEditableModel in simpleCollection)
     {
         _simpleCollection.Add(simpleEditableModel);
     }
 }
        public void ModelIsNotChanged_WhenViewModelIsClosed_MessageBoxIsNotDisplayed()
        {
            var simpleModel        = new SimpleEditableModel();
            var mockMessageService = new FakeMessageService();

            var rootObject            = CreateRootObject();
            var screenObjectViewModel = new TestEditableScreenSimpleObjectViewModel(mockMessageService, simpleModel);

            rootObject.ActivateItem(screenObjectViewModel);
            screenObjectViewModel.CloseCommand.Execute(null);

            var wasCalled = mockMessageService.WasCalled;

            wasCalled.Should().BeFalse();
        }
        public void ModelIsChanged_WhenViewModelIsClosedAndMessageResultIsNo_ThenOnChangesCancelingIsCalled()
        {
            string initialValue       = string.Empty;
            var    simpleModel        = new SimpleEditableModel(initialValue, 20);
            var    stubMessageService = new FakeMessageService();

            stubMessageService.SetMessageResult(MessageResult.No);
            RegisterInstance <IMessageService>(stubMessageService);

            var rootObject            = CreateRootObject();
            var screenObjectViewModel = new TestEditableScreenSimpleObjectViewModel(stubMessageService, simpleModel);

            rootObject.ActivateItem(screenObjectViewModel);
            simpleModel.Name = DataGenerator.ValidName;
            screenObjectViewModel.CloseCommand.Execute(null);

            var wasCalled = screenObjectViewModel.WasCancelingChangesCalled;

            wasCalled.Should().BeTrue();
        }
        public void ModelIsChanged_WhenViewModelIsClosedAndMessageResultIsYes_ModelIsSaved()
        {
            var simpleModel        = new SimpleEditableModel();
            var stubMessageService = new FakeMessageService();

            stubMessageService.SetMessageResult(MessageResult.Yes);

            var rootObject            = CreateRootObject();
            var screenObjectViewModel = new TestEditableScreenSimpleObjectViewModel(stubMessageService, simpleModel);

            rootObject.ActivateItem(screenObjectViewModel);
            const string expectedValue = DataGenerator.ValidName;

            simpleModel.Name = expectedValue;
            screenObjectViewModel.CloseCommand.Execute(null);

            var isDirty = simpleModel.IsDirty;

            isDirty.Should().BeFalse();
            var actualValue = simpleModel.Name;

            actualValue.Should().Be(expectedValue);
        }
        public void ModelIsChanged_WhenViewModelIsClosedAndMessageResultIsCancel_ModelIsSaved()
        {
            string       initialValue       = string.Empty;
            const string newValue           = DataGenerator.ValidName;
            var          simpleModel        = new SimpleEditableModel(initialValue, 20);
            var          stubMessageService = new FakeMessageService();

            stubMessageService.SetMessageResult(MessageResult.Cancel);

            var rootObject            = CreateRootObject();
            var screenObjectViewModel = new TestEditableScreenSimpleObjectViewModel(stubMessageService, simpleModel);

            rootObject.ActivateItem(screenObjectViewModel);
            simpleModel.Name = newValue;
            screenObjectViewModel.CloseCommand.Execute(null);

            var isDirty = simpleModel.IsDirty;

            isDirty.Should().BeTrue();
            var actualValue = simpleModel.Name;

            actualValue.Should().Be(DataGenerator.ValidName);
        }
Ejemplo n.º 8
0
 public void AddSimpleModelImpl(SimpleEditableModel simpleEditableModel)
 {
     _simpleCollection.Add(simpleEditableModel);
 }
Ejemplo n.º 9
0
 public void RemoveSimpleItem(SimpleEditableModel item)
 {
     MakeDirty();
     _simpleCollection.Remove(item);
 }
Ejemplo n.º 10
0
 public CompositeEditableModel(string location, IEnumerable <int> phones)
 {
     Location = location;
     _person  = new SimpleEditableModel();
     Phones.AddRange(phones);
 }
Ejemplo n.º 11
0
 public CompositeEditableModel(string location)
 {
     Location = location;
     _person  = new SimpleEditableModel();
 }