public override void AssemblyStart(TestAssembly testAssembly)
 {
     Console.WriteLine(
         "##teamcity[testSuiteStarted name='{0}']",
         Escape(Path.GetFileName(testAssembly.AssemblyFilename))
     );
 }
        public IList<RunData> Create(TestAssembly assembly)
        {
            IList<RunData> items = new List<RunData>();
            assembly.Fixtures = assembly.Fixtures.OrderBy((m) => m.Name).ToList();
            string lastFixtureName = "#";
            RunData item = null;
            foreach (TestFixture fixture in assembly.Fixtures)
            {
                if (fixture.Name.StartsWith(lastFixtureName))
                {
                    item.Groups.Add(fixture.Group);
                    item.Fixtures.Add(fixture);
                    if (fixture.Exclusive == true)
                    {
                        item.Exclusive = true;
                    }

                    continue;
                }

                item = CreateNewFromFixture(assembly, fixture);
                lastFixtureName = fixture.Name;
                items.Add(item);
            }

            return items;
        }
示例#3
0
 public virtual void AssemblyFinished(TestAssembly testAssembly, int total, int failed, int skipped, double time)
 {
     TotalTests = total;
     TotalFailures = failed;
     TotalSkips = skipped;
     TotalTime = time;
 }
        public override void AssemblyFinished(TestAssembly testAssembly, int total, int failed, int skipped, double time)
        {
            base.AssemblyFinished(testAssembly, total, failed, skipped, time);

            if (!silent)
                Console.Write("\r");

            Console.WriteLine("{0} total, {1} failed, {2} skipped, took {3} seconds", total, failed, skipped, time.ToString("0.000", CultureInfo.InvariantCulture));
        }
        public override void AssemblyFinished(TestAssembly testAssembly, int total, int failed, int skipped, double time)
        {
            base.AssemblyFinished(testAssembly, total, failed, skipped, time);

            Console.WriteLine(
                "##teamcity[testSuiteFinished name='{0}']",
                Escape(Path.GetFileName(testAssembly.AssemblyFilename))
            );
        }
示例#6
0
        public void SetsTestAssemblyOnTestClasses()
        {
            StubExecutorWrapper wrapper = new StubExecutorWrapper();
            TestClass testClass = new TestClass("typeName", new TestMethod[0]);

            var assembly = new TestAssembly(wrapper, new[] { testClass });

            Assert.Same(assembly, testClass.TestAssembly);
        }
示例#7
0
        public void DisposingAssemblyDisposesExecutorWrapper()
        {
            StubExecutorWrapper wrapper = new StubExecutorWrapper();
            var assembly = new TestAssembly(wrapper, new TestClass[0]);

            assembly.Dispose();

            Assert.True(wrapper.Dispose__Called);
        }
示例#8
0
 public virtual void ExceptionThrown(TestAssembly testAssembly, Exception exception)
 {
     Console.WriteLine();
     Console.WriteLine("CATASTROPHIC ERROR OCCURRED:");
     Console.WriteLine(exception.ToString());
     Console.WriteLine("WHILE RUNNING:");
     Console.WriteLine(testAssembly.AssemblyFilename);
     Console.WriteLine();
 }
 public SpecThisTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null)
     : base(assemblyInfo, sourceProvider, diagnosticMessageSink)
 {
     IAttributeInfo collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault<IAttributeInfo>();
     bool flag = collectionBehaviorAttribute != null && collectionBehaviorAttribute.GetNamedArgument<bool>("DisableTestParallelization");
     string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
     TestAssembly testAssembly = new TestAssembly(assemblyInfo, configurationFile);
     this.TestCollectionFactory = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, (ITestAssembly)testAssembly);
     this.TestFrameworkDisplayName = string.Format("{0} [{1}, {2}]", XunitTestFrameworkDiscoverer.DisplayName, this.TestCollectionFactory.DisplayName, flag ? "non-parallel" : "parallel");
 }
示例#10
0
        public void FilterWithFalsePredicate()
        {
            var wrapper = new StubExecutorWrapper();
            var class1Method1 = new TestMethod("method1", null, null);
            var class1Method2 = new TestMethod("method2", null, null);
            var class2Method3 = new TestMethod("method3", null, null);
            var class1 = new TestClass("foo", new[] { class1Method1, class1Method2 });
            var class2 = new TestClass("bar", new[] { class2Method3 });
            var assembly = new TestAssembly(wrapper, new[] { class1, class2 });

            var tests = assembly.EnumerateTestMethods(testMethod => false);

            Assert.Equal(0, tests.Count());
        }
示例#11
0
    public void GetFileInfo_EscapingFromTheRootFolder_ReturnsNotFound()
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js"),
                                                    TestEntry.File("jquery.min.js"),
                                                    TestEntry.File("site.css"))));

        // Act
        var provider = new ManifestEmbeddedFileProvider(assembly);

        // Assert
        var jqueryValidate = provider.GetFileInfo(Path.Combine("..", "wwwroot", "jquery.validate.js"));

        Assert.IsType <NotFoundFileInfo>(jqueryValidate);
    }
