Fixed TryFindProxyDataByTypeName (#30)

* pnp

* .

* .

* okee

* ns

* .

* o

* .

* ,

* x

* t

* co

* .

* r

* CastTo
This commit is contained in:
Stef Heyenrath
2022-02-06 11:14:14 +01:00
committed by GitHub
parent 9024b5f42c
commit b995ac3912
35 changed files with 2361 additions and 157 deletions
@@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
using CSharp.SourceGenerators.Extensions;
using CSharp.SourceGenerators.Extensions.Models;
using FluentAssertions;
@@ -65,7 +66,7 @@ namespace ProxyInterfaceSourceGeneratorTests
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = new [] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.PersonExtends)", "true" }
ArgumentList = new[] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.PersonExtends)", "true" }
}
};
@@ -138,8 +139,6 @@ namespace ProxyInterfaceSourceGeneratorTests
result.Valid.Should().BeTrue();
result.Files.Should().HaveCount(5);
// throw new Exception();
// Assert attribute
var attribute = result.Files[0].SyntaxTree;
attribute.FilePath.Should().EndWith(attributeFilename);
@@ -180,5 +179,93 @@ namespace ProxyInterfaceSourceGeneratorTests
if (Write) File.WriteAllText($"../../../Destination/{proxyClassPersonFilename}", proxyCode);
proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassPersonFilename}"));
}
[Fact]
public void GenerateFiles_ForPnP_Should_GenerateCorrectFiles()
{
// Arrange
var fileNames = new[]
{
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientObject.g.cs",
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs",
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext.g.cs",
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs",
"Microsoft.SharePoint.Client.ClientObjectProxy.g.cs",
"Microsoft.SharePoint.Client.WebProxy.g.cs",
"Microsoft.SharePoint.Client.ClientRuntimeContextProxy.g.cs",
"Microsoft.SharePoint.Client.ClientContextProxy.g.cs"
};
var pathClientObject = "./Source/PnP/IClientObject.cs";
var sourceFileClientObject = new SourceFile
{
Path = pathClientObject,
Text = File.ReadAllText(pathClientObject),
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = "typeof(Microsoft.SharePoint.Client.ClientObject)"
}
};
var pathWeb = "./Source/PnP/IWeb.cs";
var sourceFileWeb = new SourceFile
{
Path = pathWeb,
Text = File.ReadAllText(pathWeb),
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = "typeof(Web)" // Only name, no namespace
}
};
var pathClientRuntimeContext = "./Source/Pnp/IClientRuntimeContext.cs";
var sourceFileClientRuntimeContext = new SourceFile
{
Path = pathClientRuntimeContext,
Text = File.ReadAllText(pathClientRuntimeContext),
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = "typeof(Microsoft.SharePoint.Client.ClientRuntimeContext)"
}
};
var pathClientContext = "./Source/PnP/IClientContext.cs";
var sourceFileClientContext = new SourceFile
{
Path = pathClientContext,
Text = File.ReadAllText(pathClientContext),
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = "typeof(ClientContext)" // Only name, no namespace
}
};
// Act
var result = _sut.Execute(new[]
{
sourceFileClientObject,
sourceFileWeb,
sourceFileClientRuntimeContext,
sourceFileClientContext
});
// 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}"));
}
}
}
}