public void ShouldDispose()
 {
     var model = new ModelStub();
     model.IsDisposed.ShouldBe(false);
     model.Dispose();
     model.IsDisposed.ShouldBe(true);
 }
Exemplo n.º 2
0
        public void ShouldCalculateSumOfAllSubmittedOrders()
        {
            IModel model  = new ModelStub();
            string amount = userReportController.GetUserTotalOrderAmountView("123", model);

            Assert.AreEqual("userTotal", amount);
            Assert.AreEqual(String.Format("User Total: {0}$", 363.15), model.GetAttribute("userTotalMessage"));
        }
        public void Bind_Model_ModelIsBound()
        {
            var model = new ModelStub("Test", 2);

            _collectionViewModel.Bind(model);

            Assert.True(_collectionViewModel.IsBound(model));
        }
Exemplo n.º 4
0
        public void ShouldGetWarningMessageWhenUserDoesntExist()
        {
            IModel model  = new ModelStub();
            String amount = userReportController.GetUserTotalOrderAmountView("0001", model);

            Assert.AreEqual("userTotal", amount);
            Assert.AreEqual("WARNING: User ID doesn't exist.", model.GetAttribute("userTotalMessage"));
        }
Exemplo n.º 5
0
        public void GetHashCodeShouldReturnTheModelsHashCode()
        {
            var modelA = new ModelStub(System.Guid.NewGuid(), 1);

            ModelEqualityComparer<ModelStub> comparer = new ModelEqualityComparer<ModelStub>();

            Assert.That(((IEqualityComparer)comparer).GetHashCode(modelA), Is.EqualTo(modelA.GetHashCode()));
            Assert.That(((IEqualityComparer<ModelStub>)comparer).GetHashCode(modelA), Is.EqualTo(modelA.GetHashCode()));
        }
Exemplo n.º 6
0
        public void EqualsShouldReturnTrueWhenBothModelsAreEqual()
        {
            var modelA = new ModelStub(System.Guid.NewGuid(), 1);
            var modelB = new ModelStub(modelA.Id, 1);

            ModelEqualityComparer<ModelStub> comparer = new ModelEqualityComparer<ModelStub>();

            Assert.That(((IEqualityComparer)comparer).Equals(modelA, modelB), Is.True);
            Assert.That(((IEqualityComparer<ModelStub>)comparer).Equals(modelA, modelB), Is.True);
        }
Exemplo n.º 7
0
        public void ShouldGetWarningMessageWhenUserHaveNoSubmittedOrders()
        {
            userReportController.GetUserReportBuilder().GetUserDao().GetUser("123").GetAllOrders().Clear();

            IModel model  = new ModelStub();
            String amount = userReportController.GetUserTotalOrderAmountView("123", model);

            Assert.AreEqual("userTotal", amount);
            Assert.AreEqual("WARNING: User have no submitted orders.", model.GetAttribute("userTotalMessage"));
        }
        public void RemoveChildren_ViewModel_ModelUnbound()
        {
            var model = new ModelStub("Test", 2);

            _collectionViewModel.Bind(model);

            _collectionViewModel.Children.Remove(_collectionViewModel.Children.First());

            Assert.False(_collectionViewModel.IsBound(model));
        }
Exemplo n.º 9
0
        public void ShouldGetErrorMessageWhenOrderHaveNegativeAmount()
        {
            userReportController.GetUserReportBuilder().GetUserDao().GetUser("123").GetAllOrders().Add(new SubmittedNegativeOrderStub());


            IModel model  = new ModelStub();
            String amount = userReportController.GetUserTotalOrderAmountView("123", model);

            Assert.AreEqual("userTotal", amount);
            Assert.AreEqual("ERROR: Wrong order amount.", model.GetAttribute("userTotalMessage"));
        }
        public void AddChildren_ViewModel_ModelIsBound()
        {
            var model     = new ModelStub("Test", 2);
            var viewModel = new ViewModelStub();

            viewModel.Bind(model);

            _collectionViewModel.Children.Add(viewModel);

            Assert.True(_collectionViewModel.IsBound(model));
        }
        public void Bind_Model_AddedToChildrenOnce()
        {
            var model = new ModelStub("Test", 2);

            _collectionViewModel.Bind(model);

            var child = _collectionViewModel.Children.SingleOrDefault(vm => Equals(vm.ActiveModel, model));

            Assert.NotNull(child);
            Assert.Equal(2, _collectionViewModel.Children[0].Value);
        }
