Exemplo n.º 1
0
        public void AddScheduleCommand_Test()
        {
            var model = new SchedulerDescriptorEditMock();
            var vm = new SchedulerViewModel();
            var scheduleViewModelMocks = new List<IScheduleViewModel>();

            vm.ScheduleViewModelFactory = new ExportFactory<IScheduleViewModel>(
                () =>
                    {
                        var vmMock = Mock.Create<IScheduleViewModel>();

                        scheduleViewModelMocks.Add(vmMock);
                        return new Tuple<IScheduleViewModel, Action>(vmMock, () => { });
                    });

            vm.Initialize(model);

            Assert.AreEqual(0, model.ScheduleList.Count);
            Assert.AreEqual(0, vm.ScheduleList.Count);

            vm.AddScheduleCommand.Execute(new object());

            Assert.AreEqual(1, model.ScheduleList.Count);
            Assert.AreEqual(1, vm.ScheduleList.Count);

            Mock.Assert(() => scheduleViewModelMocks[0].Initialize(model.ScheduleList[0]));
        }
Exemplo n.º 2
0
        public void RemoveScheduleCommand_Test()
        {
            var model = new SchedulerDescriptorEditMock();

            model.ScheduleList.Add(DataPortal.CreateChild<ScheduleEdit>());
            model.ScheduleList.Add(DataPortal.CreateChild<ScheduleEdit>());

            var vm = new SchedulerViewModel
                         {
                             ScheduleViewModelFactory = new ExportFactory<IScheduleViewModel>(
                                 () =>
                                     {
                                         var vmMock = Mock.Create<IScheduleViewModel>(Behavior.CallOriginal);

                                         Mock.Arrange(() => vmMock.Initialize(Arg.IsAny<ScheduleEdit>())).DoInstead<ScheduleEdit>(s => Mock.Arrange(() => vmMock.Model).Returns(s));

                                         return new Tuple<IScheduleViewModel, Action>(vmMock, () => { });
                                     })
                         };

            var popupBuilderMock = Mock.Create<PopupBuilder>(Behavior.CallOriginal);

            Action onOk = null;

            Mock.Arrange(() => popupBuilderMock.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).Returns<Action, Func<bool>>(
                (ok, cancel) =>
                    {
                        onOk = ok;
                        return popupBuilderMock;
                    });
            
            var popupFactoryMock = Mock.Create<PopupFactory>(Behavior.CallOriginal);

            Mock.Arrange(() => popupFactoryMock.Popup()).Returns(popupBuilderMock);

            vm.ThePopupFactory = popupFactoryMock;

            vm.Initialize(model);

            vm.SelectedSchedule = null;

            Assert.IsFalse(vm.RemoveScheduleCommand.CanExecute(new object()));

            var scheduleToRemove = vm.ScheduleList.First();
            vm.SelectedSchedule = scheduleToRemove;

            Assert.IsTrue(vm.RemoveScheduleCommand.CanExecute(new object()));

            vm.RemoveScheduleCommand.Execute(new object());

            Assert.IsNotNull(onOk);

            onOk();
            Assert.AreEqual(1, vm.ScheduleList.Count);
            Assert.AreEqual(1, model.ScheduleList.Count);
            Assert.AreSame(vm.ScheduleList[0], vm.SelectedSchedule);
            Assert.IsFalse(vm.ScheduleList.Contains(scheduleToRemove));
        }
Exemplo n.º 3
0
        public void OnSaved_Test()
        {
            var model = new SchedulerDescriptorEditMock();
            var schedule1 = DataPortal.CreateChild<ScheduleEdit>();
            var schedule2 = DataPortal.CreateChild<ScheduleEdit>();

            model.ScheduleList.Add(schedule1);
            model.ScheduleList.Add(schedule2);

            var vm = new SchedulerViewModel();
            var scheduleViewModelMocks = new List<IScheduleViewModel>();

            vm.ScheduleViewModelFactory = new ExportFactory<IScheduleViewModel>(
                () =>
                    {
                        var vmMock = Mock.Create<IScheduleViewModel>();

                        scheduleViewModelMocks.Add(vmMock);
                        return new Tuple<IScheduleViewModel, Action>(vmMock, () => { });
                    });

            vm.Initialize(model);

            var newModel = new SchedulerDescriptorEditMock();

            newModel.ScheduleList.Add(DataPortal.CreateChild<ScheduleEdit>());
            newModel.ScheduleList.Add(DataPortal.CreateChild<ScheduleEdit>());
            newModel.ScheduleList.Add(DataPortal.CreateChild<ScheduleEdit>());

            scheduleViewModelMocks.Clear();

            vm.OnSaved(newModel);

            Assert.AreEqual(3, vm.ScheduleList.Count);
            Assert.IsTrue(scheduleViewModelMocks.Select(mock => mock).SequenceEqual(vm.ScheduleList));

            for (var i = 0; i < scheduleViewModelMocks.Count; i++)
            {
                var i1 = i;
                Mock.Assert(() => scheduleViewModelMocks[i1].Initialize(newModel.ScheduleList[i1]));
            }
        }