示例#12
0
        void AddTestAssembly(TestAssembly testAssembly)
        {
            ListViewItem lviAssembly = new ListViewItem
            {
                Text        = Path.GetFileNameWithoutExtension(testAssembly.AssemblyFilename),
                ToolTipText = testAssembly.AssemblyFilename + Environment.NewLine +
                              "xunit.dll verison " + testAssembly.XunitVersion,
                Tag = testAssembly
            };

            AddFileWatcher(testAssembly);
            listAssemblies.Items.Add(lviAssembly);

            UpdateAssemblyFilter();
            UpdateTraitsList();
            UpdateTestList();
            UpdateAssemblyDynamicMenus();
        }
示例#13
0
    public void GetFileInfo_ResolveNonExistingFile_ReturnsNotFoundFileInfo()
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js"),
                                                    TestEntry.File("jquery.min.js"),
                                                    TestEntry.File("site.css"))));

        var provider = new ManifestEmbeddedFileProvider(assembly);

        // Act
        var file = provider.GetFileInfo("some/non/existing/file.txt");

        // Assert
        Assert.IsType <NotFoundFileInfo>(file);
    }
示例#14
0
    public void ScopedFileProvider_DoesNotReturnFilesOutOfScope(string path)
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js")),
                                TestEntry.File("site.css")));

        var provider       = new ManifestEmbeddedFileProvider(assembly);
        var scopedProvider = new ManifestEmbeddedFileProvider(assembly, provider.Manifest.Scope("wwwroot"), DateTimeOffset.UtcNow);

        // Act
        var jqueryValidate = scopedProvider.GetFileInfo(path);

        // Assert
        Assert.IsType <NotFoundFileInfo>(jqueryValidate);
    }
示例#15
0
        public void ResolveAssemblies_ThrowsIfRelatedAssemblyDefinesAdditionalRelatedAssemblies()
        {
            // Arrange
            var expected  = $"Assembly 'TestRelatedAssembly' declared as a related assembly by assembly '{ThisAssembly}' cannot define additional related assemblies.";
            var assembly1 = typeof(ApplicationAssembliesProvider).Assembly;
            var assembly2 = new TestAssembly();

            var relatedAssemblies = new[] { assembly1, assembly2 };
            var provider          = new TestApplicationAssembliesProvider
            {
                GetRelatedAssembliesDelegate = (assembly) => relatedAssemblies,
            };

            // Act & Assert
            var ex = Assert.Throws <InvalidOperationException>(() => provider.ResolveAssemblies(ThisAssembly).ToArray());

            Assert.Equal(expected, ex.Message);
        }
示例#16
0
    public void GetDirectoryContents_ReturnsNotFoundDirectoryContents_ForPathsWithInvalidCharacters(string path)
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js"),
                                                    TestEntry.File("jquery.min.js"),
                                                    TestEntry.File("site.css"))));

        // Act
        var provider = new ManifestEmbeddedFileProvider(assembly);

        // Assert
        var directory = provider.GetDirectoryContents(path);

        Assert.IsType <NotFoundDirectoryContents>(directory);
    }
示例#17
0
        public void GetRelatedAssemblies_LoadsRelatedAssembly()
        {
            // Arrange
            var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
            var assembly    = new TestAssembly
            {
                AttributeAssembly = "RelatedAssembly",
            };
            var relatedAssembly = typeof(RelatedAssemblyPartTest).Assembly;

            var result = RelatedAssemblyAttribute.GetRelatedAssemblies(assembly, throwOnError: true, file => true, file =>
            {
                Assert.Equal(file, destination);
                return(relatedAssembly);
            });

            Assert.Equal(new[] { relatedAssembly }, result);
        }
示例#18
0
        public void CallsTestRunnerWithTestList()
        {
            var wrapper      = new Mock <IExecutorWrapper>();
            var callback     = new Mock <ITestMethodRunnerCallback>();
            var testMethod1  = new TestMethod("testMethod1", null, null);
            var testMethod2  = new TestMethod("testMethod2", null, null);
            var testMethod3  = new TestMethod("testMethod3", null, null);
            var testClass    = new TestableTestClass("typeName", new[] { testMethod1, testMethod2, testMethod3 });
            var testAssembly = new TestAssembly(wrapper.Object, new[] { testClass });

            var result = testClass.Run(new[] { testMethod1, testMethod2, testMethod3 }, callback.Object);

            Assert.Single(testClass.RunTests_Methods, "testMethod1");
            Assert.Single(testClass.RunTests_Methods, "testMethod2");
            Assert.Single(testClass.RunTests_Methods, "testMethod3");
            Assert.Same(callback.Object, testClass.RunTests_Callback);
            Assert.Equal(testClass.RunTests_ReturnValue, result);
        }
