Exemplo n.º 1
0
        public void TypeConstraintsTest()
        {
            object objWrapper      = new ObjectWrapper(10);
            object objWrapperChild = new ObjectWrapperChild(20);

            Assert.That(10, Is.InstanceOf(typeof(int)), "10 is int type");
            Assert.That(objWrapper, Is.InstanceOf(typeof(object)), "Object wrapper is object type");
            Assert.That(objWrapper, Is.InstanceOf(typeof(ObjectWrapper)), "Object wrapper is ObjectWrapper type");
            Assert.That(objWrapperChild, Is.InstanceOf(typeof(ObjectWrapper)), "Object wrapper child is ObjectWrapper type");
            Assert.That(objWrapperChild, Is.InstanceOf(typeof(ObjectWrapperChild)), "Object wrapper child is ObjectWrapperChild type");

            Assert.That(10, Is.InstanceOf <int>(), "10 is int type");
            Assert.That(objWrapper, Is.InstanceOf <object>(), "Object wrapper is object type");
            Assert.That(objWrapper, Is.InstanceOf <ObjectWrapper>(), "Object wrapper is ObjectWrapper type");
            Assert.That(objWrapperChild, Is.InstanceOf <ObjectWrapper>(), "Object wrapper child is ObjectWrapper type");
            Assert.That(objWrapperChild, Is.InstanceOf <ObjectWrapperChild>(), "Object wrapper child is ObjectWrapperChild type");

            Assert.That(10, Is.Not.InstanceOf(typeof(string)), "10 is not string type");
            Assert.That(objWrapper, Is.Not.InstanceOf(typeof(string)), "Object wrapper is not string type");
            Assert.That(objWrapper, Is.Not.InstanceOf(typeof(ObjectWrapperChild)), "Object wrapper is not ObjectWrapperChild type");

            Assert.That(10, Is.Not.InstanceOf <string>(), "10 is not string type");
            Assert.That(objWrapper, Is.Not.InstanceOf <string>(), "Object wrapper is not string type");
            Assert.That(objWrapper, Is.Not.InstanceOf <ObjectWrapperChild>(), "Object wrapper is not ObjectWrapperChild type");

            Assert.That(10, Is.AssignableFrom(typeof(int)), "10 can be assignable from int type");
            Assert.That(objWrapper, Is.AssignableFrom(typeof(ObjectWrapper)), "Object wrapper can be assignable from ObjectWrapper type");
            Assert.That(objWrapper, Is.AssignableFrom(typeof(ObjectWrapperChild)), "Object wrapper child can be assignable from ObjectWrapper type");
            Assert.That(objWrapperChild, Is.AssignableFrom(typeof(ObjectWrapperChild)), "Object wrapper child can be assignable from ObjectWrapperChild type");

            Assert.That(10, Is.AssignableFrom <int>(), "10 can be assignable from int type");
            Assert.That(objWrapper, Is.AssignableFrom <ObjectWrapper>(), "Object wrapper can be assignable from ObjectWrapper type");
            Assert.That(objWrapper, Is.AssignableFrom <ObjectWrapperChild>(), "Object wrapper child can be assignable from ObjectWrapper type");
            Assert.That(objWrapperChild, Is.AssignableFrom <ObjectWrapperChild>(), "Object wrapper child can be assignable from ObjectWrapperChild type");

            Assert.That(10, Is.Not.AssignableFrom(typeof(string)), "10 can not be assignable from string type");
            Assert.That(objWrapper, Is.Not.AssignableFrom(typeof(object)), "Object wrapper can not be assignable from object type");
            Assert.That(objWrapperChild, Is.Not.AssignableFrom(typeof(ObjectWrapper)), "Object wrapper child can not be assignable from ObjectWrapper type");

            Assert.That(10, Is.Not.AssignableFrom <string>(), "10 can not be assignable from string type");
            Assert.That(objWrapper, Is.Not.AssignableFrom <object>(), "Object wrapper can not be assignable from object type");
            Assert.That(objWrapperChild, Is.Not.AssignableFrom <ObjectWrapper>(), "Object wrapper child can not be assignable from ObjectWrapper type");
        }
