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); }
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")); }
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(); }
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 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); }