Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit f9c48a6

Browse files
Merge pull request #56 from 304NotModified/refactor-tests
refactor tests
2 parents 6c81795 + 7af55f1 commit f9c48a6

17 files changed

+378
-388
lines changed

Fody/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
using System.Runtime.CompilerServices;
22

3-
[assembly:InternalsVisibleTo("Tests")]
3+
[assembly:InternalsVisibleTo("Stamp.Fody.Tests")]

Stamp.sln

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.22823.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.271
55
MinimumVisualStudioVersion = 14.0.22823.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fody", "Fody\Fody.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{5A86453B-96FB-4B6E-A283-225BB9F753D3}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stamp.Fody.Tests", "Tests\Stamp.Fody.Tests.csproj", "{5A86453B-96FB-4B6E-A283-225BB9F753D3}"
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssemblyToProcess", "AssemblyToProcess\AssemblyToProcess.csproj", "{7DEC4E2D-F872-434E-A267-0BAD65299950}"
1111
EndProject
@@ -47,4 +47,7 @@ Global
4747
GlobalSection(SolutionProperties) = preSolution
4848
HideSolutionNode = FALSE
4949
EndGlobalSection
50+
GlobalSection(ExtensibilityGlobals) = postSolution
51+
SolutionGuid = {AACBE31E-CB8A-4D16-88A8-B48F962C99F8}
52+
EndGlobalSection
5053
EndGlobal

Tests/AssemblyLocation.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

Tests/ExistingTests.cs

Lines changed: 0 additions & 94 deletions
This file was deleted.

Tests/GitTests.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

Tests/Helpers/AssemblyLocation.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Stamp.Fody.Tests
2+
{
3+
using System;
4+
using System.IO;
5+
6+
public static class AssemblyLocation
7+
{
8+
public static string CurrentDirectory()
9+
{
10+
var assembly = typeof(AssemblyLocation).Assembly;
11+
var uri = new UriBuilder(assembly.CodeBase);
12+
var path = Uri.UnescapeDataString(uri.Path);
13+
14+
return Path.GetDirectoryName(path);
15+
}
16+
}
17+
}

Tests/Helpers/Verifier.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
namespace Stamp.Fody.Tests
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Text.RegularExpressions;
7+
using NUnit.Framework;
8+
9+
public static class Verifier
10+
{
11+
public static void Verify(string beforeAssemblyPath, string afterAssemblyPath)
12+
{
13+
var before = Validate(beforeAssemblyPath);
14+
var after = Validate(afterAssemblyPath);
15+
var message = $"Failed processing {Path.GetFileName(afterAssemblyPath)}\r\n{after}";
16+
Assert.AreEqual(TrimLineNumbers(before), TrimLineNumbers(after), message);
17+
}
18+
19+
private static string Validate(string assemblyPath2)
20+
{
21+
var exePath = GetPathToPeVerify();
22+
if (!File.Exists(exePath))
23+
{
24+
return string.Empty;
25+
}
26+
var process = Process.Start(new ProcessStartInfo(exePath, "\"" + assemblyPath2 + "\"")
27+
{
28+
RedirectStandardOutput = true,
29+
UseShellExecute = false,
30+
CreateNoWindow = true
31+
});
32+
33+
process.WaitForExit(10000);
34+
return process.StandardOutput.ReadToEnd().Trim().Replace(assemblyPath2, "");
35+
}
36+
37+
private static string GetPathToPeVerify()
38+
{
39+
var exePath = Environment.ExpandEnvironmentVariables(@"%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\PEVerify.exe");
40+
41+
if (!File.Exists(exePath))
42+
{
43+
exePath = Environment.ExpandEnvironmentVariables(@"%programfiles(x86)%\Microsoft SDKs\Windows\v8.0A\Bin\NETFX 4.0 Tools\PEVerify.exe");
44+
}
45+
return exePath;
46+
}
47+
48+
private static string TrimLineNumbers(string foo)
49+
{
50+
return Regex.Replace(foo, @"0x.*]", "");
51+
}
52+
}
53+
}

Tests/IntegrationTests/GitTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace Stamp.Fody.Tests
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using LibGit2Sharp;
6+
using NUnit.Framework;
7+
using Stamp.Fody.Internal;
8+
9+
[TestFixture]
10+
public class GitTests
11+
{
12+
[Test]
13+
[Explicit]
14+
public void Foo()
15+
{
16+
using (var repo = new Repository(Repository.Discover(TestContext.CurrentContext.TestDirectory)))
17+
{
18+
var repositoryStatus = repo.RetrieveStatus();
19+
var clean =
20+
repositoryStatus.Added.IsEmpty() &&
21+
repositoryStatus.Missing.IsEmpty() &&
22+
repositoryStatus.Modified.IsEmpty() &&
23+
repositoryStatus.Removed.IsEmpty() &&
24+
repositoryStatus.Staged.IsEmpty();
25+
Trace.WriteLine(clean);
26+
Trace.WriteLine(repo.Head.FriendlyName);
27+
Trace.WriteLine(repo.Head.Tip.Sha);
28+
}
29+
}
30+
}
31+
}

Tests/PatchAssemblyTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Stamp.Fody.Tests
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using NUnit.Framework;
6+
7+
public class PatchAssemblyTests : PatchAssemblyTestsBase
8+
{
9+
public PatchAssemblyTests() : base("AssemblyToProcess")
10+
{
11+
}
12+
13+
protected override void AssertVersion(string version)
14+
{
15+
Assert.IsNotNull(version);
16+
Assert.IsNotEmpty(version);
17+
StringAssert.Contains("1.0.0.0", version, "Missing number");
18+
StringAssert.Contains("Head:", version, "Missing Head");
19+
StringAssert.Contains("Sha:", version, "Missing Sha");
20+
Trace.WriteLine(version);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)