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();
        }
        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);
        }