Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions NosePlug.Tests/NasalInstanceMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,22 @@ public async Task InstanceMethod_WithIncorrectThisParameterAndParameter_ThrowsEx
Assert.Equal("Plug for NosePlug.Tests.TestClasses.HasInstanceMethods.VoidMethodWithParameter has parameters (System.String, System.String) that do not match original method parameters (NosePlug.Tests.TestClasses.HasInstanceMethods this, System.String)", ex.Message);
}

[Fact]
public async Task InstanceMethod_WithPrivateMethod_CanBePlugged()
{
int invocationCount = 0;

//[Fact]
//public async Task InstanceMethod_WithPrivateMethod_CanBePlugged()
//{
// int invocationCount = 0;

// HasInstanceMethods sut = new();

// IInstanceMethodPlug noParamsPlug = Nasal.InstanceMethod<HasInstanceMethods>("NoParameters")
// .Callback((HasInstanceMethods _) => invocationCount++);
HasInstanceMethods sut = new();

// using IDisposable _ = await Nasal.ApplyAsync(noParamsPlug);
IInstanceMethodPlug noParamsPlug = Nasal.InstanceMethod<HasInstanceMethods>("NoParameters")
.Callback((HasInstanceMethods _) => invocationCount++);

// sut.InvokeNoParameters();
using IDisposable _ = await Nasal.ApplyAsync(noParamsPlug);

// Assert.Equal(1, invocationCount);
//}
sut.InvokeNoParameters();

Assert.Equal(1, invocationCount);
}

[Fact]
public async Task InstanceMethod_WithReturnValue_CanBePlugged()
Expand Down Expand Up @@ -195,4 +193,18 @@ public async Task InstanceMethod_WithBaseClassForThisParameter_CanBePlugged()

Assert.True(wasCalled);
}

[Fact]
public async Task InstanceMethod_WithTimeZoneInfoIsDaylightSavingTime_CanBePlugged()
{
IInstanceMethodPlug<bool> methodPlug = Nasal
.InstanceMethod<TimeZoneInfo, bool>(x => x.IsDaylightSavingTime(DateTime.UtcNow))
.Returns<TimeZoneInfo, DateTime>((_, _) => true);

using var _ = await Nasal.ApplyAsync(methodPlug);

bool isDst = TimeZoneInfo.Utc.IsDaylightSavingTime(DateTime.UtcNow);

Assert.True(isDst);
}
}
6 changes: 6 additions & 0 deletions NosePlug.lutconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<LUTConfig Version="1.0">
<Repository />
<ParallelBuilds>true</ParallelBuilds>
<ParallelTestRuns>true</ParallelTestRuns>
<TestCaseTimeout>180000</TestCaseTimeout>
</LUTConfig>
1 change: 1 addition & 0 deletions NosePlug.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{7082241A-9D8B-4A38-9419-1A18435E6EA9}"
ProjectSection(SolutionItems) = preProject
.github\dependabot.yml = .github\dependabot.yml
.github\workflows\dotnet-core.yml = .github\workflows\dotnet-core.yml
.github\RELEASE.yaml = .github\RELEASE.yaml
EndProjectSection
Expand Down
5 changes: 2 additions & 3 deletions NosePlug/NosePlug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="../Shims/HashCode.cs"
Condition="$(TargetFramework) == 'net472' Or $(TargetFramework) == 'net48' " />
<Compile Include="../Shims/HashCode.cs" Condition="$(TargetFramework) == 'net472' Or $(TargetFramework) == 'net48' " />
</ItemGroup>

<ItemGroup>
<CompilerVisibleProperty Include="SourceGenerator_EnableDebug" />

<PackageReference Include="Lib.Harmony" Version="2.2.0" />
<PackageReference Include="Lib.Harmony" Version="2.2.2" />

<ProjectReference Include="../NosePlug.Generators/NosePlug.Generators.csproj">
<OutputItemType>Analyzer</OutputItemType>
Expand Down