示例#19
0
    public void MultiAssemblySimpleFilterAcceptanceTest()
    {
        string code =
            @"
                using System;
                using Xunit;

                public class MockTestClass
                {
                    [Fact]
                    public void SuccessTest()
                    {
                        Assert.Equal(2, 2);
                    }
                }
            ";

        using (MockAssembly mockAssembly1 = new MockAssembly())
            using (MockAssembly mockAssembly2 = new MockAssembly())
            {
                mockAssembly1.Compile(code);
                mockAssembly2.Compile(code);
                Mock <ITestMethodRunnerCallback> callback = new Mock <ITestMethodRunnerCallback>();
                callback.Setup(c => c.TestStart(It.IsAny <TestMethod>())).Returns(true);
                callback.Setup(c => c.TestFinished(It.IsAny <TestMethod>())).Returns(true);
                MultiAssemblyTestEnvironment mate = new MultiAssemblyTestEnvironment();
                mate.Load(mockAssembly1.FileName);
                mate.Load(mockAssembly2.FileName);
                TestAssembly testAssembly1   = mate.EnumerateTestAssemblies().Where(a => a.AssemblyFilename == mockAssembly1.FileName).Single();
                TestAssembly testAssembly2   = mate.EnumerateTestAssemblies().Where(a => a.AssemblyFilename == mockAssembly2.FileName).Single();
                TestMethod   assembly1Method = testAssembly1.EnumerateTestMethods().Single();
                TestMethod   assembly2Method = testAssembly1.EnumerateTestMethods().Single();

                mate.Run(mate.EnumerateTestMethods(m => m.TestClass.TestAssembly == testAssembly1), callback.Object);

                callback.Verify(c => c.AssemblyStart(testAssembly1));
                callback.Verify(c => c.TestStart(assembly1Method));
                callback.Verify(c => c.TestFinished(assembly1Method));
                callback.Verify(c => c.AssemblyFinished(testAssembly1, 1, 0, 0, It.IsAny <double>()));
                callback.Verify(c => c.AssemblyStart(testAssembly2), Times.Never());
                var runResult = Assert.IsType <TestPassedResult>(assembly1Method.RunResults[0]);
                Assert.Null(runResult.Output);
            }
    }
示例#20
0
    public void GetFileInfo_ReturnsNotFoundfileInfo_ForPathsWithInvalidCharacters(string path)
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js"),
                                                    TestEntry.File("jquery.min.js"),
                                                    TestEntry.File("site.css"))));

        // Act
        var provider = new ManifestEmbeddedFileProvider(assembly);

        // Assert
        var file = provider.GetFileInfo(path);

        Assert.IsType <NotFoundFileInfo>(file);
        Assert.Equal(path, file.Name);
    }
示例#21
0
        /// <summary>
        /// Build a suite of tests given the name or the location of an assembly
        /// </summary>
        /// <param name="assemblyNameOrPath">The name or the location of the assembly.</param>
        /// <param name="options">A dictionary of options to use in building the suite</param>
        /// <returns>
        /// A TestSuite containing the tests found in the assembly
        /// </returns>
        public ITest Build(string assemblyNameOrPath, IDictionary <string, object> options)
        {
            log.Debug("Loading {0} in AppDomain {1}", assemblyNameOrPath, AppDomain.CurrentDomain.FriendlyName);

            TestSuite testAssembly = null;

            try
            {
                var assembly = AssemblyHelper.Load(assemblyNameOrPath);
                testAssembly = Build(assembly, assemblyNameOrPath, options);
            }
            catch (Exception ex)
            {
                testAssembly = new TestAssembly(assemblyNameOrPath);
                testAssembly.MakeInvalid(ExceptionHelper.BuildMessage(ex, true));
            }

            return(testAssembly);
        }
示例#22
0
        public void Validate(TestAssembly testAssembly)
        {
            foreach (var fixture in testAssembly.Fixtures)
            {
                foreach (var method in fixture.TestMethods)
                {
                    TestViolation violation = AssertTestOrNull(
                        method,
                        testAssembly.AssemblyCategories,
                        fixture.TestFixtureCategories
                        );

                    if (violation != null)
                    {
                        fixture.AddViolation(violation);
                    }
                }
            }
        }
示例#23
0
        public void ExecuteSimple()
        {
            var types = new[] { typeof(TestBullet1) };

            var strategy = new Mock <ISysDatabaseStrategy>();

            strategy.Setup(x => x.GetLastVersion(It.IsAny <string>())).Returns(0);

            ObjectFactory.Initialize(x =>
            {
                x.ForSingletonOf <ISysDatabaseStrategy>().Use(strategy.Object);
                x.ForSingletonOf <IDatabaseStrategy>().Use(new Mock <IDatabaseStrategy>().Object);
            });

            var assembly = new TestAssembly(types);

            Executor.Execute(assembly);
            Assert.IsTrue(TestBullet1.IsUpdateInvoked);
        }
        private RunData CreateNewFromFixture(TestAssembly testAssembly, TestFixture fixture)
        {
            RunData item = new RunData()
            {
                Fixtures = new List<TestFixture>() { fixture },
                Root = Args.Root,
                Output = new StringBuilder(),
                Groups = new HashSet<string>(),
                Exclusive = fixture.Exclusive ?? false,
                Executable = Args.GetExecutablePath(),
                RunId = Guid.NewGuid(),
                AssemblyName = testAssembly.Name
            };
            if (!string.IsNullOrEmpty(fixture.Group))
            {
                item.Groups.Add(fixture.Group);
            }

            return item;
        }
