Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 766855a

Browse files
committed
Progress on porting the xunit tests
1 parent 3234b6b commit 766855a

File tree

8 files changed

+448
-15
lines changed

8 files changed

+448
-15
lines changed

src/CodeFormatter.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{34034F
1616
EndProject
1717
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitConverter", "XUnitConverter\XUnitConverter.csproj", "{81B0FF57-C128-4F6B-83C7-94DBAF261582}"
1818
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitConverter.Tests", "XUnitConverter.Tests\XUnitConverter.Tests.csproj", "{BA4C1700-8A72-4F33-AF67-0E60F324E521}"
20+
EndProject
1921
Global
2022
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2123
Debug|Any CPU = Debug|Any CPU
@@ -38,6 +40,10 @@ Global
3840
{81B0FF57-C128-4F6B-83C7-94DBAF261582}.Debug|Any CPU.Build.0 = Debug|Any CPU
3941
{81B0FF57-C128-4F6B-83C7-94DBAF261582}.Release|Any CPU.ActiveCfg = Release|Any CPU
4042
{81B0FF57-C128-4F6B-83C7-94DBAF261582}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{BA4C1700-8A72-4F33-AF67-0E60F324E521}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44+
{BA4C1700-8A72-4F33-AF67-0E60F324E521}.Debug|Any CPU.Build.0 = Debug|Any CPU
45+
{BA4C1700-8A72-4F33-AF67-0E60F324E521}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{BA4C1700-8A72-4F33-AF67-0E60F324E521}.Release|Any CPU.Build.0 = Release|Any CPU
4147
EndGlobalSection
4248
GlobalSection(SolutionProperties) = preSolution
4349
HideSolutionNode = FALSE
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("XUnitConverter.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("XUnitConverter.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("53b17378-8f9a-4669-ac68-94b0ae5e4e24")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Microsoft.CodeAnalysis;
10+
using Xunit;
11+
using System.Threading;
12+
using Microsoft.CodeAnalysis.Formatting;
13+
14+
namespace XUnitConverterTests
15+
{
16+
public class UsesXunitForTestsFormattingRuleTests
17+
{
18+
private static readonly MetadataReference s_MSTestReference = MetadataReference.CreateFromAssembly(typeof(Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute).Assembly);
19+
private static readonly MetadataReference s_XunitReference = MetadataReference.CreateFromAssembly(typeof(FactAttribute).Assembly);
20+
21+
private CustomWorkspace CreateWorkspace()
22+
{
23+
return null;
24+
}
25+
26+
private async Task<Solution> RunConverter(Project project, bool runFormatter)
27+
{
28+
var xunitConverter = new XUnitConverter.XUnitConverter();
29+
var solution = await xunitConverter.ProcessAsync(project, CancellationToken.None);
30+
31+
if (runFormatter)
32+
{
33+
foreach (var id in project.DocumentIds)
34+
{
35+
var document = solution.GetDocument(id);
36+
document = await Formatter.FormatAsync(document);
37+
solution = document.Project.Solution;
38+
}
39+
}
40+
41+
return solution;
42+
}
43+
44+
/*
45+
protected override IEnumerable<MetadataReference> GetSolutionMetadataReferences()
46+
{
47+
return base.GetSolutionMetadataReferences()
48+
.Concat(new[] {
49+
s_MSTestReference,
50+
s_XunitReference
51+
});
52+
}
53+
*/
54+
55+
[Fact]
56+
public void TestUpdatesUsingStatements()
57+
{
58+
var text = @"
59+
using System;
60+
using Microsoft.VisualStudio.TestTools.UnitTesting;
61+
62+
namespace System.Composition.UnitTests
63+
{
64+
}
65+
";
66+
67+
var expected = @"
68+
using System;
69+
using Xunit;
70+
71+
namespace System.Composition.UnitTests
72+
{
73+
}
74+
";
75+
Verify(text, expected);
76+
}
77+
78+
[Fact]
79+
public void TestUpdatesUsingStatementsWithIfDefs()
80+
{
81+
var text = @"
82+
using System;
83+
#if NETFX_CORE
84+
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
85+
#elif PORTABLE_TESTS
86+
using Microsoft.Bcl.Testing;
87+
#else
88+
using Microsoft.VisualStudio.TestTools.UnitTesting;
89+
90+
#endif
91+
namespace System.Composition.UnitTests
92+
{
93+
}
94+
";
95+
96+
var expected = @"
97+
using System;
98+
using Xunit;
99+
100+
namespace System.Composition.UnitTests
101+
{
102+
}
103+
";
104+
Verify(text, expected);
105+
}
106+
107+
[Fact]
108+
public void TestRemovesTestClassAttributes()
109+
{
110+
var text = @"
111+
using System;
112+
using Microsoft.VisualStudio.TestTools.UnitTesting;
113+
114+
namespace System.Composition.UnitTests
115+
{
116+
[TestClass]
117+
public class MyTestClass
118+
{
119+
}
120+
}
121+
";
122+
123+
var expected = @"
124+
using System;
125+
using Xunit;
126+
127+
namespace System.Composition.UnitTests
128+
{
129+
public class MyTestClass
130+
{
131+
}
132+
}
133+
";
134+
Verify(text, expected);
135+
}
136+
137+
[Fact]
138+
public void TestUpdatesTestMethodAttributes()
139+
{
140+
var text = @"
141+
using System;
142+
using Microsoft.VisualStudio.TestTools.UnitTesting;
143+
144+
namespace System.Composition.UnitTests
145+
{
146+
public class MyTestClass
147+
{
148+
[TestMethod]
149+
public void MyTestMethod()
150+
{
151+
}
152+
}
153+
}
154+
";
155+
156+
var expected = @"
157+
using System;
158+
using Xunit;
159+
160+
namespace System.Composition.UnitTests
161+
{
162+
public class MyTestClass
163+
{
164+
[Fact]
165+
public void MyTestMethod()
166+
{
167+
}
168+
}
169+
}
170+
";
171+
Verify(text, expected);
172+
}
173+
174+
[Fact]
175+
public void TestUpdatesAsserts()
176+
{
177+
var text = @"
178+
using System;
179+
using Microsoft.VisualStudio.TestTools.UnitTesting;
180+
181+
namespace System.Composition.UnitTests
182+
{
183+
public class MyTestClass
184+
{
185+
public void MyTestMethod()
186+
{
187+
object obj = new object();
188+
189+
Assert.AreEqual(1, 1);
190+
Assert.AreNotEqual(1, 2);
191+
Assert.IsNull(null);
192+
Assert.IsNotNull(obj);
193+
Assert.AreSame(obj, obj);
194+
Assert.AreNotSame(obj, new object());
195+
Assert.IsTrue(true);
196+
Assert.IsFalse(false);
197+
Assert.IsInstanceOfType(string.Empty, typeof(String));
198+
}
199+
}
200+
}
201+
";
202+
203+
var expected = @"
204+
using System;
205+
using Xunit;
206+
207+
namespace System.Composition.UnitTests
208+
{
209+
public class MyTestClass
210+
{
211+
public void MyTestMethod()
212+
{
213+
object obj = new object();
214+
215+
Assert.Equal(1, 1);
216+
Assert.NotEqual(1, 2);
217+
Assert.Null(null);
218+
Assert.NotNull(obj);
219+
Assert.Same(obj, obj);
220+
Assert.NotSame(obj, new object());
221+
Assert.True(true);
222+
Assert.False(false);
223+
Assert.IsAssignableFrom(typeof(String), string.Empty);
224+
}
225+
}
226+
}
227+
";
228+
Verify(text, expected);
229+
}
230+
}
231+
}

0 commit comments

Comments
 (0)