Skip to content

Commit

Permalink
CodeVerifier for #18
Browse files Browse the repository at this point in the history
  • Loading branch information
veblush committed May 17, 2016
1 parent 5035cef commit 2fdfc1a
Show file tree
Hide file tree
Showing 24 changed files with 940 additions and 4 deletions.
36 changes: 36 additions & 0 deletions Akka.Interfaced.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Basic.Interface", "samples\
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Basic.Program", "samples\Basic\Program\Basic.Program.csproj", "{3E04D2BF-DE54-4608-9E5D-98596F943AE2}"
ProjectSection(ProjectDependencies) = postProject
{290774D5-43FB-4F0C-AF75-5615A8370547} = {290774D5-43FB-4F0C-AF75-5615A8370547}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample-SlimHttp", "Sample-SlimHttp", "{02565A03-B570-401D-8796-F84DE193F194}"
EndProject
Expand All @@ -41,6 +44,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld.Interface", "sam
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld.Program", "samples\HelloWorld\Program\HelloWorld.Program.csproj", "{DEF6B954-981A-4B94-BED5-539D37A86B4E}"
ProjectSection(ProjectDependencies) = postProject
{290774D5-43FB-4F0C-AF75-5615A8370547} = {290774D5-43FB-4F0C-AF75-5615A8370547}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample-Protobuf", "Sample-Protobuf", "{68FB30CB-4812-4893-8CA1-D53C08AD06D7}"
EndProject
Expand Down Expand Up @@ -118,6 +124,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Interfaced.ProtobufSer
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Interfaced.TestKit.Tests", "plugins\Akka.Interfaced.TestKit.Tests\Akka.Interfaced.TestKit.Tests.csproj", "{EC828D56-8C88-49EF-9716-68B2663A7F81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeVerifier", "core\CodeVerifier\CodeVerifier.csproj", "{290774D5-43FB-4F0C-AF75-5615A8370547}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeVerifier.Tests", "core\CodeVerifier.Tests\CodeVerifier.Tests.csproj", "{2137109B-6ACF-43CC-834A-19064FD784B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -484,6 +494,30 @@ Global
{EC828D56-8C88-49EF-9716-68B2663A7F81}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EC828D56-8C88-49EF-9716-68B2663A7F81}.Release|Win32.ActiveCfg = Release|Any CPU
{EC828D56-8C88-49EF-9716-68B2663A7F81}.Release|Win32.Build.0 = Release|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Debug|Any CPU.Build.0 = Debug|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Debug|Win32.ActiveCfg = Debug|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Debug|Win32.Build.0 = Debug|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Release|Any CPU.ActiveCfg = Release|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Release|Any CPU.Build.0 = Release|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Release|Win32.ActiveCfg = Release|Any CPU
{290774D5-43FB-4F0C-AF75-5615A8370547}.Release|Win32.Build.0 = Release|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Debug|Win32.ActiveCfg = Debug|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Debug|Win32.Build.0 = Debug|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Release|Any CPU.Build.0 = Release|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Release|Win32.ActiveCfg = Release|Any CPU
{2137109B-6ACF-43CC-834A-19064FD784B6}.Release|Win32.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -521,5 +555,7 @@ Global
{91EA29B0-8DE7-49FB-BBFB-7A73F28987F4} = {558DE237-AC05-41A5-AA45-2084614D95D3}
{63708BDC-9285-4F67-A1D8-237A5D77ABDD} = {558DE237-AC05-41A5-AA45-2084614D95D3}
{EC828D56-8C88-49EF-9716-68B2663A7F81} = {558DE237-AC05-41A5-AA45-2084614D95D3}
{290774D5-43FB-4F0C-AF75-5615A8370547} = {1A90348B-9EF5-475B-83D8-9D4F385BA8B5}
{2137109B-6ACF-43CC-834A-19064FD784B6} = {1A90348B-9EF5-475B-83D8-9D4F385BA8B5}
EndGlobalSection
EndGlobal
5 changes: 5 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ let solution =
[ ("Akka.Interfaced-SlimClient", "")
("protobuf-net", "2.0.0.668")
("TypeAlias", "1.1.2") ] }
{ // CodeVerifier
emptyProject with Name = "Akka.Interfaced.CodeVerifier"
Folder = "./core/CodeVerifier"
Template = true
Dependencies = [ ] }
{ // Plugins
emptyProject with Name = "Akka.Interfaced.LogFilter"
Folder = "./plugins/Akka.Interfaced.LogFilter"
Expand Down
5 changes: 3 additions & 2 deletions core/Akka.Interfaced/ExtendedHandlerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ namespace Akka.Interfaced
public class ExtendedHandlerAttribute : Attribute
{
public Type Type;
public string Method;

public ExtendedHandlerAttribute()
{
Type = null;
}

public ExtendedHandlerAttribute(Type interfaceType)
public ExtendedHandlerAttribute(Type interfaceType, string method = null)
{
Type = interfaceType;
Method = method;
}
}
}
17 changes: 15 additions & 2 deletions core/Akka.Interfaced/RequestHandlerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,21 @@ private void BuildExtendedInterfaceHandler()
MethodInfo targetMethod = null;
foreach (var method in targetMethods)
{
if (method.Item1.Name == name && (method.Item2.Type == null || method.Item2.Type == ifs) &&
AreParameterTypesEqual(method.Item1.GetParameters(), parameters))
if (method.Item2.Type != null || method.Item2.Method != null)
{
// check tagged method
if (method.Item2.Type != null && method.Item2.Type != ifs)
continue;
if (method.Item2.Method != null && method.Item2.Method != name)
continue;
}
else if (method.Item1.Name != name)
{
// check method
continue;
}

if (AreParameterTypesEqual(method.Item1.GetParameters(), parameters))
{
if (targetMethod != null)
{
Expand Down
132 changes: 132 additions & 0 deletions core/CodeVerifier.Tests/CodeVerifier.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
<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>{2137109B-6ACF-43CC-834A-19064FD784B6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CodeVerifier.Tests</RootNamespace>
<AssemblyName>CodeVerifier.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<CodeAnalysisRuleSet>..\..\CodeAnalysis.ruleset</CodeAnalysisRuleSet>
</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>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemGroup>
<Reference Include="Akka, Version=1.0.8.24, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Akka.1.0.8\lib\net45\Akka.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ExtendedInterfaceVerifierTest.cs" />
<Compile Include="ExtendedInterfaceVerifierTestTypes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Akka.Interfaced-Base\Akka.Interfaced-Base.csproj">
<Project>{c0d22336-c49e-4245-b39d-0b3083c28205}</Project>
<Name>Akka.Interfaced-Base</Name>
</ProjectReference>
<ProjectReference Include="..\Akka.Interfaced\Akka.Interfaced.csproj">
<Project>{5cbda46b-b22c-474a-8b99-e2e855a8bca8}</Project>
<Name>Akka.Interfaced</Name>
</ProjectReference>
<ProjectReference Include="..\CodeVerifier\CodeVerifier.csproj">
<Project>{290774d5-43fb-4f0c-af75-5615a8370547}</Project>
<Name>CodeVerifier</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.0\analyzers\dotnet\cs\Newtonsoft.Json.dll" />
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.0\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.0\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- 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>
56 changes: 56 additions & 0 deletions core/CodeVerifier.Tests/ExtendedInterfaceVerifierTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Xunit;

namespace CodeVerifier.Tests
{
public class ExtendedInterfaceVerifierTest
{
private AssemblyGroup GetAssemblyGroup()
{
return new AssemblyGroup(typeof(ExtendedInterfaceVerifierTest).Assembly.Location);
}

private ExtendedInterfaceVerifier CreateVerifierAndTest(string testClassName)
{
var asmGroup = GetAssemblyGroup();
var verifier = new ExtendedInterfaceVerifier(new Options());
verifier.Verify(asmGroup, "CodeVerifier.Tests." + testClassName);
return verifier;
}

[Fact]
public void Test_MethodCompleted_Succeed()
{
var verifier = CreateVerifierAndTest(nameof(ExtendedClass_MethodCompleted));
Assert.Equal(1, verifier.VerifiedTypes.Count);
Assert.Equal(0, verifier.Errors.Count);
}

[Fact]
public void Test_MethodMissing_Fail()
{
var verifier = CreateVerifierAndTest(nameof(ExtendedClass_MethodMissing));
Assert.Equal(1, verifier.VerifiedTypes.Count);
Assert.Equal(
new[] { "Cannot find handler for CodeVerifier.Tests.IFoo.Hello" },
verifier.Errors);
}

[Fact]
public void Test_MethoRedundant_Fail()
{
var verifier = CreateVerifierAndTest(nameof(ExtendedClass_MethodRedundant));
Assert.Equal(1, verifier.VerifiedTypes.Count);
Assert.Equal(
new[] { "Unused extended handler: CodeVerifier.Tests.ExtendedClass_MethodRedundant.Bye" },
verifier.Errors);
}

[Fact]
public void Test_ExplicitMethodCompleted_Succeed()
{
var verifier = CreateVerifierAndTest(nameof(ExtendedClass_ExplicitMethodCompleted));
Assert.Equal(1, verifier.VerifiedTypes.Count);
Assert.Equal(0, verifier.Errors.Count);
}
}
}
Loading

0 comments on commit 2fdfc1a

Please sign in to comment.