public void MoveFieldDownCommandTest()
        {
            // Arrange.
            var field = new FieldEditMock("Text Field", "TextField", new FieldTypeInfo("Text", "String", true));
            var section = new SectionEditMock(1, "Test section");
            var pf = Mock.Create<ProcessFieldViewModel>();
            var pf2 = Mock.Create<ProcessFieldViewModel>();
            var pf3 = Mock.Create<ProcessFieldViewModel>();
            Mock.Arrange(() => pf.Model).Returns(new FieldEdit());
            Mock.Arrange(() => pf2.Model).Returns(new FieldEdit());
            Mock.Arrange(() => pf3.Model).Returns(new FieldEdit());
            section.FieldList.Add(field);

            var vm = new ProcessSectionViewModel(section);
            vm.FieldList.Add(pf);
            vm.FieldList.Add(pf3);
            vm.FieldList.Add(pf2);


            var pfvm = Mock.Create<ProcessFieldsViewModel>();
            Mock.Arrange(() => pfvm.Enabled).Returns(true);

            vm.TheProcessFieldsViewModel = pfvm;
            var ic = vm.MoveFieldDownCommand;

            var listboxM = new ListBoxItem { DataContext = pf };

            Assert.IsTrue(ic.CanExecute(listboxM));

            ic.Execute(listboxM);
            Assert.IsTrue(vm.FieldList[0].Model.Position == 0);
            Assert.IsTrue(vm.FieldList[1].Model.Position == 1);
        }
        public void ChangeFieldCommandTest()
        {
            // Arrange.
            var field = new FieldEditMock("Text Field", "TextField", new FieldTypeInfo("Text", "String", true));
            var section = new SectionEditMock(1, "Test section");

            section.FieldList.Add(field);

            var vm = new ProcessSectionViewModel(section);

            var pfvm = Mock.Create<ProcessFieldsViewModel>();

            vm.TheProcessFieldsViewModel = pfvm;
            var ic = vm.ChangeFieldCommand;

            Assert.IsTrue(ic.CanExecute(null));
            Assert.IsFalse(vm.TheProcessFieldsViewModel.IsFieldsFocused);

            ic.Execute(null);

            Assert.IsTrue(vm.TheProcessFieldsViewModel.IsFieldsFocused);
        }
        public void AddNewFieldCommandTest()
        {
            // Arrange.
            var field = new FieldEditMock("Text Field", "TextField", new FieldTypeInfo("Text", "String", true));
            var section = new SectionEditMock(1, "Test section");

            section.FieldList.Add(field);

            var vm = new ProcessSectionViewModel(section);
            var pfvm = Mock.Create<ProcessFieldsViewModel>();

            Mock.Arrange(() => pfvm.Enabled).Returns(true);
            Mock.Arrange(() => pfvm.UnitOfWork).Returns(new ProcessEditRetrieverMock(new ProcessEdit(), new FieldTypes()));

            vm.TheProcessFieldsViewModel = pfvm;
            var factory = Mock.Create<IFieldViewModelFactory>();

            vm.FieldFactory = factory;

            var ic = vm.AddNewFieldCommand;

            Assert.IsTrue(ic.CanExecute(null));
        }
        public void RemoveFieldCommandTest()
        {
            // Arrange.
            var field = new FieldEditMock("Text Field", "TextField", new FieldTypeInfo("Text", "String", true));
            var section = new SectionEditMock(1, "Test section");

            section.FieldList.Add(field);

            var vm = new ProcessSectionViewModel(section);

            var pfvm = Mock.Create<ProcessFieldsViewModel>();
            Mock.Arrange(() => pfvm.Enabled).Returns(true);
            vm.TheProcessFieldsViewModel = pfvm;

            var pf = Mock.Create<ProcessFieldViewModel>();

            Mock.Arrange(() => pf.Model).Returns(new FieldEdit() { IsBase = true });

            vm.SelectedField = pf;

            var ic = vm.RemoveFieldCommand;

            Assert.IsFalse(ic.CanExecute(null));

            Mock.Arrange(() => pf.Model).Returns(new FieldEdit() { IsBase = false });
            vm.SelectedField = pf;

            Assert.IsTrue(ic.CanExecute(null));
        }
Ejemplo n.º 5
0
        [TestMethod]
        public void WhenModelChildIsChanged_PropertiesAreUpdated()
        {
            // Arrange.
            var screenMock = Mock.Create<IFieldSecurityManager>();

            var field = new FieldEditMock();

            var processMock = Mock.Create<ProcessEdit>();

            var steps = new List<IStepEdit>();

            var stepMock = Mock.Create<IStepEdit>();
            Mock.Arrange(() => stepMock.IsChild).Returns(true);
            steps.Add(stepMock);

            stepMock = Mock.Create<IStepEdit>();
            Mock.Arrange(() => stepMock.IsChild).Returns(true);
            steps.Add(stepMock);

            stepMock = Mock.Create<IStepEdit>();
            Mock.Arrange(() => stepMock.IsChild).Returns(true);
            steps.Add(stepMock);

            field.StepList.AddRange(steps);

            var vm = new ExpandableStepPropBag(processMock) { FieldSecurityManager = screenMock, Model = field };

            field.RaiseChildChanged();

            foreach (var mock in steps)
            {
                Mock.Assert(() => mock.UpdateProps(vm), Occurs.Once());
            }