public void Init()
 {
     m_PropInstance = new PropertiesTestType();
     m_DefaultConstructor = m_TypeUnderTest.GetConstructor(Type.EmptyTypes);
     m_PropInstanceMeta  = new ObjectInstance(m_PropInstance, new ObjectCreationData(m_DefaultConstructor));
     m_ConstructorTest = new ConstructorTest(TimeSpan.FromMilliseconds(1), m_DefaultConstructor, m_PropInstance);
 }
Exemple #2
0
        public void Init()
        {
            m_Str = new String('C', 5);

             m_StringInstance = new ObjectInstance(m_Str);
             m_CopyTo = m_StrType.GetMethod("CopyTo", new Type[] { typeof(int), typeof(char[]), typeof(int), typeof(int) });
        }
 public void NullInstanceTest()
 {
     Assert.Throws<ArgumentNullException>(() =>
         {
             var objInstance = new ObjectInstance(null);
         });
 }
        public void InstanceThatNeedsConstructorMustHaveCreationDataTest()
        {
            List<String> testList = new List<string>();

               Assert.Throws<ArgumentException>(()=>{
               var strInstance = new ObjectInstance(testList);
               }
               );
        }
        public void StringTest()
        {
            Type stringType = typeof(String);
            var constructor = stringType.GetConstructor(new Type[]{typeof(char), typeof(Int32)});
            var c = new ObjectInstance('I');
            var i = new ObjectInstance(32);

            var objCreationData = new ObjectCreationData(constructor, new List<ObjectInstance>(){c, i});
            Assert.That(objCreationData.HasArguments, Is.True);
            Assert.That(objCreationData.Arguments.Count, Is.EqualTo(2));
            Assert.That(objCreationData.Constructor, Is.EqualTo(constructor));
        }
        public void ArgumentsMatchParametersTest()
        {
            Type stringType = typeof(String);
            var constructor = stringType.GetConstructor(new Type[] { typeof(char), typeof(Int32) });
            var c = new ObjectInstance('I');
            var i = new ObjectInstance(32);

            Assert.DoesNotThrow(() =>
            {
                ObjectCreationData objCreationData = new ObjectCreationData(constructor, new List<ObjectInstance>() { c, i });
            });
        }
        public void NonPrimitiveInstanceTest()
        {
            List<String> testList = new List<String>();
            Type listType = testList.GetType();

            var creationData = new ObjectCreationData(listType.GetConstructor(Type.EmptyTypes));

            var objInstance = new ObjectInstance(testList, creationData);
            Assert.That(objInstance.Instance, Is.SameAs(testList));
            Assert.That(objInstance.InstanceNeedsConstructor, Is.True);
            Assert.That(objInstance.CreationData, Is.SameAs(creationData));
        }
        public void InstanceThatDoesntNeedConstructorMustNotHaveCreationDataTest()
        {
            var creationData = new ObjectCreationData(typeof(String).GetConstructor(new Type[] { typeof(Char), typeof(Int32) }),
                new List<ObjectInstance>() { new ObjectInstance('T'), new ObjectInstance(5) });

            Assert.Throws<ArgumentException>(() =>
            {
                var objInstance = new ObjectInstance('c', creationData);
            }

                );
        }
        public void ConstructorMustMatchInstanceTest()
        {
            List<String> testList = new List<string>();
            Type t = typeof(ArgumentException);

            var creationData = new ObjectCreationData(t.GetConstructor(Type.EmptyTypes));

            Assert.Throws<ArgumentException>(() =>
            {
                var objInstance = new ObjectInstance(testList, creationData);
            });
        }
        public void ToStringTest()
        {
            Type stringType = typeof(String);
            var constructor = stringType.GetConstructor(new Type[] { typeof(char), typeof(Int32) });
            var c = new ObjectInstance('I');
            var i = new ObjectInstance(32);

            var objCreationData = new ObjectCreationData(constructor, new List<ObjectInstance>() { c, i });

            var s = new StringBuilder(objCreationData.Constructor.ToString() + " ");

            objCreationData.Arguments.ForEach(a => { s.Append(a); s.Append(" "); });

            Assert.That(s.ToString() == objCreationData.ToString());
        }
        public void Setup()
        {
            m_OtherTestClassInstance = new ObjectInstance(new OtherTestClass(), new ObjectCreationData(typeof(OtherTestClass).GetConstructor(Type.EmptyTypes)));
            m_TestCodeWriter = new NUnitUnitTestCodeWriter();
            m_TestType = typeof(ConstructorTestsType);
            m_TestTypeIntsConstructor = m_TestType.GetConstructor(new[] {typeof(int), typeof(int)});

            m_TestTypeComplexConstructor = m_TestType.GetConstructor(new[] {typeof(OtherTestClass)});

            List<ObjectInstance> intArgs = new List<ObjectInstance>(){new ObjectInstance(1), new ObjectInstance(2)};
            m_TestTypeInstance = new ObjectInstance(new ConstructorTestsType(1, 2),
                                                    new ObjectCreationData(m_TestTypeIntsConstructor, intArgs));

            m_TestTypeComplexInstance = new ObjectInstance(new ConstructorTestsType(new OtherTestClass()), new ObjectCreationData(m_TestTypeComplexConstructor, new []{m_OtherTestClassInstance}));

            List<ObjectInstance> complexArgs = new List<ObjectInstance> { new ObjectInstance(new OtherTestClass(), new ObjectCreationData(typeof(OtherTestClass).GetConstructor(Type.EmptyTypes))) };

            m_IntsConstructorTest = new ConstructorTest(TimeSpan.FromMilliseconds(1), m_TestTypeIntsConstructor, m_TestTypeInstance.Instance, intArgs);

            m_ComplexConstructorTest = new ConstructorTest(TimeSpan.FromMilliseconds(2), m_TestTypeComplexConstructor, m_TestTypeComplexInstance.Instance, complexArgs);

            List<ObjectInstance> moreComplexArgs = new List<ObjectInstance> { new ObjectInstance(new OtherTestClass(), new ObjectCreationData(typeof(OtherTestClass).GetConstructor(new []{typeof(Int32), typeof(Int32)}), intArgs)) };
            m_MoreComplexConstructorTest = new ConstructorTest(TimeSpan.FromMilliseconds(1), m_TestTypeComplexConstructor, m_TestTypeComplexInstance.Instance, moreComplexArgs);
        }
        public void Setup()
        {
            m_TestCodeWriter = new NUnitUnitTestCodeWriter();
            m_TypeUnderTest = typeof(MethodTestsType);
            m_SimpleMethod = m_TypeUnderTest.GetMethod("SimpleMethod");
            m_IntReturningMethod = m_TypeUnderTest.GetMethod("IntReturningMethod");
            m_MethodTakingAnInt = m_TypeUnderTest.GetMethod("MethodTakingAnInt");
            m_MethodTakingAComplexType = m_TypeUnderTest.GetMethod("MethodTakingAComplexType");
            m_MethodReturningAComplexType = m_TypeUnderTest.GetMethod("MethodReturningAComplexType");
            m_MethodReturningNull = m_TypeUnderTest.GetMethod("MethodReturningNull");
            m_MethodCalledWithNull = m_TypeUnderTest.GetMethod("MethodCalledWithNull");

            m_TargetInstanceMeta = new ObjectInstance(m_TargetInstance, new ObjectCreationData(m_TypeUnderTest.GetConstructor(Type.EmptyTypes)));
            m_OtherTypeMeta = new ObjectInstance(m_OtherType, new ObjectCreationData(typeof(OtherType).GetConstructor(Type.EmptyTypes)));
            m_IntMeta = new ObjectInstance(1);

            m_SimpleMethodTest = new MethodTest(TimeSpan.FromMilliseconds(1), m_SimpleMethod, instance: m_TargetInstanceMeta);

            m_IntReturningMethodTest = new MethodTest(TimeSpan.FromMilliseconds(1), m_IntReturningMethod, 3, instance: m_TargetInstanceMeta);
            m_MethodTakingAnIntTest = new MethodTest(TimeSpan.FromMilliseconds(1), m_MethodTakingAnInt, null, new[]{m_IntMeta}, m_TargetInstanceMeta);

            m_MethodTakingAComplexTypeTest = new MethodTest(TimeSpan.FromMilliseconds(1), m_MethodTakingAComplexType, null, new[] { m_OtherTypeMeta }, m_TargetInstanceMeta);
            m_MethodReturningAComplexTypeTest = new MethodTest(TimeSpan.FromMilliseconds(1), m_MethodReturningAComplexType, m_OtherType, instance: m_TargetInstanceMeta);

            m_MethodReturningNullTest = new MethodTest(TimeSpan.FromMilliseconds(1), m_MethodReturningNull, null, instance:m_TargetInstanceMeta);
        }
        public void Setup()
        {
            m_TestCodeWriter = new NUnitUnitTestCodeWriter();
            m_TestType = typeof(BasicTestType);
            m_TestTypeDefaultConstructor = m_TestType.GetConstructor(Type.EmptyTypes);
            m_TestTypeInstance = new ObjectInstance(new BasicTestType(), new ObjectCreationData(m_TestTypeDefaultConstructor));
            m_ExceptionThrowingTest = new ExceptionThrowingTest(TimeSpan.FromMilliseconds(1), m_TestType.GetMethod("ExceptionThrower"), new ArgumentOutOfRangeException(), m_TestTypeInstance);

            m_ConstructorTest = new ConstructorTest(TimeSpan.FromMilliseconds(1), m_TestTypeDefaultConstructor, new BasicTestType());

            m_MethodTest = new MethodTest(TimeSpan.FromMilliseconds(1), m_TestType.GetMethod("Method1"), 5, instance:m_TestTypeInstance);
        }
 public void ToStringTest()
 {
     var testInstance = new ObjectInstance(12);
     Assert.That(testInstance.ToString() == "12");
 }
 public void PrimitiveInstanceTest()
 {
     var objInstance = new ObjectInstance('T');
     Assert.That(objInstance.Instance, Is.EqualTo('T'));
     Assert.That(objInstance.InstanceNeedsConstructor, Is.False);
     Assert.That(objInstance.CreationData, Is.Null);
 }