示例#25
0
        private TestSuite Build(Assembly assembly, string assemblyPath, IDictionary options)
        {
            TestSuite testAssembly = null;

            try
            {
                IList fixtureNames = options[PackageSettings.LOAD] as IList;
                IList fixtures     = GetFixtures(assembly, fixtureNames);

                testAssembly = BuildTestAssembly(assembly, assemblyPath, fixtures);
            }
            catch (Exception ex)
            {
                testAssembly          = new TestAssembly(assemblyPath);
                testAssembly.RunState = RunState.NotRunnable;
                testAssembly.Properties.Set(PropertyNames.SkipReason, ex.Message);
            }

            return(testAssembly);
        }
示例#26
0
        public void SetUpThrowsException()
        {
            var consoleOutput = new StringWriter();

            AssemblyFactory.Type = typeof(ATestAssembly);
            ATestAssembly.AssemblyFixtureType = typeof(AssemblyFixtureThrowsInSetUp);
            var ta = new TestAssembly(new AssemblyName("ATestAssembly"));

            Console.SetOut(consoleOutput);
            ta.RunTests(new TestRun(new AllTestsCriterion()), new SimpleTestListener());
            var expected =
                "Error: Exception thrown in SetUp method of TestAssemblyFixture:"
                + LineFeed +
                "       Tests depending on it might fail. Error details follow."
                + LineFeed +
                "Exception thrown in " + ATestAssembly.AssemblyFixtureType.FullName
                + @".SetUp()";

            Assert.Contains(expected, consoleOutput.ToString());
        }
示例#27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MettleTestFrameworkDiscoverer"/> class.
        /// </summary>
        /// <param name="assemblyInfo">The test assembly.</param>
        /// <param name="sourceProvider">The source information provider.</param>
        /// <param name="diagnosticMessageSink">The message sink used to send diagnostic messages</param>
        /// <param name="collectionFactory">The test collection factory used to look up test collections.</param>
        public MettleTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo,
                                             ISourceInformationProvider sourceProvider,
                                             IMessageSink diagnosticMessageSink,
                                             IXunitTestCollectionFactory collectionFactory = null)
            : base(assemblyInfo, sourceProvider, diagnosticMessageSink)
        {
            var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault();
            var disableParallelization      = collectionBehaviorAttribute != null && collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization");

            string config = null;

#if NETFRAMEWORK
            config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
#endif
            var testAssembly = new TestAssembly(assemblyInfo, config);

            TestCollectionFactory    = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, testAssembly);
            TestFrameworkDisplayName = $"{DisplayName} [{TestCollectionFactory.DisplayName}, {(disableParallelization ? "non-parallel" : "parallel")}]";
            this.AssemblyInfo        = assemblyInfo;
        }
示例#28
0
        public void Parse_TestClass()
        {
            args.Stub(m => m.PLevel).Return(PLevel.TestClass);

            Assembly     assembly     = Assembly.GetExecutingAssembly();
            TestAssembly testAssembly = target.Parse(assembly);

            Assert.AreEqual(assembly.Location, testAssembly.Name);

            TestFixture testClass1 = testAssembly.Fixtures.FirstOrDefault(x => x.Name == "ParallelTestRunner.Tests.VSTest.TestClass1");

            Assert.IsNotNull(testClass1);
            Assert.AreEqual("Group2", testClass1.Group);
            Assert.IsFalse(testClass1.Exclusive.Value);

            TestFixture testClass2 = testAssembly.Fixtures.FirstOrDefault(x => x.Name == "ParallelTestRunner.Tests.VSTest.TestClass2");

            Assert.IsNotNull(testClass2);
            Assert.AreEqual("Group1", testClass2.Group);
            Assert.AreEqual(true, testClass2.Exclusive);
        }
示例#29
0
        public void GivenIHaveATestAssemblyWithAValidConfigurationFile()
        {
            _executorMock = new Mock <ITestExecutor>();
            _executorMock.Setup(m => m.RunTests(It.IsAny <IEnumerable <TestDetails> >(), It.IsAny <TestAssembly>(), It.IsAny <string>(), null));

            _configMock = new Mock <IConfigurationManager>();
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\FieldTest.Runner.exe.config";

            _configMock.Setup(m => m.CopyApplicationConfiguration(It.IsAny <string>(), It.IsAny <string>()));

            _remoteTestRunner = new Core.RemoteTestRunner(null, _configMock.Object, _executorMock.Object);

            var testAssembly = new TestAssembly("", "ValidAssembly", "This is a string to a valid location");
            var testClass    = new TestClass(testAssembly, "ValidClass", "Valid.Namespace");
            var test         = new TestDetails(testClass, "TestMethod", "", 0);

            _tests = new List <TestDetails>()
            {
                test
            };
        }
