Пример #1
0
        public void GetTypeDescriptor_NullInstanceWithParent_ThrowsArgumentNullException()
        {
            var mockParentProvider = new Mock <TypeDescriptionProvider>(MockBehavior.Strict);
            var provider           = new SubTypeDescriptionProvider(mockParentProvider.Object);

            AssertExtensions.Throws <ArgumentNullException>("instance", () => provider.GetTypeDescriptor((object)null));
        }
Пример #2
0
        public void GetTypeDescriptor_InvokeTypeObjectWithParent_ReturnsExpected(Type objectType, object instance, ICustomTypeDescriptor result)
        {
            var mockParentProvider = new Mock <TypeDescriptionProvider>(MockBehavior.Strict);

            mockParentProvider
            .Setup(p => p.GetTypeDescriptor(objectType, instance))
            .Returns(result)
            .Verifiable();
            var provider = new SubTypeDescriptionProvider(mockParentProvider.Object);

            Assert.Same(result, provider.GetTypeDescriptor(objectType, instance));
            mockParentProvider.Verify(p => p.GetTypeDescriptor(objectType, instance), Times.Once());

            // Call again.
            Assert.Same(result, provider.GetTypeDescriptor(objectType, instance));
            mockParentProvider.Verify(p => p.GetTypeDescriptor(objectType, instance), Times.Exactly(2));
        }
Пример #3
0
        public void GetTypeDescriptor_NullInstance_ThrowsArgumentNullException()
        {
            var provider = new SubTypeDescriptionProvider();

            AssertExtensions.Throws <ArgumentNullException>("instance", () => provider.GetTypeDescriptor((object)null));
        }
Пример #4
0
        public void GetTypeDescriptor_InvokeTypeObjectWithoutParent_ReturnsExpected(Type objectType, object instance)
        {
            var provider = new SubTypeDescriptionProvider();
            CustomTypeDescriptor result1 = Assert.IsAssignableFrom <CustomTypeDescriptor>(provider.GetTypeDescriptor(objectType, instance));

            Assert.Empty(result1.GetProperties());

            // Call again.
            CustomTypeDescriptor result2 = Assert.IsAssignableFrom <CustomTypeDescriptor>(provider.GetTypeDescriptor(objectType, instance));

            Assert.Same(result1, result2);
        }