Exemplo n.º 12
0
        public void EqualShouldReturnTrueWhenModelsAreEqual()
        {
            ModelStub model1 = new ModelStub();
            ModelStub model2 = model1;
            ModelStub model4 = new ModelStub(System.Guid.NewGuid(), 1);
            ModelStub model5 = new ModelStub(model4.Id, 2);

            Assert.That(model1, Is.EqualTo(model2));

            Assert.That(model4, Is.EqualTo(model5));
        }
Exemplo n.º 13
0
        public void GetHashCodeShouldReturnSameHasCodeWhereModelIdentityIsEqual()
        {
            ModelStub model1 = new ModelStub();
            ModelStub model2 = new ModelStub();

            Assert.That(model1.GetHashCode(), Is.Not.EqualTo(model2.GetHashCode()));

            ModelStub model3 = new ModelStub(System.Guid.NewGuid(), 0);
            ModelStub model4 = new ModelStub(model3.Id, 0);

            Assert.That(model3.GetHashCode(), Is.Not.EqualTo(model4.GetHashCode()));
        }
        public void Unbind_ViewModel_ModelUnbound()
        {
            var model = new ModelStub("Test", 2);

            _collectionViewModel.Bind(model);

            var child = _collectionViewModel.Children.First();

            _collectionViewModel.Unbind(child);

            Assert.False(_collectionViewModel.IsBound(model));
        }
        public void Unbind_Model_RemovedFromChildren()
        {
            var model = new ModelStub("Test", 2);

            _collectionViewModel.Bind(model);

            _collectionViewModel.Unbind(model);

            var child = _collectionViewModel.Children.FirstOrDefault(vm => Equals(vm.ActiveModel, model));

            Assert.Null(child);
        }
Exemplo n.º 16
0
        public void EqualsShouldReturnFalseWhenEitherModelIsNull()
        {
            var modelA = new ModelStub(System.Guid.NewGuid(), 1);
            var modelB = new ModelStub(modelA.Id, 1);

            ModelEqualityComparer<ModelStub> comparer = new ModelEqualityComparer<ModelStub>();

            Assert.That(((IEqualityComparer)comparer).Equals(modelA, null), Is.False);
            Assert.That(((IEqualityComparer)comparer).Equals(null, modelB), Is.False);
            Assert.That(((IEqualityComparer<ModelStub>)comparer).Equals(modelA, null), Is.False);
            Assert.That(((IEqualityComparer<ModelStub>)comparer).Equals(null, modelB), Is.False);
        }
        public void Bind_ViewModel_AddedToChildrenOnce()
        {
            var model     = new ModelStub("Test", 2);
            var viewModel = new ViewModelStub();

            viewModel.Bind(model);

            _collectionViewModel.Bind(viewModel);

            var child = _collectionViewModel.Children.Single(vm => Equals(vm.ActiveModel, model));

            Assert.NotNull(child);
        }
        public void ShouldCallOnDisposedVirtualMethodWhenDisposedOf()
        {
            var model = new ModelStub();
            model.DisposeOfManagedResourcesCount.ShouldBe(0);

            model.Dispose();
            model.DisposeOfManagedResourcesCount.ShouldBe(1);

            model.Dispose();
            model.Dispose();
            model.Dispose();
            model.DisposeOfManagedResourcesCount.ShouldBe(1);
        }
Exemplo n.º 19
0
        public void GetHashCodeShouldReturnAUniqueHashCodePerModelIdentity()
        {
            ModelStub model1 = new ModelStub();
            ModelStub model2 = model1;

            Assert.That(model1.GetHashCode(), Is.EqualTo(model1.GetHashCode()));

            Assert.That(model1.GetHashCode(), Is.EqualTo(model2.GetHashCode()));

            ModelStub model3 = new ModelStub(System.Guid.NewGuid(), 1);
            ModelStub model4 = new ModelStub(model3.Id, 1);

            Assert.That(model3.GetHashCode(), Is.EqualTo(model4.GetHashCode()));
        }
