Permalink
Browse files

Creating a unit test project for the LanguageServices assembly

  • Loading branch information...
1 parent 769853c commit 5cdc0f6ae7cf8e5dd5829c12c6182aed78f3dfd9 @jrusbatch committed Sep 23, 2012
View
@@ -26,6 +26,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess", "DataAccess\Da
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{67A4A77F-7D7D-4A37-BCC1-A7E018CCD6C8}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LanguageServices.Tests", "Tests\LanguageServices.Tests\LanguageServices.Tests.csproj", "{9F0E99A4-2347-4598-8502-19E4AB080CBC}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -98,11 +100,22 @@ Global
{67A4A77F-7D7D-4A37-BCC1-A7E018CCD6C8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{67A4A77F-7D7D-4A37-BCC1-A7E018CCD6C8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{67A4A77F-7D7D-4A37-BCC1-A7E018CCD6C8}.Release|x86.ActiveCfg = Release|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0D23E4FF-5460-4563-809A-D5A4F2D9F18D} = {B0515ECE-80FA-400C-A9E8-ED6E881D9625}
+ {9F0E99A4-2347-4598-8502-19E4AB080CBC} = {B0515ECE-80FA-400C-A9E8-ED6E881D9625}
EndGlobalSection
EndGlobal
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{9F0E99A4-2347-4598-8502-19E4AB080CBC}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Compilify</RootNamespace>
+ <AssemblyName>Compilify.LanguageServices.Tests</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="LanguageServices\CSharpCompilerTests.cs" />
+ <Compile Include="LanguageServices\EvaluateCodeCommandTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="Moq">
+ <HintPath>..\..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
+ </Reference>
+ <Reference Include="protobuf-net">
+ <HintPath>..\..\packages\protobuf-net.2.0.0.480\lib\net40\protobuf-net.dll</HintPath>
+ </Reference>
+ <Reference Include="Roslyn.Compilers, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Roslyn.Compilers.Common.1.2.20906.2\lib\net45\Roslyn.Compilers.dll</HintPath>
+ </Reference>
+ <Reference Include="Roslyn.Compilers.CSharp, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Roslyn.Compilers.CSharp.1.2.20906.2\lib\net45\Roslyn.Compilers.CSharp.dll</HintPath>
+ </Reference>
+ <Reference Include="Roslyn.Services, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Roslyn.Services.Common.1.2.20906.2\lib\net45\Roslyn.Services.dll</HintPath>
+ </Reference>
+ <Reference Include="Roslyn.Services.CSharp, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Roslyn.Services.CSharp.1.2.20906.2\lib\net45\Roslyn.Services.CSharp.dll</HintPath>
+ </Reference>
+ <Reference Include="Roslyn.Utilities, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Roslyn.Services.Common.1.2.20906.2\lib\net45\Roslyn.Utilities.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.XML" />
+ <Reference Include="xunit">
+ <HintPath>..\..\packages\xunit.1.9.1\lib\net20\xunit.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\Core\Core.csproj">
+ <Project>{67a4a77f-7d7d-4a37-bcc1-a7e018ccd6c8}</Project>
+ <Name>Core</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\LanguageServices\LanguageServices.csproj">
+ <Project>{8f2ea92a-1519-482e-9808-dacb2ca67503}</Project>
+ <Name>LanguageServices</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup />
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using Xunit;
+
+namespace Compilify.LanguageServices
+{
+ public class CSharpCompilerTests
+ {
+ [Fact]
+ public void CodeCanBeCompiledAndExecuted()
+ {
+ var classes = new Document("Classes", "public static void SayHello() { Console.WriteLine(\"Hello, world!\"); }");
+ var content = new Document("Content", "SayHello(); return \"Done!\";");
+
+ var command = new EvaluateCodeCommand
+ {
+ ClientId = Guid.NewGuid().ToString("N"),
+ Documents = new List<Document> { content, classes },
+ Name = "Untitled",
+ Submitted = DateTime.UtcNow,
+ TimeoutPeriod = TimeSpan.FromSeconds(30)
+ };
+
+ var sandbox = new Sandbox();
+ var compiler = new CSharpCompiler();
+
+ var actual = compiler.Compile(command);
+
+ Assert.NotNull(actual);
+
+ var result = sandbox.Execute(actual, Timeout.InfiniteTimeSpan);
+
+ Assert.NotNull(result);
+ Assert.Equal("Hello, world!\r\n", result.ConsoleOutput);
+ Assert.Equal("\"Done!\"", result.Result);
+ }
+ }
+}
@@ -0,0 +1,33 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using ProtoBuf;
+using Xunit;
+
+namespace Compilify.LanguageServices
+{
+ public class EvaluateCodeCommandTests
+ {
+ [Fact]
+ public void CanBeSerialized()
+ {
+ var expected = new EvaluateCodeCommand
+ {
+ Documents = new List<Document>()
+ };
+
+ EvaluateCodeCommand actual;
+ using (var stream = new MemoryStream())
+ {
+ Assert.DoesNotThrow(() => Serializer.Serialize(stream, expected));
+
+ stream.Seek(0, SeekOrigin.Begin);
+
+ actual = Serializer.Deserialize<EvaluateCodeCommand>(stream);
+ }
+
+ Assert.NotNull(actual);
+ Assert.Equal(0, actual.Documents.Count());
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("LanguageServices.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("LanguageServices.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("053d9acf-8976-4fc9-81d4-3fb165b29575")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Moq" version="4.0.10827" targetFramework="net45" />
+ <package id="protobuf-net" version="2.0.0.480" targetFramework="net45" />
+ <package id="Roslyn.Compilers.Common" version="1.2.20906.2" targetFramework="net45" />
+ <package id="Roslyn.Compilers.CSharp" version="1.2.20906.2" targetFramework="net45" />
+ <package id="Roslyn.Services.Common" version="1.2.20906.2" targetFramework="net45" />
+ <package id="Roslyn.Services.CSharp" version="1.2.20906.2" targetFramework="net45" />
+ <package id="xunit" version="1.9.1" targetFramework="net45" />
+</packages>

0 comments on commit 5cdc0f6

Please sign in to comment.