forked from CosmosOS/Cosmos
-
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.
Add test project and solution fpr ILSpy plugin
- Loading branch information
1 parent
da440ff
commit 19b186b
Showing
12 changed files
with
251 additions
and
104 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,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29709.97 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpyPlugAddIn", "ILSpyPlugAddIn\ILSpyPlugAddIn.csproj", "{08FE791B-5864-4E6F-AF7B-A02742C9C764}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpyPlugAddin.Tests", "ILSpyPlugAddin.Tests\ILSpyPlugAddin.Tests\ILSpyPlugAddin.Tests.csproj", "{573518BB-28C4-47DC-81A1-1C1FECDD87D3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{08FE791B-5864-4E6F-AF7B-A02742C9C764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{08FE791B-5864-4E6F-AF7B-A02742C9C764}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{08FE791B-5864-4E6F-AF7B-A02742C9C764}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{08FE791B-5864-4E6F-AF7B-A02742C9C764}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{573518BB-28C4-47DC-81A1-1C1FECDD87D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{573518BB-28C4-47DC-81A1-1C1FECDD87D3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{573518BB-28C4-47DC-81A1-1C1FECDD87D3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{573518BB-28C4-47DC-81A1-1C1FECDD87D3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {DFF6D834-D4FF-4981-A1E0-E087501A6E36} | ||
EndGlobalSection | ||
EndGlobal |
29 changes: 29 additions & 0 deletions
29
Tools/ILSpyPlugAddIn/ILSpyPlugAddin.Tests/ILSpyPlugAddin.Tests/ILSpyPlugAddin.Tests.csproj
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>net46</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="nunit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ILSpyReference Include="ICSharpCode.TreeView.dll" /> | ||
<ILSpyReference Include="ILSpy.exe" /> | ||
<ILSpyReference Include="Mono.Cecil.dll" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\ILSpyPlugAddIn\ILSpyPlugAddIn.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="@(ILSpyReference)" HintPath="$(RepoRoot)Resources\Dependencies\ILSpy\%(Identity)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
87 changes: 87 additions & 0 deletions
87
Tools/ILSpyPlugAddIn/ILSpyPlugAddin.Tests/ILSpyPlugAddin.Tests/UtilitiesTests.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,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cosmos.ILSpyPlugs.Plugin; | ||
using ICSharpCode.ILSpy; | ||
using Mono.Cecil; | ||
using NUnit.Framework; | ||
|
||
namespace ILSpyPlugAddin.Tests | ||
{ | ||
public class UtilitiesTests | ||
{ | ||
[Test] | ||
public void ReturnsExpectedFieldAccessString() | ||
{ | ||
var moduleDefinition = CreateTestModuleDefinition(); | ||
var typeDefinition = CreateTestTypeDefinition(); | ||
var fieldDefinition = CreateTestFieldDefinition(); | ||
typeDefinition.Fields.Add(fieldDefinition); | ||
moduleDefinition.Types.Add(typeDefinition); | ||
|
||
string expected = "[FieldAccess(Name = \"TestNamespace.TestFieldType TestNamespace.TestType.TestField\")] ref [TestAssembly]TestNamespace.TestFieldType fieldTestField"; | ||
string actual = Utilities.GenerateFieldAccessPlugEntry(fieldDefinition); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
public void ReturnsExpectedTypePlugEntry() | ||
{ | ||
var typeDefinition = new TypeDefinition("TestNamespace", "TestType", TypeAttributes.Public); | ||
|
||
var moduleDefinition = ModuleDefinition.CreateModule("TestModule", ModuleKind.Dll); | ||
moduleDefinition.Types.Add(typeDefinition); | ||
|
||
string expected = "[Plug(Target = typeof(global::TestNamespace.TestType))]\r\npublic static class TestTypeImpl\r\n{\r\n}\r\n"; | ||
string actual = Utilities.GenerateTypePlugEntry(typeDefinition); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
public void ReturnsExpectedMethodPlugEntry() | ||
{ | ||
var moduleDefinition = CreateTestModuleDefinition(); | ||
var typeDefinition = CreateTestTypeDefinition(); | ||
var methodDefinition = CreateTestMethodDefinition(); | ||
typeDefinition.Methods.Add(methodDefinition); | ||
moduleDefinition.Types.Add(typeDefinition); | ||
|
||
string expected = "public static [TestAssembly]TestNamespace.TestFieldType TestMethod(TestNamespace.TestType aThis)\r\n{\r\n}\r\n"; | ||
string actual = Utilities.GenerateMethodPlugEntry(methodDefinition); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
private static ModuleDefinition CreateTestModuleDefinition() | ||
{ | ||
var definition = ModuleDefinition.CreateModule("TestModule", ModuleKind.Dll); | ||
return definition; | ||
} | ||
|
||
private static TypeDefinition CreateTestTypeDefinition() | ||
{ | ||
var definition = new TypeDefinition("TestNamespace", "TestType", TypeAttributes.Public); | ||
return definition; | ||
} | ||
|
||
private static TypeReference CreateTestTypeReference() | ||
{ | ||
var module = CreateTestModuleDefinition(); | ||
var reference = new TypeReference("TestNamespace", "TestFieldType", module, new AssemblyNameDefinition("TestAssembly", new Version())); | ||
return reference; | ||
} | ||
|
||
private static FieldDefinition CreateTestFieldDefinition() | ||
{ | ||
var typeReference = CreateTestTypeReference(); | ||
var definition = new FieldDefinition("TestField", FieldAttributes.Public, typeReference); | ||
return definition; | ||
} | ||
|
||
public static MethodDefinition CreateTestMethodDefinition() | ||
{ | ||
var returnType = CreateTestTypeReference(); | ||
var definition = new MethodDefinition("TestMethod", MethodAttributes.Public, returnType); | ||
return definition; | ||
} | ||
} | ||
} |
File renamed without changes.
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
53 changes: 53 additions & 0 deletions
53
Tools/ILSpyPlugAddIn/ILSpyPlugAddin/GenerateMethodPlugEntry.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,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using ICSharpCode.ILSpy; | ||
using ICSharpCode.ILSpy.TreeNodes; | ||
using Mono.Cecil; | ||
|
||
namespace Cosmos.ILSpyPlugs.Plugin | ||
{ | ||
[ExportContextMenuEntry(Header = "Cosmos Plug: Generate method plug")] | ||
public class GenerateMethodPlugEntry: BaseContextMenuEntry | ||
{ | ||
public override bool IsVisible(TextViewContext context) | ||
{ | ||
if (context?.SelectedTreeNodes != null) | ||
{ | ||
foreach (var node in context.SelectedTreeNodes) | ||
{ | ||
var xCurrentMethod = node as MethodTreeNode; | ||
if (xCurrentMethod != null) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public override void Execute(TextViewContext context) | ||
{ | ||
if (MessageBox.Show("Do you want to generate plug code to your clipboard?", "Cosmos Plug tool", MessageBoxButton.YesNo) == MessageBoxResult.No) | ||
{ | ||
return; | ||
} | ||
|
||
StringBuilder xString = new StringBuilder(); | ||
foreach (var node in context.SelectedTreeNodes) | ||
{ | ||
var xCurrentMethod = node as MethodTreeNode; | ||
xString.Append(Utilities.GenerateMethodPlugEntry(xCurrentMethod.MethodDefinition)); | ||
xString.AppendLine(); | ||
} | ||
|
||
Clipboard.SetText(xString.ToString()); | ||
|
||
MessageBox.Show("Done", "Cosmos Plug tool"); | ||
} | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.