コード例 #1
0
        public void ClearDiagnosticMessagesShouldClearMessagesFromWriteLine()
        {
            var stringWriter = new ThreadSafeStringWriter(null, "test");

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties);

            this.testContextImplementation.WriteLine("1 Testing write");
            this.testContextImplementation.WriteLine("2 Its a happy day");

            this.testContextImplementation.ClearDiagnosticMessages();

            Assert.AreEqual(string.Empty, stringWriter.ToString());
        }
コード例 #2
0
        public void WriteLineWithMessageShouldNotThrowIfStringWriterIsDisposed()
        {
            var stringWriter = new ThreadSafeStringWriter(null, "test");

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties);

            stringWriter.Dispose();

            this.testContextImplementation.WriteLine("1 Testing write");

            // Calling it twice to cover the direct return when we know the object has been disposed.
            this.testContextImplementation.WriteLine("1 Testing write");
        }
コード例 #3
0
        public void PropertiesShouldReturnPropertiesPassedToTestContext()
        {
            var property1 = new KeyValuePair <string, object>("IntProperty", 1);
            var property2 = new KeyValuePair <string, object>("DoubleProperty", 2.023);

            this.properties.Add(property1);
            this.properties.Add(property2);

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new ThreadSafeStringWriter(null, "test"), this.properties);

            CollectionAssert.Contains(this.testContextImplementation.Properties, property1);
            CollectionAssert.Contains(this.testContextImplementation.Properties, property2);
        }
コード例 #4
0
        public void GetResultFilesShouldReturnListOfAddedResultFiles()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new ThreadSafeStringWriter(null, "test"), this.properties);

            this.testContextImplementation.AddResultFile("C:\\files\\myfile.txt");
            this.testContextImplementation.AddResultFile("C:\\files\\myfile2.txt");

            var resultFiles = this.testContextImplementation.GetResultFiles();

            Assert.IsTrue(resultFiles.Count > 0, "GetResultFiles returned added elements");
            CollectionAssert.Contains(resultFiles.ToList(), "C:\\files\\myfile.txt");
            CollectionAssert.Contains(resultFiles.ToList(), "C:\\files\\myfile2.txt");
        }
コード例 #5
0
        public TestMethodRunnerTests()
        {
            var constructorInfo = typeof(DummyTestClass).GetConstructors().Single();

            this.methodInfo = typeof(DummyTestClass).GetMethods().Single(m => m.Name.Equals("DummyTestMethod"));
            var classAttribute = new UTF.TestClassAttribute();

            this.testMethodAttribute = new UTF.TestMethodAttribute();
            var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext");

            var testAssemblyInfo = new TestAssemblyInfo();

            this.testMethod = new TestMethod("dummyTestName", "dummyClassName", "dummyAssemblyName", false);
            this.testContextImplementation = new TestContextImplementation(this.testMethod, null, new Dictionary <string, object>());
            this.testClassInfo             = new TestClassInfo(
                type: typeof(DummyTestClass),
                constructor: constructorInfo,
                testContextProperty: testContextProperty,
                classAttribute: classAttribute,
                parent: testAssemblyInfo);

            this.globaltestMethodOptions = new TestMethodOptions()
            {
                Timeout           = 3600 * 1000,
                Executor          = this.testMethodAttribute,
                TestContext       = this.testContextImplementation,
                ExpectedException = null
            };
            var globalTestMethodInfo = new TestMethodInfo(
                this.methodInfo,
                this.testClassInfo,
                this.globaltestMethodOptions);

            this.globalTestMethodRunner = new TestMethodRunner(globalTestMethodInfo, this.testMethod, this.testContextImplementation, false);

            this.testMethodOptions = new TestMethodOptions()
            {
                Timeout           = 200,
                Executor          = this.testMethodAttribute,
                TestContext       = this.testContextImplementation,
                ExpectedException = null
            };

            // Reset test hooks
            DummyTestClass.TestConstructorMethodBody = () => { };
            DummyTestClass.TestContextSetterBody     = value => { };
            DummyTestClass.TestInitializeMethodBody  = value => { };
            DummyTestClass.TestMethodBody            = instance => { };
            DummyTestClass.TestCleanupMethodBody     = value => { };
        }
