예제 #1
0
        public async Task Returns_ReadJsonPatchAsync_Types()
        {
            string code = @"
using LaDeak.JsonMergePatch.Http;
public class Controller
{
    public class SomeType { }
    public async System.Threading.Tasks.Task TestMethodAsync()
    {
        var client = new System.Net.Http.HttpClient();
        var response = await client.GetAsync(""https://test.com"");
        await response.Content.ReadJsonPatchAsync<SomeType>();
    }
}";

            var compilation = SourceBuilder.Compile(code, new[] {
                MetadataReference.CreateFromFile(typeof(PatchParameterWalkerTests).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Patch <>).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(HttpClient).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(HttpContentExtensions).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(JsonSerializerOptions).Assembly.Location)
            });

            var sut    = new PatchParametersWalker();
            var result = sut.Process(await compilation.Tree.GetRootAsync(), compilation.Compilation.GetSemanticModel(compilation.Tree));

            Assert.Equal("SomeType", result.First().Name);
        }
예제 #2
0
        public async Task No_PatchedType_EmptyResult()
        {
            string code = @"
public class Controller
{
    public void TestMethod1(SomeType input) { }
}";

            var compilation = SourceBuilder.Compile(code, new[] { MetadataReference.CreateFromFile(typeof(PatchParameterWalkerTests).Assembly.Location), MetadataReference.CreateFromFile(typeof(Patch <>).Assembly.Location) });

            var sut    = new PatchParametersWalker();
            var result = sut.Process(await compilation.Tree.GetRootAsync(), compilation.Compilation.GetSemanticModel(compilation.Tree));

            Assert.Empty(result);
        }
예제 #3
0
        public async Task ReturnsGeneric_TypeOf_Patch()
        {
            string code = @"
public class Controller
{
    public class SomeType { }
    public void TestMethod(LaDeak.JsonMergePatch.Abstractions.Patch<SomeType> input) { }
}";

            var compilation = SourceBuilder.Compile(code, new[] { MetadataReference.CreateFromFile(typeof(PatchParameterWalkerTests).Assembly.Location), MetadataReference.CreateFromFile(typeof(Patch <>).Assembly.Location) });

            var sut    = new PatchParametersWalker();
            var result = sut.Process(await compilation.Tree.GetRootAsync(), compilation.Compilation.GetSemanticModel(compilation.Tree));

            Assert.Equal("SomeType", result.Single().Name);
        }
예제 #4
0
        public async Task RecordTypeWithPatchableArgument_Patch_ReturnsType()
        {
            string code = @"
public class Controller
{
    [LaDeak.JsonMergePatch.Abstractions.Patchable]
    public record SomeType(int Param);

    public record SomeOtherType(int Param);
}";

            var compilation = SourceBuilder.Compile(code, new[] { MetadataReference.CreateFromFile(typeof(PatchParameterWalkerTests).Assembly.Location), MetadataReference.CreateFromFile(typeof(Patch <>).Assembly.Location) });

            var sut    = new PatchParametersWalker();
            var result = sut.Process(await compilation.Tree.GetRootAsync(), compilation.Compilation.GetSemanticModel(compilation.Tree));

            Assert.Equal("SomeType", result.Single().Name);
        }
예제 #5
0
        public async Task Returns_Multiple_PatchTypes()
        {
            string code = @"
public class Controller
{
    public class SomeType { }
    public void TestMethod1(LaDeak.JsonMergePatch.Abstractions.Patch<SomeType> input) { }
    public void TestMethod2(LaDeak.JsonMergePatch.Abstractions.Patch<bool> input) { }
}";

            var compilation = SourceBuilder.Compile(code, new[] { MetadataReference.CreateFromFile(typeof(PatchParameterWalkerTests).Assembly.Location), MetadataReference.CreateFromFile(typeof(Patch <>).Assembly.Location) });

            var sut    = new PatchParametersWalker();
            var result = sut.Process(await compilation.Tree.GetRootAsync(), compilation.Compilation.GetSemanticModel(compilation.Tree));

            Assert.Equal("SomeType", result.First().Name);
            Assert.Equal("Boolean", result.Last().Name);
            Assert.Equal("System", result.Last().ContainingNamespace.Name);
        }