added support for records

This commit is contained in:
daver32
2021-08-15 14:41:36 +02:00
parent ce722408cf
commit 2b1f8af5a3
3 changed files with 75 additions and 10 deletions
@@ -0,0 +1,54 @@
using System.Runtime.CompilerServices;
using FluentAssertions;
using Xunit;
namespace InterfaceGenerator.Tests
{
public class RecordInterfaceGenerationTests
{
private readonly ITestRecord _sut;
public RecordInterfaceGenerationTests()
{
_sut = new TestRecord(420);
}
[Fact]
public void RecordProperty_IsGenerated()
{
var prop = typeof(ITestRecord)
.GetProperty(nameof(TestRecord.RecordProperty));
prop.Should().NotBeNull();
prop.GetMethod.Should().NotBeNull();
prop.SetMethod.Should().NotBeNull();
prop.SetMethod.ReturnParameter.GetRequiredCustomModifiers().Should().Contain(typeof(IsExternalInit));
_sut.RecordProperty.Should().Be(420);
}
[Fact]
public void RecordMethod_IsGenerated()
{
var method = typeof(ITestRecord).GetMethod(
nameof(TestRecord.RecordMethod));
method.Should().NotBeNull();
method.ReturnType.Should().Be(typeof(void));
var parameters = method.GetParameters();
parameters.Should().BeEmpty();
_sut.RecordMethod();
}
}
[GenerateAutoInterface]
internal record TestRecord(int RecordProperty) : ITestRecord
{
public void RecordMethod()
{
}
}
}