Exemplo n.º 2
0
        public void TypeAssertsTest()
        {
            object objWrapper      = new ObjectWrapper(10);
            object objWrapperChild = new ObjectWrapperChild(20);

            Assert.IsInstanceOf(typeof(int), 10, "10 is int type");
            Assert.IsInstanceOf(typeof(object), objWrapper, "Object wrapper is object type");
            Assert.IsInstanceOf(typeof(ObjectWrapper), objWrapper, "Object wrapper is ObjectWrapper type");
            Assert.IsInstanceOf(typeof(ObjectWrapper), objWrapperChild, "Object wrapper child is ObjectWrapper type");
            Assert.IsInstanceOf(typeof(ObjectWrapperChild), objWrapperChild, "Object wrapper child is ObjectWrapperChild type");

            Assert.IsInstanceOf <int>(10, "10 is int type");
            Assert.IsInstanceOf <object>(objWrapper, "Object wrapper is object type");
            Assert.IsInstanceOf <ObjectWrapper>(objWrapper, "Object wrapper is ObjectWrapper type");
            Assert.IsInstanceOf <ObjectWrapper>(objWrapperChild, "Object wrapper child is ObjectWrapper type");
            Assert.IsInstanceOf <ObjectWrapperChild>(objWrapperChild, "Object wrapper child is ObjectWrapperChild type");

            Assert.IsNotInstanceOf(typeof(string), 10, "10 is not string type");
            Assert.IsNotInstanceOf(typeof(string), objWrapper, "Object wrapper is not string type");
            Assert.IsNotInstanceOf(typeof(ObjectWrapperChild), objWrapper, "Object wrapper is not ObjectWrapperChild type");

            Assert.IsNotInstanceOf <string>(10, "10 is not string type");
            Assert.IsNotInstanceOf <string>(objWrapper, "Object wrapper is not string type");
            Assert.IsNotInstanceOf <ObjectWrapperChild>(objWrapper, "Object wrapper is not ObjectWrapperChild type");

            Assert.IsAssignableFrom(typeof(int), 10, "10 can be assignable from int type");
            Assert.IsAssignableFrom(typeof(ObjectWrapper), objWrapper, "Object wrapper can be assignable from ObjectWrapper type");
            Assert.IsAssignableFrom(typeof(ObjectWrapperChild), objWrapper, "Object wrapper child can be assignable from ObjectWrapper type");
            Assert.IsAssignableFrom(typeof(ObjectWrapperChild), objWrapperChild, "Object wrapper child can be assignable from ObjectWrapperChild type");

            Assert.IsAssignableFrom <int>(10, "10 can be assignable from int type");
            Assert.IsAssignableFrom <ObjectWrapper>(objWrapper, "Object wrapper can be assignable from ObjectWrapper type");
            Assert.IsAssignableFrom <ObjectWrapperChild>(objWrapper, "Object wrapper child can be assignable from ObjectWrapper type");
            Assert.IsAssignableFrom <ObjectWrapperChild>(objWrapperChild, "Object wrapper child can be assignable from ObjectWrapperChild type");

            Assert.IsNotAssignableFrom(typeof(string), 10, "10 can not be assignable from string type");
            Assert.IsNotAssignableFrom(typeof(object), objWrapper, "Object wrapper can not be assignable from object type");
            Assert.IsNotAssignableFrom(typeof(ObjectWrapper), objWrapperChild, "Object wrapper child can not be assignable from ObjectWrapper type");

            Assert.IsNotAssignableFrom <string>(10, "10 can not be assignable from string type");
            Assert.IsNotAssignableFrom <object>(objWrapper, "Object wrapper can not be assignable from object type");
            Assert.IsNotAssignableFrom <ObjectWrapper>(objWrapperChild, "Object wrapper child can not be assignable from ObjectWrapper type");
        }