This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for the RoslynCompiler class.
- Loading branch information
Cesar Blum Silveira
committed
Oct 14, 2015
1 parent
008a7fd
commit b281692
Showing
4 changed files
with
95 additions
and
8 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
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
82 changes: 82 additions & 0 deletions
82
test/Microsoft.Dnx.Compilation.CSharp.Tests/RoslynCompilerTest.cs
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,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Versioning; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.Dnx.Compilation.Caching; | ||
using Microsoft.Dnx.Runtime; | ||
#if DNX451 | ||
using Moq; | ||
#endif | ||
using Xunit; | ||
|
||
namespace Microsoft.Dnx.Compilation.CSharp.Tests | ||
{ | ||
public class RoslynCompilerTest | ||
{ | ||
#if DNX451 | ||
[Fact] | ||
public void FlowsProjectPropertiesIntoAssembly() | ||
{ | ||
const string testName = "Test name"; | ||
const string testTitle = "Test title"; | ||
const string testDescription = "Test description"; | ||
const string testCopyright = "Test copyright"; | ||
const string testAssemblyFileVersion = "1.2.3.4"; | ||
const string testVersion = "1.2.3-rc1"; | ||
const string testFrameworkName = "DNX,Version=v4.5.1"; | ||
|
||
// Arrange | ||
var compilationProjectContext = new CompilationProjectContext( | ||
new CompilationTarget(testName, new FrameworkName(testFrameworkName), string.Empty, string.Empty), | ||
string.Empty, | ||
string.Empty, | ||
testTitle, | ||
testDescription, | ||
testCopyright, | ||
testVersion, | ||
new Version(testAssemblyFileVersion), | ||
false, | ||
new CompilationFiles( | ||
new List<string> { }, | ||
new List<string> { }), | ||
new Mock<ICompilerOptions>().Object); | ||
var compiler = new RoslynCompiler( | ||
new Mock<ICache>().Object, | ||
new Mock<ICacheContextAccessor>().Object, | ||
new Mock<INamedCacheDependencyProvider>().Object, | ||
new Mock<IAssemblyLoadContext>().Object, | ||
new Mock<IFileWatcher>().Object, | ||
new Mock<IApplicationEnvironment>().Object, | ||
new Mock<IServiceProvider>().Object); | ||
var metadataReference = new Mock<IRoslynMetadataReference>(); | ||
metadataReference | ||
.Setup(reference => reference.MetadataReference) | ||
.Returns(MetadataReference.CreateFromFile(typeof(object).Assembly.Location)); | ||
|
||
// Act | ||
var compilationContext = compiler.CompileProject( | ||
compilationProjectContext, | ||
new List<IMetadataReference> { metadataReference.Object }, | ||
new List<ISourceReference> { }, | ||
() => new List<ResourceDescriptor> { }); | ||
|
||
// Assert | ||
var expectedAttributes = new Dictionary<string, string> | ||
{ | ||
[typeof(AssemblyTitleAttribute).FullName] = testTitle, | ||
[typeof(AssemblyDescriptionAttribute).FullName] = testDescription, | ||
[typeof(AssemblyCopyrightAttribute).FullName] = testCopyright, | ||
[typeof(AssemblyFileVersionAttribute).FullName] = testAssemblyFileVersion, | ||
[typeof(AssemblyVersionAttribute).FullName] = testVersion.Substring(0, testVersion.IndexOf('-')), | ||
[typeof(AssemblyInformationalVersionAttribute).FullName] = testVersion, | ||
}; | ||
var compilationAttributes = compilationContext.Compilation.Assembly.GetAttributes(); | ||
|
||
Assert.All(compilationAttributes, compilationAttribute => expectedAttributes[compilationAttribute.AttributeClass.ToString()].Equals( | ||
compilationAttribute.ConstructorArguments.First().Value)); | ||
} | ||
#endif | ||
} | ||
} |
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