Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,38 @@ public override int this[int index]
""").IgnoringNewlineStyle();
}

[Fact]
public async Task ShouldNotCallBaseForAbstractIndexersOfAbstractClasses()
{
GeneratorResult result = Generator
.Run("""
using Mockolate;

namespace MyCode;
public class Program
{
public static void Main(string[] args)
{
_ = MyAbstractService.CreateMock();
}
}

public abstract class MyAbstractService
{
public abstract object this[int index] { get; }
public abstract int this[string key] { get; set; }
}
""");

await That(result.Diagnostics).IsEmpty();
await That(result.Sources).ContainsKey("Mock.MyAbstractService.g.cs");
await That(result.Sources["Mock.MyAbstractService.g.cs"])
.Contains("public override object this[int index]").And
.Contains("public override int this[string key]").And
.DoesNotContain("base[")
.Because("abstract indexers have no base implementation to call (CS0205)");
}

[Fact]
public async Task ShouldSupportSpanAndReadOnlySpanIndexerParameters()
{
Expand Down
15 changes: 15 additions & 0 deletions Tests/Mockolate.Tests/ReturnsThrowsAsyncExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ public async Task ReturnsAsync_WithParameters_ReturnsConfiguredValue()

await That(result).IsEqualTo(42);
}

[Fact]
public async Task Returns_TaskFactory_ShouldReturnPendingTaskAsIs()
{
TaskCompletionSource<int> completionSource = new();
IReturnsAsyncExtensionsSetupTest sut = IReturnsAsyncExtensionsSetupTest.CreateMock();
sut.Mock.Setup.Method0().Returns(() => completionSource.Task);

Task<int> result = sut.Method0();

await That(result.IsCompleted).IsFalse()
.Because("the factory's task must be handed to the caller as-is, so it can be raced against timeouts or cancellation");
completionSource.SetResult(42);
await That(await result).IsEqualTo(42);
}
}

#if NET8_0_OR_GREATER
Expand Down
Loading