Skip to content

Commit dc53f44

Browse files
committed
Initial commit for Roslyn testing code. Doesn't work yet - using this commit to copy to other machine.
1 parent 5eec60a commit dc53f44

File tree

11 files changed

+336
-0
lines changed

11 files changed

+336
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2014 Jon Skeet. All rights reserved. Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.
2+
using System;
3+
4+
namespace ProductionCode.Attributes
5+
{
6+
[AttributeUsage(AttributeTargets.Parameter)]
7+
public sealed class NotNullAttribute : Attribute
8+
{
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{14988D27-F3F8-4BFD-B0B6-C68ECBD5E4DF}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ProductionCode</RootNamespace>
11+
<AssemblyName>ProductionCode</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Xml" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="Attributes\NotNullAttribute.cs" />
43+
<Compile Include="SampleCode.cs" />
44+
<Compile Include="Utilities\Preconditions.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
48+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
49+
Other similar extension points exist, see Microsoft.Common.targets.
50+
<Target Name="BeforeBuild">
51+
</Target>
52+
<Target Name="AfterBuild">
53+
</Target>
54+
-->
55+
</Project>
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("ProductionCode")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ProductionCode")]
13+
[assembly: AssemblyCopyright("Copyright © 2014")]
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("f72c562f-e8a8-4910-b11c-0f67b43efcf8")]
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")]
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 Jon Skeet. All rights reserved. Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.
2+
using System;
3+
using ProductionCode.Attributes;
4+
using ProductionCode.Utilities;
5+
6+
namespace ProductionCode
7+
{
8+
public class SampleCode
9+
{
10+
public static void Foo([NotNull] string a, [NotNull] string b, [NotNull] string c, string d)
11+
{
12+
Preconditions.CheckNotNull(b, "b");
13+
Preconditions.CheckNotNull("c", c);
14+
Preconditions.CheckNotNull(d, "e");
15+
DoSomethingWith(a);
16+
Console.WriteLine(a.Length);
17+
}
18+
19+
private static void DoSomethingWith([NotNull] string a)
20+
{
21+
Preconditions.CheckNotNull(a, "a");
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 Jon Skeet. All rights reserved. Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.
2+
using System;
3+
4+
namespace ProductionCode.Utilities
5+
{
6+
internal static class Preconditions
7+
{
8+
public static T CheckNotNull<T>(T value, string paramName) where T : class
9+
{
10+
if (value == null)
11+
{
12+
throw new ArgumentNullException(paramName);
13+
}
14+
return value;
15+
}
16+
}
17+
}

RoslynTesting/RoslynTesting.sln

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.30501.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductionCode", "ProductionCode\ProductionCode.csproj", "{14988D27-F3F8-4BFD-B0B6-C68ECBD5E4DF}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{CDC97ACD-6DF4-4513-935F-38745205FF5E}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{14988D27-F3F8-4BFD-B0B6-C68ECBD5E4DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{14988D27-F3F8-4BFD-B0B6-C68ECBD5E4DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{14988D27-F3F8-4BFD-B0B6-C68ECBD5E4DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{14988D27-F3F8-4BFD-B0B6-C68ECBD5E4DF}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{CDC97ACD-6DF4-4513-935F-38745205FF5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{CDC97ACD-6DF4-4513-935F-38745205FF5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{CDC97ACD-6DF4-4513-935F-38745205FF5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{CDC97ACD-6DF4-4513-935F-38745205FF5E}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

RoslynTesting/Tests/NotNullTest.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 Jon Skeet. All rights reserved. Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.
2+
using System.Threading.Tasks;
3+
using Microsoft.CodeAnalysis.MSBuild;
4+
using NUnit.Framework;
5+
6+
namespace Tests
7+
{
8+
public class NotNullTest
9+
{
10+
// Tests to write:
11+
// - Every [NotNull] parameter has a check or is used in a call which checks (and is the same name)
12+
// - Every call to Preconditions.CheckNotNull uses a [NotNull] parameter name
13+
// - Every call to Preconditions.CheckNotNull uses a string literal as a parameter name
14+
// - No call to Preconditions.CheckNotNull uses the right parameter as the value
15+
16+
[Test]
17+
public async Task CheckParameters()
18+
{
19+
MSBuildWorkspace workspace = MSBuildWorkspace.Create();
20+
var project = await workspace.OpenProjectAsync("../../../ProductionCode/ProductionCode.csproj");
21+
var compilation = await project.GetCompilationAsync();
22+
// More code to go here...
23+
}
24+
}
25+
}
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("Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2014")]
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("e26454d5-02ca-4564-b256-855b92c36473")]
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")]

RoslynTesting/Tests/Tests.csproj

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{CDC97ACD-6DF4-4513-935F-38745205FF5E}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Tests</RootNamespace>
11+
<AssemblyName>Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Microsoft.CodeAnalysis">
34+
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Microsoft.CodeAnalysis.CSharp">
37+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Microsoft.CodeAnalysis.CSharp.Desktop">
40+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces">
43+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
44+
</Reference>
45+
<Reference Include="Microsoft.CodeAnalysis.Desktop">
46+
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Microsoft.CodeAnalysis.VisualBasic">
49+
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll</HintPath>
50+
</Reference>
51+
<Reference Include="Microsoft.CodeAnalysis.VisualBasic.Desktop">
52+
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Desktop.dll</HintPath>
53+
</Reference>
54+
<Reference Include="Microsoft.CodeAnalysis.Workspaces">
55+
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.0.7.4091001-beta\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
56+
</Reference>
57+
<Reference Include="nunit.framework">
58+
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
59+
</Reference>
60+
<Reference Include="System" />
61+
<Reference Include="System.Collections.Immutable">
62+
<HintPath>..\packages\Microsoft.Bcl.Immutable.1.1.20-beta\lib\portable-net45+win8\System.Collections.Immutable.dll</HintPath>
63+
</Reference>
64+
<Reference Include="System.Core" />
65+
<Reference Include="System.Reflection.Metadata">
66+
<HintPath>..\packages\Microsoft.Bcl.Metadata.1.0.12-alpha\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
67+
</Reference>
68+
<Reference Include="System.Xml.Linq" />
69+
<Reference Include="System.Data.DataSetExtensions" />
70+
<Reference Include="Microsoft.CSharp" />
71+
<Reference Include="System.Data" />
72+
<Reference Include="System.Xml" />
73+
</ItemGroup>
74+
<ItemGroup>
75+
<Compile Include="NotNullTest.cs" />
76+
<Compile Include="Properties\AssemblyInfo.cs" />
77+
</ItemGroup>
78+
<ItemGroup>
79+
<None Include="packages.config" />
80+
</ItemGroup>
81+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
82+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
83+
Other similar extension points exist, see Microsoft.Common.targets.
84+
<Target Name="BeforeBuild">
85+
</Target>
86+
<Target Name="AfterBuild">
87+
</Target>
88+
-->
89+
</Project>

RoslynTesting/Tests/packages.config

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net451" />
4+
<package id="Microsoft.Bcl.Metadata" version="1.0.12-alpha" targetFramework="net451" />
5+
<package id="Microsoft.CodeAnalysis.Common" version="0.7.4091001-beta" targetFramework="net451" />
6+
<package id="Microsoft.CodeAnalysis.Compilers" version="0.7.4091001-beta" targetFramework="net451" />
7+
<package id="Microsoft.CodeAnalysis.CSharp" version="0.7.4091001-beta" targetFramework="net451" />
8+
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="0.7.4091001-beta" targetFramework="net451" />
9+
<package id="Microsoft.CodeAnalysis.VisualBasic" version="0.7.4091001-beta" targetFramework="net451" />
10+
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="0.7.4091001-beta" targetFramework="net451" />
11+
<package id="NUnit" version="2.6.3" targetFramework="net451" />
12+
</packages>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<repositories>
3+
<repository path="..\Tests\packages.config" />
4+
</repositories>

0 commit comments

Comments
 (0)