コード例 #1
1
 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);
 }
コード例 #2
0
        public void StringTest()
        {
            var cTest = new ConstructorTest(new TimeSpan(), typeof(String).GetConstructor(new Type[] { typeof(Char), typeof(Int32) }), new String('C', 5),
                    new List<ObjectInstance>(){new ObjectInstance('C'), new ObjectInstance(5)});

                Assert.That(cTest.Result, Is.EqualTo("CCCCC"));
        }
コード例 #3
0
        private String GetConstructorTestCode(ConstructorTest constructorTest)
        {
            StringBuilder testCode = new StringBuilder();
            testCode.Append(TestSuiteGenerator.INDENT);
            testCode.AppendLine(CodeWritingUtils.GetVariableInstantiationStatement(constructorTest.Method as ConstructorInfo, constructorTest.Arguments, INSTANCE_NAME));
            testCode.Append(TestSuiteGenerator.INDENT);

            if(constructorTest.Result == null)
            {
                testCode.AppendFormat("Assert.That({0}, Is.Null);", INSTANCE_NAME);
                testCode.AppendLine();
            }
            else
            {
                testCode.AppendFormat("Assert.That({0}, Is.Not.Null);", INSTANCE_NAME);
                testCode.AppendLine();

                String propTestCode = GetPublicFieldsAndPropertiesTestCode(constructorTest.Result);
                if (propTestCode != String.Empty)
                {
                    testCode.Append(TestSuiteGenerator.INDENT);
                    testCode.AppendLine(propTestCode.Replace("\r\n", "\r\n" + TestSuiteGenerator.INDENT));
                }
            }

            return testCode.ToString();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }