Files
2024-05-17 11:58:54 +01:00

71 lines
1.8 KiB
C#

using System;
using System.Runtime.CompilerServices;
using FluentAssertions;
using Xunit;
namespace Speckle.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))
?? throw new InvalidOperationException();
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();
}
[Fact]
public void Deconstruct_IsGenerated()
{
var method = typeof(ITestRecord).GetMethod(nameof(TestRecord.Deconstruct));
method.Should().NotBeNull();
method?.ReturnType.Should().Be(typeof(void));
var parameters = method?.GetParameters() ?? throw new InvalidOperationException();
parameters.Length.Should().Be(1);
var parameter = parameters[0];
parameter.ParameterType.Should().Be(typeof(int).MakeByRefType());
parameter.IsOut.Should().BeTrue();
}
}
[GenerateAutoInterface]
internal record TestRecord(int RecordProperty) : ITestRecord
{
public void RecordMethod() { }
}