-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 992ffb6
Showing
6 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Auto-detect text vs binary | ||
* text=auto | ||
# Better context in unified diffs | ||
*.cs diff=csharp | ||
# Force \n on shell scripts | ||
*.sh eol=lf | ||
# Force \r\n on solution files (may not be necessary) | ||
*.sln eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[Oo]bj/ | ||
[Bb]in/ | ||
TestResults/ | ||
.nuget/ | ||
.build/ | ||
.testPublish/ | ||
*.sln.ide/ | ||
_ReSharper.*/ | ||
packages/ | ||
artifacts/ | ||
PublishProfiles/ | ||
.vs/ | ||
bower_components/ | ||
node_modules/ | ||
debugSettings.json | ||
project.lock.json | ||
*.user | ||
*.suo | ||
*.cache | ||
*.docstates | ||
_ReSharper.* | ||
nuget.exe | ||
*net45.csproj | ||
*net451.csproj | ||
*k10.csproj | ||
*.psess | ||
*.vsp | ||
*.pidb | ||
*.userprefs | ||
*DS_Store | ||
*.ncrunchsolution | ||
*.*sdf | ||
*.ipch | ||
.settings | ||
*.sln.ide | ||
node_modules | ||
*launchSettings.json | ||
*.orig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26228.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XunitTestImmutable", "XunitTestImmutable\XunitTestImmutable.csproj", "{FF392B37-09DB-4A52-A79A-70614D751A1D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FF392B37-09DB-4A52-A79A-70614D751A1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FF392B37-09DB-4A52-A79A-70614D751A1D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FF392B37-09DB-4A52-A79A-70614D751A1D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FF392B37-09DB-4A52-A79A-70614D751A1D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.PortableExecutable; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.Extensions.DependencyModel; | ||
using Xunit; | ||
|
||
namespace XunitTestImmutable | ||
{ | ||
public class UnitTest1 | ||
{ | ||
[Fact] | ||
public void AddAdds() | ||
{ | ||
// Arrange | ||
var list = ImmutableList<string>.Empty; | ||
|
||
// Act | ||
list = list.Add("Hello World"); | ||
|
||
// Assert | ||
var item = Assert.Single(list); | ||
Assert.Equal("Hello World", item); | ||
} | ||
|
||
[Fact] | ||
public void CreateCreates() | ||
{ | ||
// Arrange & Act | ||
var compilation = CSharpCompilation.Create("__unrealName"); | ||
|
||
// Assert | ||
Assert.NotNull(compilation); | ||
} | ||
|
||
[Fact] | ||
public void GetGets() | ||
{ | ||
// Arrange | ||
var compilation = CSharpCompilation.Create("__unrealName", references: GetReferences()); | ||
|
||
// Act | ||
var typeSymbol = compilation.GetTypeByMetadataName("System.Collections.Generic.IDictionary`2"); | ||
|
||
// Assert | ||
Assert.NotNull(typeSymbol); | ||
} | ||
|
||
private static List<MetadataReference> GetReferences() | ||
{ | ||
var applicationAssembly = Assembly.GetExecutingAssembly(); | ||
var dependencyContext = DependencyContext.Load(applicationAssembly); | ||
var references = dependencyContext | ||
?.CompileLibraries | ||
.SelectMany(library => library.ResolveReferencePaths()) | ||
.ToList(); | ||
|
||
var libraryPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
var metadataReferences = new List<MetadataReference>(); | ||
foreach (var path in references ?? Enumerable.Empty<string>()) | ||
{ | ||
if (libraryPaths.Add(path)) | ||
{ | ||
var metadataReference = CreateMetadataReference(path); | ||
metadataReferences.Add(metadataReference); | ||
} | ||
} | ||
|
||
return metadataReferences; | ||
} | ||
|
||
private static MetadataReference CreateMetadataReference(string path) | ||
{ | ||
using (var stream = File.OpenRead(path)) | ||
{ | ||
var moduleMetadata = ModuleMetadata.CreateFromStream(stream, PEStreamOptions.PrefetchMetadata); | ||
var assemblyMetadata = AssemblyMetadata.Create(moduleMetadata); | ||
|
||
return assemblyMetadata.GetReference(filePath: path); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net452</TargetFramework> | ||
|
||
<!-- Need the .deps.json file to use DependencyContext.Load() on the test assembly. --> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="1.3.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> | ||
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- | ||
Work around https://github.com/Microsoft/vstest/issues/196. Execute tests with assemblies in the bin folder, not | ||
a temporary location. Lose the .deps.json file otherwise. | ||
--> | ||
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"shadowCopy": false | ||
} |