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);
        }
Exemplo n.º 2
0
        private void AddTestSuiteToProject(TestSuite testSuite, Project testProject)
        {
            var unitTestsWriter = new NUnitUnitTestCodeWriter();
            var testSuiteGenerator = new TestSuiteGenerator(testSuite, unitTestsWriter, testProject.Name, "[TestFixture]");

            var testSuiteFilePath =
                Path.Combine(
            new string[]{
                testProject.FullName.Substring(0, testProject.FullName.LastIndexOf('\\')),
                                               testSuite.Type.FullName + ".Tests.cs"
            }
            );
            var file = File.Create(testSuiteFilePath);
            var streamWriter = new StreamWriter(file);
            streamWriter.Write(testSuiteGenerator.TransformText());
            streamWriter.Close();
            file.Close();

            var item =testProject.ProjectItems.AddFromFile(testSuiteFilePath);
            item.Open(Constants.vsViewKindCode);
            item.Document.Activate();
        }
        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);
        }