-
-
Notifications
You must be signed in to change notification settings - Fork 672
/
GenerateMessagePackFormatterAttrTest.cs
74 lines (64 loc) · 2.35 KB
/
GenerateMessagePackFormatterAttrTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace MessagePack.Generator.Tests
{
public class GenerateMessagePackFormatterAttrTest
{
private readonly ITestOutputHelper testOutputHelper;
public GenerateMessagePackFormatterAttrTest(ITestOutputHelper testOutputHelper)
{
this.testOutputHelper = testOutputHelper;
}
[Fact]
public async Task CanGenerateMessagePackFormatterAttr()
{
using var tempWorkarea = TemporaryProjectWorkarea.Create();
var contents = @"
using System;
using System.Collections.Generic;
using MessagePack;
namespace TempProject
{
[MessagePackFormatter(typeof(MyFormatter))]
public class MyMessagePackObject
{
public int Foo { get; set; }
public class MyFormatter : IMessagePackFormatter<MyMessagePackObject>
{
public MyMessagePackObject Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
throw new NotImplementedException();
}
public void Serialize(ref MessagePackWriter writer, MyMessagePackObject value, MessagePackSerializerOptions options)
{
throw new NotImplementedException();
}
}
}
[MessagePackObject]
public class Bar
{
[Key(0)]
public MyMessagePackObject Baz { get; set; }
}
}
";
tempWorkarea.AddFileToTargetProject("MyMessagePackObject.cs", contents);
var compiler = new MessagePackCompiler.CodeGenerator(testOutputHelper.WriteLine, CancellationToken.None);
// can compile(does not throw MessagePackGeneratorResolveFailedException : Serialization Object must mark MessagePackObjectAttribute. type: global::TempProject.MyMessagePackObject)
await compiler.GenerateFileAsync(
tempWorkarea.GetOutputCompilation().Compilation,
tempWorkarea.OutputDirectory,
"TempProjectResolver",
"TempProject.Generated",
false,
string.Empty,
Array.Empty<string>());
}
}
}