Ejemplo n.º 1
0
        public void CreateType(Type instanceType, Type baseType)
        {
            // Arrange
            Func <object> instanceDelegate = TypeActivator.Create(instanceType);

            // Act
            object instance = instanceDelegate();

            // Assert
            Assert.IsType(instanceType, instance);
        }
Ejemplo n.º 2
0
        public void CreateOfTInvalid()
        {
            // string doesn't have a default ctor
            Assert.ThrowsArgument(() => TypeActivator.Create <string>(), paramName: null);

            // Uri doesn't have a default ctor
            Assert.ThrowsArgument(() => TypeActivator.Create <Uri>(), paramName: null);

            // HttpContent is abstract
            Assert.Throws <InvalidOperationException>(() => TypeActivator.Create <HttpContent>());

            // HttpActionDescriptor is abstract
            Assert.Throws <InvalidOperationException>(() => TypeActivator.Create <HttpActionDescriptor>());
        }
Ejemplo n.º 3
0
        public void CreateOfTBaseInvalid()
        {
            // int not being a ref type
            Assert.ThrowsArgument(() => TypeActivator.Create <object>(typeof(int)), paramName: null);

            // GUID is not a ref type
            Assert.ThrowsArgument(() => TypeActivator.Create <object>(typeof(Guid)), paramName: null);

            // HttpStatusCode is not a ref type
            Assert.ThrowsArgument(() => TypeActivator.Create <object>(typeof(HttpStatusCode)), paramName: null);

            // string does not have a default ctor
            Assert.ThrowsArgument(() => TypeActivator.Create <string>(typeof(string)), paramName: null);

            // ObjectContent does not have a default ctor
            Assert.ThrowsArgument(() => TypeActivator.Create <HttpContent>(typeof(ObjectContent)), paramName: null);

            // Base type and instance type flipped
            Assert.ThrowsArgument(() => TypeActivator.Create <ReflectedHttpActionDescriptor>(typeof(HttpActionDescriptor)), paramName: null);
        }
Ejemplo n.º 4
0
 public void CreateTypeInvalidThrowsInvalidOperation(Type type)
 {
     // Abstract types cause InvalidOperationException
     Assert.Throws <InvalidOperationException>(() => TypeActivator.Create(type));
 }
Ejemplo n.º 5
0
 public void CreateTypeInvalidThrowsInvalidArgument(Type type)
 {
     // Value types, interfaces, and open generics cause ArgumentException
     Assert.ThrowsArgument(() => TypeActivator.Create(type), paramName: null);
 }