示例#30
0
        static public bool RunAssemblyInitializeMethod(TestAssembly testAssembly)
        {
            Guard.NotNull(testAssembly, nameof(testAssembly));
            var method = testAssembly.AssemblyInitializeMethod;

            if (method == null)
            {
                return(true);
            }
            EventHandlerPipeline.Raise(
                new AssemblyInitializeMethodBeginEvent()
            {
                MethodName             = method.Name,
                FirstTestClassFullName = testAssembly.TestClasses.First().FullName,
                FirstTestMethodName    = testAssembly.TestClasses.First().TestMethods.First().Name,
            });
            var success = Run(method, null, true, null, false);

            EventHandlerPipeline.Raise(new AssemblyInitializeMethodEndEvent());
            return(success);
        }
示例#31
0
        public void CallsExecutorWrapperToRunTests()
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml("<foo/>");
            var xmlNode      = xmlDocument.ChildNodes[0];
            var wrapper      = new Mock <IExecutorWrapper>(MockBehavior.Strict);
            var callback     = new Mock <ITestMethodRunnerCallback>();
            var testMethod   = new TestMethod("testMethod", null, null);
            var testClass    = new TestClass("typeName", new[] { testMethod });
            var testAssembly = new TestAssembly(wrapper.Object, new[] { testClass });

            wrapper.Setup(w => w.RunTests(testClass.TypeName, new List <string> {
                "testMethod"
            }, It.IsAny <Predicate <XmlNode> >()))
            .Returns(xmlNode);

            var result = testClass.Run(new[] { testMethod }, callback.Object);

            Assert.Equal("<foo />", result);
        }
示例#32
0
        void ReloadAssemblies(IEnumerable assemblyListViewItems)
        {
            foreach (ListViewItem assemblyListViewItem in assemblyListViewItems)
            {
                TestAssembly testAssembly     = (TestAssembly)assemblyListViewItem.Tag;
                string       assemblyFilename = testAssembly.AssemblyFilename;
                string       configFilename   = testAssembly.ConfigFilename;

                RemoveFileWatcher(testAssembly);
                mate.Unload(testAssembly);

                testAssembly             = mate.Load(assemblyFilename, configFilename);
                assemblyListViewItem.Tag = testAssembly;
                AddFileWatcher(testAssembly);
            }

            UpdateAssemblyFilter();
            UpdateTestList();
            UpdateTraitsList();

            progress.Status = ProgressControl.ProgressStatus.Unknown;
        }
示例#33
0
    public void Contructor_CanScopeManifestToAFolder()
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js")),
                                TestEntry.File("site.css")));

        var provider       = new ManifestEmbeddedFileProvider(assembly);
        var scopedProvider = new ManifestEmbeddedFileProvider(assembly, provider.Manifest.Scope("wwwroot"), DateTimeOffset.UtcNow);

        // Act
        var jqueryValidate = scopedProvider.GetFileInfo("jquery.validate.js");

        // Assert
        Assert.True(jqueryValidate.Exists);
        Assert.False(jqueryValidate.IsDirectory);
        Assert.Equal("jquery.validate.js", jqueryValidate.Name);
        Assert.Null(jqueryValidate.PhysicalPath);
        Assert.Equal(0, jqueryValidate.Length);
    }
        public void TestStarted(ITest test)
        {
#if PORTABLE
            if (test is TestAssembly)
            {
                TestAssembly testAssembly = test as TestAssembly;
                Console.WriteLine(testAssembly.Name);
            }
            else if (test is TestFixture)
            {
                TestFixture testFixture = test as TestFixture;
                Console.WriteLine("\t{0}", testFixture.Name);
            }
            else if (test is TestMethod)
            {
                TestMethod testMethod = test as TestMethod;
                Console.Write("\t\t{0} => ", testMethod.Name);
            }
#else
            Events += string.Format("<{0}:", test.Name);
#endif
        }
示例#35
0
        private static void ProcessAssemblyInput(string[] inputLines, Dictionary <string, TestAssembly> assemblies)
        {
            // ASSEMBLY=>{AssemblyID}
            // {Path}
            // {HintPath}
            // {HintPath}
            // {HintPath}
            // ;
            string assemblyId = ExtractValue("ASSEMBLY=>{", inputLines[0]);

            string assemblyPath = inputLines[1];
            var    hintPaths    = inputLines.Skip(2).ToList();

            TestAssembly newAssembly = new TestAssembly(assemblyId, string.Empty, assemblyPath);

            if (hintPaths != null && hintPaths.Count > 0)
            {
                newAssembly.HintPaths.AddRange(hintPaths);
            }

            assemblies.Add(assemblyId, newAssembly);
        }
示例#36
0
    public void GetDirectoryContents_EnumeratesFilesAndDirectoriesOnAGivenPath()
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot"),
                                TestEntry.File("site.css")));

        var provider = new ManifestEmbeddedFileProvider(assembly);

        var expectedContents = new[]
        {
            CreateTestFileInfo("wwwroot", isDirectory: true),
            CreateTestFileInfo("site.css")
        };

        // Act
        var contents = provider.GetDirectoryContents(".").ToArray();

        // Assert
        Assert.Equal(expectedContents, contents, FileInfoComparer.Instance);
    }
示例#37
0
    public void GetFileInfo_AllowsLeadingDots_OnThePath()
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js"),
                                                    TestEntry.File("jquery.min.js"),
                                                    TestEntry.File("site.css"))));

        // Act
        var provider = new ManifestEmbeddedFileProvider(assembly);

        // Assert
        var jqueryValidate = provider.GetFileInfo(Path.Combine(".", "wwwroot", "jquery.validate.js"));

        Assert.True(jqueryValidate.Exists);
        Assert.False(jqueryValidate.IsDirectory);
        Assert.Equal("jquery.validate.js", jqueryValidate.Name);
        Assert.Null(jqueryValidate.PhysicalPath);
        Assert.Equal(0, jqueryValidate.Length);
    }
示例#38
0
    public void GetFileInfo_ResolvesFiles_WithDifferentCasing(string folder, string file)
    {
        // Arrange
        var assembly = new TestAssembly(
            TestEntry.Directory("unused",
                                TestEntry.Directory("wwwroot",
                                                    TestEntry.File("jquery.validate.js"),
                                                    TestEntry.File("jquery.min.js"),
                                                    TestEntry.File("site.css"))));

        // Act
        var provider = new ManifestEmbeddedFileProvider(assembly);

        // Assert
        var jqueryValidate = provider.GetFileInfo(Path.Combine(folder, file));

        Assert.True(jqueryValidate.Exists);
        Assert.False(jqueryValidate.IsDirectory);
        Assert.Equal("jquery.validate.js", jqueryValidate.Name);
        Assert.Null(jqueryValidate.PhysicalPath);
        Assert.Equal(0, jqueryValidate.Length);
    }
示例#39
0
        private TestSuite BuildTestAssembly(Assembly assembly, string assemblyName, IList fixtures, bool autoSuites)
        {
            TestSuite testAssembly = new TestAssembly(assembly, assemblyName);

            if (autoSuites)
            {
                NamespaceTreeBuilder treeBuilder =
                    new NamespaceTreeBuilder(testAssembly);
                treeBuilder.Add(fixtures);
                testAssembly = treeBuilder.RootSuite;
            }
            else
            {
                foreach (TestSuite fixture in fixtures)
                {
                    if (fixture != null)
                    {
                        if (fixture is SetUpFixture)
                        {
                            fixture.RunState     = RunState.NotRunnable;
                            fixture.IgnoreReason = "SetUpFixture cannot be used when loading tests as a flat list of fixtures";
                        }

                        testAssembly.Add(fixture);
                    }
                }
            }

            NUnitFramework.ApplyCommonAttributes(assembly, testAssembly);

            testAssembly.Properties["_PID"]       = System.Diagnostics.Process.GetCurrentProcess().Id;
            testAssembly.Properties["_APPDOMAIN"] = AppDomain.CurrentDomain.FriendlyName;


            // TODO: Make this an option? Add Option to sort assemblies as well?
            testAssembly.Sort();

            return(testAssembly);
        }
示例#40
0
        private void TestProjectTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            TestCaseInfo caseInfo = this.TestProjectTreeView.SelectedItem as TestCaseInfo;

            if (caseInfo != null)
            {
                DependencyObject parent = VisualTreeHelper.GetParent(current as TreeViewItem);
                while (!(parent is TreeViewItem))
                {
                    parent = VisualTreeHelper.GetParent(parent);
                }

                parent = VisualTreeHelper.GetParent(parent);
                while (!(parent is TreeViewItem))
                {
                    parent = VisualTreeHelper.GetParent(parent);
                }

                TestProjectShip testProjectShip = (parent as TreeViewItem).Header as TestProjectShip;
                this.testProjectsViewModel.SelectedItemChanged(testProjectShip);
            }

            TestAssembly assembly = this.TestProjectTreeView.SelectedItem as TestAssembly;

            if (assembly != null)
            {
                DependencyObject parent = VisualTreeHelper.GetParent(current as TreeViewItem);
                while (!(parent is TreeViewItem))
                {
                    parent = VisualTreeHelper.GetParent(parent);
                }

                TestProjectShip testProjectShip = (parent as TreeViewItem).Header as TestProjectShip;
                this.testProjectsViewModel.SelectedItemChanged(testProjectShip);
            }

            this.testProjectsViewModel.SelectedItemChanged(this.TestProjectTreeView.SelectedItem);
        }
示例#41
0
        private static int Run(Arguments args)
        {
            string path = args.AssembliesPath.FullName;

            SetupAssemblyResolver(path);

            Console.WriteLine("Loading assemblies from '{0}'", path);

            var sw = new DebugStopwatch("1.LoadAssemblies");
            IEnumerable <Assembly> assemblies = args.AssembliesPath
                                                .EnumerateFiles("*.dll", SearchOption.TopDirectoryOnly)
                                                .Where(file => !args.ExcludedAssemblies.Contains(file.Name))
                                                .Select(GetAssemblyOrNull)
                                                .Where(ass => ass != null)
                                                .Where(NUnitFrameworkReferenceChecker.ReferencesNUnitFramework);

            sw.Dispose();

            int violations = 0;

            TestAssemblyScanner scanner = new TestAssemblyScanner(
                new IAssemblyValidator[] {
                new ProhibitedAssemblyCategoryValidator(args.ProhibitedAssemblyCategories),
                new RequaredCategoryValidator(args.RequiredCategories)
            });

            using (IndentedTextWriter writer = new IndentedTextWriter(Console.Error, "\t")) {
                foreach (Assembly assembly in assemblies)
                {
                    TestAssembly testAssembly = scanner.Scan(assembly);
                    violations += Report(testAssembly, writer);
                }

                DebugStopwatch.Report(writer);
            }

            return(violations);
        }
示例#42
0
        public void ExceptionThrown(TestAssembly testAssembly, Exception exception)
        {
            if (InvokeRequired)
            {
                Delegate del = new ExceptionThrownDelegate(ExceptionThrown);
                BeginInvoke(del, testAssembly, exception);
                return;
            }

            textResults.Text += exception.ToString() + Environment.NewLine + Environment.NewLine;
        }
示例#43
0
 void AddFileWatcher(TestAssembly testAssembly)
 {
     FileWatcher fileWatcher = new FileWatcher(testAssembly.AssemblyFilename);
     fileWatcher.Changed += (s, e) => ReloadAssembly(testAssembly);
     fileWatchers[testAssembly] = fileWatcher;
 }
示例#44
0
        public void AssemblyFinished(TestAssembly testAssembly, int total, int failed, int skipped, double time)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new AssemblyFinishedDelegate(AssemblyFinished), testAssembly, total, failed, skipped, time);
                return;
            }

            testsTotal += total;
            testsFailed += failed;
            testsSkipped += skipped;
            testsDuration += time;
        }
示例#45
0
 public void AssemblyStart(TestAssembly testAssembly)
 {
 }
示例#46
0
 public void AssemblyFinished(TestAssembly testAssembly, int total, int failed, int skipped, double time)
 {
     throw new NotImplementedException();
 }
示例#47
0
        private TestSuite BuildTestAssembly( string assemblyName, IList fixtures, bool autoSuites )
        {
            TestSuite testAssembly = new TestAssembly( assemblyName );

            if ( autoSuites )
            {
                NamespaceTreeBuilder treeBuilder =
                    new NamespaceTreeBuilder( testAssembly );
                treeBuilder.Add( fixtures );
                testAssembly = treeBuilder.RootSuite;
            }
            else
            foreach( TestSuite fixture in fixtures )
            {
                if (fixture != null)
                {
                    if (fixture is SetUpFixture)
                    {
                        fixture.RunState = RunState.NotRunnable;
                        fixture.IgnoreReason = "SetUpFixture cannot be used when loading tests as a flat list of fixtures";
                    }

                    testAssembly.Add(fixture);
                }
            }

            if ( fixtures.Count == 0 )
            {
                testAssembly.RunState = RunState.NotRunnable;
                testAssembly.IgnoreReason = "Has no TestFixtures";
            }

            NUnitFramework.ApplyCommonAttributes( assembly, testAssembly );

            testAssembly.Properties["_PID"] = System.Diagnostics.Process.GetCurrentProcess().Id;
            testAssembly.Properties["_APPDOMAIN"] = AppDomain.CurrentDomain.FriendlyName;

            // TODO: Make this an option? Add Option to sort assemblies as well?
            testAssembly.Sort();

            return testAssembly;
        }
        /// <summary>
        /// Unloads the specified assembly.
        /// </summary>
        /// <param name="assembly">The assembly to unload.</param>
        public void Unload(TestAssembly assembly)
        {
            Guard.ArgumentNotNull("assembly", assembly);
            Guard.ArgumentValid("assembly", "Assembly not loaded in this environment", testAssemblies.Contains(assembly));

            testAssemblies.Remove(assembly);
            assembly.Dispose();
        }
示例#49
0
        void ReloadAssembly(TestAssembly testAssembly)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new ReloadAssemblyDelegate(ReloadAssembly), testAssembly);
                return;
            }

            ListViewItem lvi = FindTestAssemblyItem(testAssembly);

            if (lvi != null)
            {
                if (isRunning)
                {
                    isCancelRequested = true;
                    reloadRequested.Add(testAssembly);
                }
                else
                {
                    ReloadAssemblies(new[] { lvi });
                    statusLabel.Text = "Reloaded " + testAssembly.AssemblyFilename + " at " + DateTime.Now.ToShortTimeString();
                }
            }
        }
示例#50
0
 public void TestFixtureNestedInIgnoredTestFixture() {
    AssemblyFactory.Type = typeof(ASpecialAssembly);
    var assembly = new TestAssembly(new AssemblyName("bla"));
    assembly.RunTests(new TestRun(new AllTestsCriterion()), new SimpleTestListener());
    Assert.DoesNotContain("Bar", SimpleTestListener.Messages);
 }
示例#51
0
      public void IgnoreAppliedOnlyAfterTestSpec() {
         AssemblyFactory.Type = typeof(ASpecialAssembly);
         var assembly = new TestAssembly(new AssemblyName("bla"));

         // The fixture is actually in category "Blue"!
         assembly.RunTests(new TestRun(new CategoryCriterion("Green")), new SimpleTestListener());
         
         Assert.Equals(0, SimpleTestListener.IgnoredItems.Length,
            "Ignored tests that were not specified.");
      }
示例#52
0
 public void IgnoredTestFixtureIsReported() {
    AssemblyFactory.Type = typeof(ASpecialAssembly);
    var assembly = new TestAssembly(new AssemblyName("bla"));
    assembly.RunTests(new TestRun(new AllTestsCriterion()), new SimpleTestListener());
    Assert.Contains(GetType().Assembly.FullName +
       "#csUnit.Core.Tests.TestAssemblyTests+IgnoredFixture##Ignored for testing reasons.#",
       SimpleTestListener.IgnoredItems);
 }
示例#53
0
 public void ExceptionThrown(TestAssembly testAssembly, Exception exception)
 {
     innerCallback.ExceptionThrown(testAssembly, exception);
 }
示例#54
0
 public void AssemblyStart(TestAssembly testAssembly)
 {
     throw new NotImplementedException();
 }
示例#55
0
        void AddTestAssembly(TestAssembly testAssembly)
        {
            ListViewItem lviAssembly = new ListViewItem
            {
                Text = Path.GetFileNameWithoutExtension(testAssembly.AssemblyFilename),
                ToolTipText = testAssembly.AssemblyFilename + Environment.NewLine +
                              "xunit.dll verison " + testAssembly.XunitVersion,
                Tag = testAssembly
            };

            AddFileWatcher(testAssembly);
            listAssemblies.Items.Add(lviAssembly);

            UpdateAssemblyFilter();
            UpdateTraitsList();
            UpdateTestList();
            UpdateAssemblyDynamicMenus();
        }
        public void TestMethodNotForThisEnvironmentThrows()
        {
            var wrapper = new Mock<IExecutorWrapper>();
            var mate = TestableMultiAssemblyTestEnvironment.Create();
            var testMethod = new TestMethod(null, null, null);
            var testClass = new TestClass(null, new[] { testMethod });
            var testAssembly = new TestAssembly(wrapper.Object, new[] { testClass });
            var callback = new Mock<ITestMethodRunnerCallback>();

            Assert.Throws<ArgumentException>(() => mate.Run(new[] { testMethod }, callback.Object));
        }
示例#57
0
        ListViewItem FindTestAssemblyItem(TestAssembly testAssembly)
        {
            foreach (ListViewItem lvi in listAssemblies.Items)
                if (lvi.Tag == testAssembly)
                    return lvi;

            return null;
        }
 public void TearDownThrowsException() {
    var consoleOutput = new StringWriter();
    AssemblyFactory.Type = typeof(ATestAssembly);
    ATestAssembly.AssemblyFixtureType = typeof(AssemblyFixtureThrowsInTearDown);
    var ta = new TestAssembly(new AssemblyName("ATestAssembly"));
    Console.SetOut(consoleOutput);
    ta.RunTests(new TestRun(new AllTestsCriterion()), new SimpleTestListener());
    var expected =
       "Executing " + GetType().FullName + @"+ATestAssembly+ATestClass.TheOnlyTestInThisAssembly()" + LineFeed +
       "Error: Exception thrown in TearDown method of TestAssemblyFixture:" + LineFeed +
       "       Assembly might not properly tear down used resources. Error details follow." + LineFeed +
       "Exception thrown in " + ATestAssembly.AssemblyFixtureType.FullName + @".TearDown()" + LineFeed;
    Assert.Contains(expected, consoleOutput.ToString());
 }
示例#59
0
        private void RemoveFileWatcher(TestAssembly testAssembly)
        {
            FileWatcher fileWatcher = fileWatchers[testAssembly];

            fileWatcher.Dispose();
            fileWatchers.Remove(testAssembly);
        }
        public void AssemblyNotInAssemblyList()
        {
            var wrapper = CreateStubExecutor();
            var assembly = new TestAssembly(wrapper, new TestClass[0]);

            Assert.Throws<ArgumentException>(
                () => new TestableMultiAssemblyTestEnvironment().Unload(assembly));
        }