Add support for implicit and explicit operators (#51)

* .

* xxxxxxxx

* rev

* ....

* .

* ok

* 2

* .

* ,
This commit is contained in:
Stef Heyenrath
2023-01-09 21:06:30 +01:00
committed by GitHub
parent da40aae293
commit 106385a466
21 changed files with 288 additions and 2 deletions
@@ -88,6 +88,63 @@ namespace ProxyInterfaceSourceGeneratorTests
}
}
[Fact]
public void GenerateFiles_ForClassWithOperator_Should_GenerateCorrectFiles()
{
// Arrange
var fileNames = new[]
{
"ProxyInterfaceSourceGeneratorTests.Source.IOperatorTest.g.cs",
"ProxyInterfaceSourceGeneratorTests.Source.OperatorTestProxy.g.cs"
};
var path = "./Source/IOperatorTest.cs";
var sourceFile = new SourceFile
{
Path = path,
Text = File.ReadAllText(path),
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.OperatorTest)"
}
};
// Act
var result = _sut.Execute(new[]
{
sourceFile
});
// Assert
result.Valid.Should().BeTrue();
result.Files.Should().HaveCount(fileNames.Length + 1);
foreach (var fileName in fileNames.Select((fileName, index) => new { fileName, index }))
{
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
builder.Path.Should().EndWith(fileName.fileName);
if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text);
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}"));
}
var name = "stef";
var operatorTest = new OperatorTest
{
Name = name
};
string name1 = (string) operatorTest;
name1.Should().Be(name);
var p = new OperatorTestProxy(operatorTest);
string name2 = (string)p;
name2.Should().Be(name);
var p2 = (OperatorTestProxy)name;
p2.Should().BeEquivalentTo(new OperatorTestProxy(operatorTest));
}
[Fact]
public void GenerateFiles_When_NoNamespace_Should_GenerateCorrectFiles()
{