committed by
GitHub
7 changed files with 105 additions and 4 deletions
@ -0,0 +1,51 @@ |
|||
using System; |
|||
using System.ComponentModel; |
|||
using Microsoft.CodeAnalysis; |
|||
using Microsoft.CodeAnalysis.CSharp; |
|||
using XamlNameReferenceGenerator.Infrastructure; |
|||
using XamlX; |
|||
using XamlX.Parsers; |
|||
using Xunit; |
|||
|
|||
namespace XamlNameReferenceGenerator.Tests |
|||
{ |
|||
public class MiniCompilerTests |
|||
{ |
|||
private const string MiniClass = "namespace Example { public class Valid { public int Foo() => 21; } }"; |
|||
private const string MiniInvalidXaml = "<Invalid xmlns='clr-namespace:Example;assembly=Example' />"; |
|||
private const string MiniValidXaml = "<Valid xmlns='clr-namespace:Example;assembly=Example' />"; |
|||
|
|||
[Fact] |
|||
public void Should_Resolve_Types_From_Valid_Xaml_Markup() |
|||
{ |
|||
var xaml = XDocumentXamlParser.Parse(MiniValidXaml); |
|||
var compilation = CreateBasicCompilation(MiniClass, "Example"); |
|||
|
|||
MiniCompiler |
|||
.CreateDefault(new RoslynTypeSystem(compilation)) |
|||
.Transform(xaml); |
|||
|
|||
Assert.NotNull(xaml.Root); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Throw_When_Unable_To_Resolve_Types() |
|||
{ |
|||
var xaml = XDocumentXamlParser.Parse(MiniInvalidXaml); |
|||
var compilation = CreateBasicCompilation(MiniClass, "Example"); |
|||
var compiler = MiniCompiler.CreateDefault(new RoslynTypeSystem(compilation)); |
|||
|
|||
Assert.Throws<XamlParseException>(() => compiler.Transform(xaml)); |
|||
} |
|||
|
|||
private static CSharpCompilation CreateBasicCompilation(string source, string name) => |
|||
CSharpCompilation |
|||
.Create(name, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)) |
|||
.AddReferences(MetadataReference.CreateFromFile(typeof(string).Assembly.Location)) |
|||
.AddReferences(MetadataReference.CreateFromFile(typeof(IServiceProvider).Assembly.Location)) |
|||
.AddReferences(MetadataReference.CreateFromFile(typeof(ITypeDescriptorContext).Assembly.Location)) |
|||
.AddReferences(MetadataReference.CreateFromFile(typeof(ISupportInitialize).Assembly.Location)) |
|||
.AddReferences(MetadataReference.CreateFromFile(typeof(TypeConverterAttribute).Assembly.Location)) |
|||
.AddSyntaxTrees(CSharpSyntaxTree.ParseText(source)); |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net5</TargetFramework> |
|||
<LangVersion>preview</LangVersion> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-3.final" /> |
|||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0" /> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> |
|||
<PackageReference Include="xunit" Version="2.4.1" /> |
|||
<PackageReference Include="xunit.runner.console" Version="2.4.1" /> |
|||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="Avalonia" Version="0.10.0-preview5" /> |
|||
<PackageReference Include="Avalonia.Desktop" Version="0.10.0-preview5" /> |
|||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0-preview5" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="../XamlNameReferenceGenerator/XamlNameReferenceGenerator.csproj" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -0,0 +1,13 @@ |
|||
using Xunit; |
|||
|
|||
namespace XamlNameReferenceGenerator.Tests |
|||
{ |
|||
public class XamlXNameReferenceXamlParserTests |
|||
{ |
|||
[Fact] |
|||
public void Should_Resolve_Named_Controls_From_Xaml_Markup() |
|||
{ |
|||
// TODO: Fix all stuff.
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue