// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team // // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons // to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml; using ICSharpCode.MSTest; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.UnitTesting; using NUnit.Framework; namespace MSTest.SharpDevelop.Tests { [TestFixture] public class MSTestResultsTests { MSTestResults testResults; void CreateMSTestResults(string xml) { using (var reader = new XmlTextReader(new StringReader(xml))) { testResults = new MSTestResults(reader); } } void AssertTestResultsAreEqual(TestResult[] expectedResults) { List expectedResultsAsString = ConvertToStrings(expectedResults); List actualResultsAsString = ConvertToStrings(testResults); CollectionAssert.AreEqual(expectedResultsAsString, actualResultsAsString); } List ConvertToStrings(IEnumerable results) { return results.Select( result => String.Format( "Name: {0}, Result: {1}, Message: '{2}', StackTrace: '{3}', StackPosition: {4}", result.Name, result.ResultType, result.Message, result.StackTrace, result.StackTraceFilePosition)) .ToList(); } [Test] public void Results_OneClassWithTwoPassingTestMethods_ReturnsTwoResults() { CreateMSTestResults(oneClassWithTwoPassingTestMethods); var expectedResults = new TestResult[] { new TestResult("FooTest.UnitTest1.TestMethod1") { ResultType = TestResultType.Success }, new TestResult("FooTest.UnitTest1.TestMethod2") { ResultType = TestResultType.Success }, }; AssertTestResultsAreEqual(expectedResults); } string oneClassWithTwoPassingTestMethods = @" These are default test settings for a local test run.
"; [Test] public void Results_OneTestMethodThrowsException_ReturnsOneErrorResultWithStackTrace() { CreateMSTestResults(oneTestMethodThrowsException); var expectedResults = new TestResult[] { new TestResult("FooTest.UnitTest1.TestMethod1") { ResultType = TestResultType.Failure, Message = "System.ApplicationException: asdfafds", StackTrace = " at FooTest.UnitTest1.TestMethod1() in d:\\projects\\FooTest\\UnitTest1.cs:line 21\r\n", StackTraceFilePosition = new DomRegion(@"d:\projects\FooTest\UnitTest1.cs", 21, 1) } }; AssertTestResultsAreEqual(expectedResults); } string oneTestMethodThrowsException = @" Test method FooTest.UnitTest1.TestMethod1 threw exception: System.ApplicationException: asdfafds at FooTest.UnitTest1.TestMethod1() in d:\projects\FooTest\UnitTest1.cs:line 21 "; } }