Exemplo n.º 20
0
        public void EqualShouldReturnFalseWhenModelsAreNotEqual()
        {
            ModelStub model1 = new ModelStub();
            ModelStub model2 = new ModelStub();
            ModelStub model3 = new ModelStub(System.Guid.NewGuid(), 0);
            ModelStub model4 = new ModelStub(model3.Id, 0);
            ModelStub model5 = new ModelStub(System.Guid.NewGuid(), 1);

            Assert.That(model1, Is.Not.EqualTo(model2));
            Assert.That(model3, Is.Not.EqualTo(model4));

            NotEqualHelper(model1);
            NotEqualHelper(model5);
        }
        public void ShouldReportPropertyChanged()
        {
            var model = new ModelStub();
            model.ShouldFirePropertyChanged(() => model.Text1 = "value", ModelStub.PropText1);

            var eventCount = 0;
            model.PropertyChanged += (sender, e) => eventCount++;

            model.TestOnPropertyChanged("Name");
            eventCount.ShouldBe(1);

            eventCount = 0;
            model.TestOnPropertyChanged("Name1", "Name2");
            eventCount.ShouldBe(2);
        }
        public void Bind_ExistingModel_UpdatesOnly()
        {
            var model = new ModelStub("Test", 2);

            _collectionViewModel.Bind(model);

            Assert.Single(_collectionViewModel.Children);
            Assert.Equal(2, _collectionViewModel.Children[0].Value);

            model.Value = 3;

            _collectionViewModel.Bind(model);

            Assert.Single(_collectionViewModel.Children);
            Assert.Equal(3, _collectionViewModel.Children[0].Value);
        }
        public void ShouldFireWhenDisposed()
        {
            var model = new ModelStub();

            var fireCount = 0;
            model.Disposed += delegate { fireCount++; };

            model.Dispose();
            fireCount.ShouldBe(1);

            // ---

            model.Dispose();
            model.Dispose();
            model.Dispose();
            fireCount.ShouldBe(1);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        public void BlockedContentTests()
        {
            // arrange
            var fieldViewModel = new FieldViewModel();
            var popupViewModel = new ExportFactory<FieldViewModel>(() => new Tuple<FieldViewModel, Action>(fieldViewModel, null));

            var fieldFactory = new FieldFactory { FieldViewModelFactory = popupViewModel };

            var model = new ModelStub();
            var property = model.GetType().GetProperty("BlockedContentField");

            var detailViewMdoel = new DetailsViewModel();

            // act
            var viewModel = fieldFactory.CreateField(property, null, model, detailViewMdoel, false);

            // assert
            Assert.IsTrue(viewModel is FieldViewModel);
        }
        public void ShouldInvokeAsyncronously()
        {
            var startContext = SynchronizationContext.Current;
            var model = new ModelStub();

            PropertyChangedEventArgs args = null;
            model.PropertyChanged += (sender, e) => args = e;

            Action onComplete = () =>
                                    {
                                        model.ActionInvoked.ShouldBe(true);
                                        model.AsyncOperationCount.ShouldBe(0);
                                        model.AsyncCountDuringAction.ShouldBe(1);
                                        SynchronizationContext.Current.ShouldBe(startContext);
                                        args.PropertyName.ShouldBe(PropRunningAsyncOperations);

                                        EnqueueTestComplete();
                                    };

            model.DoAsync(startContext, 50, onComplete);
        }
        public void ShouldRunSynchronously()
        {
            var model = new ModelStub();
            ModelBase.IsAsyncEnabled.ShouldBe(true);
            ModelBase.IsAsyncEnabled = false;

            PropertyChangedEventArgs args = null;
            model.PropertyChanged += (sender, e) => args = e;

            var onCompleteCalled = false;
            Action onComplete = () =>
                                    {
                                        onCompleteCalled = true;
                                    };

            var result =model.DoAsync(5, onComplete);
            result.ShouldBe(null);

            onCompleteCalled.ShouldBe(true);
            model.ActionInvoked.ShouldBe(true);
            model.AsyncOperationCount.ShouldBe(0);
            model.AsyncCountDuringAction.ShouldBe(1);
            args.PropertyName.ShouldBe(PropRunningAsyncOperations);
        }
Exemplo n.º 28
0
        public void DateTimeFieldTests()
        {
            // arrange
            var fieldViewModel = new DateTimeFieldViewModel();
            var popupViewModel = new ExportFactory<DateTimeFieldViewModel>(() => new Tuple<DateTimeFieldViewModel, Action>(fieldViewModel, null));

            var fieldFactory = new FieldFactory { DateTimeFieldViewModelFactory = popupViewModel };

            var model = new ModelStub();
            var property = model.GetType().GetProperty("DateTimeField");

            // act
            var viewModel = fieldFactory.CreateField(property, null, model, new DetailsViewModel(), false);

            // assert
            Assert.AreEqual("Time", ((DateTimeFieldViewModel)viewModel).InputMode);
        }
Exemplo n.º 29
0
        public void TextFieldTests()
        {
            // arrange
            var fieldViewModel = new TextFieldViewModel();
            var popupViewModel = new ExportFactory<TextFieldViewModel>(() => new Tuple<TextFieldViewModel, Action>(fieldViewModel, null));

            var fieldFactory = new FieldFactory { TextFieldViewModelFactory = popupViewModel };

            var model = new ModelStub();
            var property = model.GetType().GetProperty("TextField");

            // act
            var viewModel = fieldFactory.CreateField(property, null, model, new DetailsViewModel(), false);

            // assert
            Assert.AreEqual(2, ((TextFieldViewModel)viewModel).NumberOfRows);
        }
Exemplo n.º 30
0
        public void CreateField_Returns_SingleItemViewDisplayListFieldViewModel()
        {
            // Arrange.
            const string ProcessName = "TestProcess";

            var fieldViewModel = Mock.Create<ISingleItemViewDisplayListFieldViewModel>(Behavior.Loose);
            var fieldViewModelFactory =
                new ExportFactory<ISingleItemViewDisplayListFieldViewModel>(
                    () => Tuple.Create<ISingleItemViewDisplayListFieldViewModel, Action>(fieldViewModel, () => { }));

            var list = Mock.Create<IDisplayListItemList>(Behavior.Loose);
            var displayListManager = Mock.Create<IDisplayListManager>(Behavior.Loose);
            var model = new ModelStub
                            {
                                ProcessName = ProcessName,
                                SingleItemViewDisplayList = list,
                                SingleItemViewDisplayList_Manager = displayListManager
                            };

            var property = TestsHelper.ExtractProperty(() => model.SingleItemViewDisplayList);
            var detailsViewModel = Mock.Create<IDetailsViewModel>(Behavior.Loose);
            var dtm = Mock.Create<IDynamicTypeManager>(Behavior.Loose);
            Mock.Arrange(() => dtm.GetDisplayListItemType(ProcessName, property.Name)).Returns(typeof(DisplayListItem));

            var fieldFactory = new FieldFactory
                                   {
                                       TheDynamicTypeManager = dtm,
                                       SingleItemViewDisplayListFieldViewModelFactory = fieldViewModelFactory
                                   };

            // Act.
            var result = (ISingleItemViewDisplayListFieldViewModel)fieldFactory.CreateField(property, null, model, detailsViewModel, false);

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreEqual("DisplayListSingleItemView", result.FieldType);
            Assert.AreSame(property, result.Property);
            Assert.AreSame(detailsViewModel, result.ParentDetailsVM);
            Mock.Assert(() => result.Init(model, list, detailsViewModel), Occurs.Once());
            Assert.AreSame(typeof(DisplayListItem), result.ItemType);
            Assert.AreEqual("RefProcess", result.ReferencedProcess);
            Assert.AreSame(displayListManager, result.DisplayListManager);
        }
Exemplo n.º 31
0
        public void RichFieldTests()
        {
            // arrange
            var fieldViewModel = new RichTextFieldViewModel();
            var popupViewModel = new ExportFactory<RichTextFieldViewModel>(() => new Tuple<RichTextFieldViewModel, Action>(fieldViewModel, null));

            var fieldFactory = new FieldFactory { RichTextFieldViewModelFactory = popupViewModel };

            var model = new ModelStub();
            var property = model.GetType().GetProperty("RichTextField");

            // act
            var viewModel = fieldFactory.CreateField(property, null, model, new DetailsViewModel(), false);

            // assert
            Assert.IsTrue(viewModel is RichTextFieldViewModel);
        }
 public void ShouldBeSerializableToXml()
 {
     var model = new ModelStub();
     var xml = model.ToSerializedXml();
     xml.Length.ShouldNotBe(0);
 }
        public void ShouldBeSerializable()
        {
            var model = new ModelStub();
            var dcs = new DataContractSerializer(typeof(ModelStub));
            var stream = new MemoryStream();

            dcs.WriteObject(stream, model);
            stream.Length.ShouldNotBe(0);
        }
 public void ShouldRequireAction()
 {
     var model = new ModelStub();
     Should.Throw<ArgumentNullException>(() => model.DoAsyncNull());
 }