Esempio n. 1
0
        public void EnsureModel_ModelIsNotNull_DoesNothing()
        {
            // Arrange
            ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext()
            {
                ModelMetadata = GetMetadataForObject(new Person())
            };

            Mock <TestableMutableObjectModelBinder> mockTestableBinder = new Mock <TestableMutableObjectModelBinder>()
            {
                CallBase = true
            };

            mockTestableBinder.Expect(o => o.CreateModelPublic(null, bindingContext)).Never();
            TestableMutableObjectModelBinder testableBinder = mockTestableBinder.Object;

            // Act
            object originalModel = bindingContext.Model;

            testableBinder.EnsureModelPublic(null, bindingContext);
            object newModel = bindingContext.Model;

            // Assert
            Assert.AreSame(originalModel, newModel, "Model instance shouldn't have changed.");
            mockTestableBinder.Verify();
        }
        public void EnsureModel_ModelIsNull_CallsCreateModel()
        {
            // Arrange
            ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext
            {
                ModelMetadata = GetMetadataForType(typeof(Person))
            };

            Mock <TestableMutableObjectModelBinder> mockTestableBinder = new Mock <TestableMutableObjectModelBinder> {
                CallBase = true
            };

            mockTestableBinder.Setup(o => o.CreateModelPublic(null, bindingContext)).Returns(new Person()).Verifiable();
            TestableMutableObjectModelBinder testableBinder = mockTestableBinder.Object;

            // Act
            object originalModel = bindingContext.Model;

            testableBinder.EnsureModelPublic(null, bindingContext);
            object newModel = bindingContext.Model;

            // Assert
            Assert.Null(originalModel);
            Assert.IsType <Person>(newModel);
            mockTestableBinder.Verify();
        }
Esempio n. 3
0
        public void EnsureModel_ModelIsNotNull_DoesNothing()
        {
            // Arrange
            ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext
            {
                ModelMetadata = GetMetadataForObject(new Person())
            };

            Mock <TestableMutableObjectModelBinder> mockTestableBinder =
                new Mock <TestableMutableObjectModelBinder> {
                CallBase = true
            };
            TestableMutableObjectModelBinder testableBinder = mockTestableBinder.Object;

            // Act
            object originalModel = bindingContext.Model;

            testableBinder.EnsureModelPublic(null, bindingContext);
            object newModel = bindingContext.Model;

            // Assert
            Assert.Same(originalModel, newModel);
            mockTestableBinder.Verify(
                o => o.CreateModelPublic(null, bindingContext),
                Times.Never()
                );
        }