public void AdjustScheduleDateCommand_CanExecute_Tests() { // arrange var vm = new ScheduleDateFieldViewModel(); vm.Init(new EditableRoot{Id = 10}, DateTime.Today, null); // act var canExecute = vm.AdjustScheduleDateCommand.CanExecute(null); // assert Assert.IsTrue(canExecute); // arrnage vm.Init(new EditableRoot{Id = 9}, DateTime.Today, null); // act canExecute = vm.AdjustScheduleDateCommand.CanExecute(null); // assert Assert.IsFalse(canExecute); // arrnage vm.Init(new EditableRootBase(), DateTime.Today, null); // act canExecute = vm.AdjustScheduleDateCommand.CanExecute(null); // assert Assert.IsFalse(canExecute); }
public void FirstInitializationTests() { // arrange var vm = new ScheduleDateFieldViewModel { Property = typeof(EditableRoot).GetProperty("ScheduleDisplayDate") }; var expectedDate = (string)new DateTimeFormatConverter().Convert(DateTime.Now, null, DateTimeFormat.Date.ToString(), CultureInfo.InvariantCulture); // act vm.Init(new EditableRoot(), DateTime.Now, null); // assert Assert.AreEqual(expectedDate, vm.DisplayDate); // arrange vm.Property = typeof (EditableRoot).GetProperty("ScheduleDisplayDateWithOutDateTimeFormat"); // act vm.Init(new EditableRoot(), DateTime.Today, null); // assert Assert.AreEqual(((object)DateTime.Today).ToString(), vm.DisplayDate); }
public void ScheduleFieldTests() { // arrange var fieldViewModel = new ScheduleDateFieldViewModel(); var popupViewModel = new ExportFactory<ScheduleDateFieldViewModel>(() => new Tuple<ScheduleDateFieldViewModel, Action>(fieldViewModel, null)); var fieldFactory = new FieldFactory { ScheduleDateFieldViewModelFactory = popupViewModel }; var model = new ModelStub { ScheduleDateField = DateTime.Now }; var property = model.GetType().GetProperty("ScheduleDateField"); // act var viewModel = fieldFactory.CreateField(property, null, model, new DetailsViewModel(), false); // assert Assert.IsTrue(viewModel is ScheduleDateFieldViewModel); }
public void AdjustScheduleDateCommand_Execute_Tests() { // arrange var vm = new ScheduleDateFieldViewModel { Property = typeof(EditableRoot).GetProperty("ScheduleDisplayDate") }; var model = new EditableRoot { Id = 10, IsScheduleDateChangedForOnlyItem = true }; vm.Init(model, DateTime.Today, null); vm.ScheduleDateChangeViewModel = new ExportFactory<ScheduleDateChangeViewModel>(() => new Tuple<ScheduleDateChangeViewModel, Action>(new ScheduleDateChangeViewModel(), null)); var popupBuilder = Mock.Create<PopupBuilder>(Behavior.CallOriginal); Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead<Action, Func<bool>>((onOk, onCancel) => onOk()); Mock.Arrange(() => popupBuilder.SetCustomViewModel(Arg.IsAny<INotificationViewModel>())).Returns(popupBuilder); var popupFactory = Mock.Create<PopupFactory>(Behavior.Loose); Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder); vm.ThePopupFactory = popupFactory; var expectedDate = (string)new DateTimeFormatConverter().Convert(DateTime.Today, null, DateTimeFormat.Date.ToString(), CultureInfo.InvariantCulture); // act vm.AdjustScheduleDateCommand.Execute(null); // assert Assert.IsNotNull(vm.DisplayDate); Assert.AreEqual(expectedDate, vm.DisplayDate); Assert.AreEqual(DateTime.Today, ((ISupportScheduling)vm.ParentModel).ScheduleDisplayDate); Assert.IsTrue(((ISupportScheduling)vm.ParentModel).IsScheduleDateChangedForOnlyItem); }
public void Override_OnValueChanged_Tests() { // arrange var vm = new ScheduleDateFieldViewModel(); vm.Init(new EditableRoot { Id = 10 }, DateTime.Today, null); // act vm.Value = DateTime.Now; // assert Assert.IsTrue(vm.AdjustScheduleDateCommand.CanExecute(null)); }