コード例 #6
0
        public void SetDataConnectionShouldSetDbConnectionForFetchingData()
        {
            var stringWriter = new StringWriter();

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties);

            DbProviderFactory factory    = DbProviderFactories.GetFactory("System.Data.Odbc");
            DbConnection      connection = factory.CreateConnection();

            connection.ConnectionString = @"Dsn=Excel Files;dbq=.\data.xls;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5";

            this.testContextImplementation.SetDataConnection(connection);

            Assert.AreEqual("Dsn=Excel Files;dbq=.\\data.xls;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5", this.testContextImplementation.DataConnection.ConnectionString);
        }
コード例 #7
0
        public void TestContextConstructorShouldInitializeDefaultProperties()
        {
            this.testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
            this.testMethod.Setup(tm => tm.Name).Returns("M");

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            Assert.IsNotNull(this.testContextImplementation.Properties);

            CollectionAssert.Contains(
                this.testContextImplementation.Properties,
                new KeyValuePair <string, object>("FullyQualifiedTestClassName", "A.C.M"));
            CollectionAssert.Contains(
                this.testContextImplementation.Properties,
                new KeyValuePair <string, object>("TestName", "M"));
        }
コード例 #8
0
        public void RunDataDrivenTestsShouldAttachResultsFilesForEachTestCase()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new TestFrameworkV2.DataSourceAttribute(
                "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential);

            this.mockTestMethodInfo.Setup(ds => ds.GetAttributes <TestFrameworkV2.DataSourceAttribute>(false))
            .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute });

            TestFrameworkV2.TestResult testResult = new TestFrameworkV2.TestResult();

            DummyTestClass testClassInstance = new DummyTestClass();
            var            methodInfo        = typeof(DummyTestClass).GetMethod("PassingTest");

            this.mockTestMethodInfo.Setup(ds => ds.Invoke(null)).
            Callback(() =>
            {
                try
                {
                    testClassInstance.TestContext = this.testContextImplementation;

                    var task = methodInfo.Invoke(testClassInstance, null) as Task;
                    task?.GetAwaiter().GetResult();

                    testResult.Outcome     = TestFrameworkV2.UnitTestOutcome.Passed;
                    testResult.ResultFiles = this.testContextImplementation.GetResultFiles();
                }
                catch (Exception ex)
                {
                    testResult.Outcome = TestFrameworkV2.UnitTestOutcome.Failed;
                    testResult.TestFailureException = ex;
                }
            }).Returns(testResult);
            this.mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo);

            TestFrameworkV2.TestMethodAttribute testMethodAttribute = new TestFrameworkV2.TestMethodAttribute();
            TestDataSource testDataSource = new TestDataSource();

            TestFrameworkV2.TestResult[] result = testDataSource.RunDataDrivenTest(this.testContextImplementation, this.mockTestMethodInfo.Object, null, testMethodAttribute);
            CollectionAssert.Contains(result[0].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(result[1].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(result[2].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(result[3].ResultFiles.ToList(), "C:\\temp.txt");
        }
コード例 #9
0
        public void SetDataRowShouldSetDataRowObjectForCurrentRun()
        {
            var stringWriter = new StringWriter();

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties);

            DataTable dataTable = new DataTable();

            // create the table with the appropriate column names
            dataTable.Columns.Add("Id", typeof(int));
            dataTable.Columns.Add("Name", typeof(string));

            dataTable.LoadDataRow(new object[] { 2, "Hello" }, true);

            this.testContextImplementation.SetDataRow(dataTable.Select()[0]);

            Assert.AreEqual(2, this.testContextImplementation.DataRow.ItemArray[0]);
            Assert.AreEqual("Hello", this.testContextImplementation.DataRow.ItemArray[1]);
        }
コード例 #10
0
        public void CurrentTestOutcomeShouldReturnDefaultOutcome()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            Assert.AreEqual(UnitTestOutcome.Failed, this.testContextImplementation.CurrentTestOutcome);
        }
コード例 #11
0
        public void TestContextConstructorShouldInitializeProperties()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            Assert.IsNotNull(this.testContextImplementation.Properties);
        }
コード例 #12
0
 public void TryGetPropertyValueShouldReturnFalseIfPropertyIsNotPresent()
 {
     this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
     Assert.IsFalse(this.testContextImplementation.TryGetPropertyValue("Random", out object propValue));
     Assert.IsNull(propValue);
 }
コード例 #13
0
 internal TestableTestmethodInfo(MethodInfo testMethod, int timeout, UTF.TestMethodAttribute executor, TestClassInfo parent, TestContextImplementation testContext, Func <UTF.TestResult> invoke)
     : base(testMethod, timeout, executor, null, parent, testContext)
 {
     this.invokeTest = invoke;
 }