Skip to content

Commit 4d84b78

Browse files
Add log output snapshot check (#258)
* Add log output verification * Add 1.4.42 log output result * Add v1.5.0 log output data * Add v1.5.0.1 log output data * Add v1.5.7 log output data * Split log output test into 3 --------- Co-authored-by: Aaron Stannard <[email protected]>
1 parent 1036b9c commit 4d84b78

File tree

11 files changed

+669
-22
lines changed

11 files changed

+669
-22
lines changed

Akka.Logger.Serilog.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{489D8D37
1515
build.fsx = build.fsx
1616
build.ps1 = build.ps1
1717
build.sh = build.sh
18+
src\common.props = src\common.props
1819
EndProjectSection
1920
EndProject
2021
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{28CDBE4C-053C-4CD4-B5D2-4DF529922916}"

src/Akka.Logger.Serilog.Tests/Akka.Logger.Serilog.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
<PropertyGroup>
55
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetCoreTestVersion)</TargetFrameworks>
6+
<OutputType>Exe</OutputType>
7+
<StartupObject>Akka.Logger.Serilog.Tests.Generator.Program</StartupObject>
68
</PropertyGroup>
79

810
<ItemGroup>
@@ -17,6 +19,9 @@
1719

1820
<ItemGroup>
1921
<ProjectReference Include="..\Akka.Logger.Serilog\Akka.Logger.Serilog.csproj" />
22+
<None Update="TestFiles\**\*.*">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
2025
</ItemGroup>
2126

2227
</Project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="Program.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013-2023 Akka.NET project <https://github.com/akkadotnet/akka.net>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
using System;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Reflection;
11+
using System.Threading.Tasks;
12+
using Serilog;
13+
14+
namespace Akka.Logger.Serilog.Tests.Generator
15+
{
16+
public static class Program
17+
{
18+
public static async Task Main(string[] args)
19+
{
20+
var version = args.Length > 0 ? args[0] : Assembly.GetAssembly(typeof(Log))?.GetName().Version?.ToString() ?? Guid.NewGuid().ToString("N");
21+
22+
var sink = new TestSink();
23+
Log.Logger = new LoggerConfiguration()
24+
.WriteTo.ColoredConsole()
25+
.WriteTo.Sink(sink)
26+
.MinimumLevel.Debug()
27+
.CreateLogger();
28+
29+
sink.Clear();
30+
31+
using (var fileWriter = new StreamWriter($"./TestFiles/v{version}.tf"))
32+
{
33+
foreach (var i in Enumerable.Range(0, TestData.MessageFormats.Length))
34+
{
35+
var messageFormat = TestData.MessageFormats[i];
36+
var arg = TestData.Args[i];
37+
38+
Log.Logger.Information(messageFormat, arg);
39+
40+
var count = 0;
41+
while (sink.Writes.Count < 1 && count < 50)
42+
{
43+
await Task.Delay(100);
44+
count++;
45+
}
46+
47+
if (!sink.Writes.TryDequeue(out var logEvent))
48+
throw new Exception($"Failed to log test data [{messageFormat}] with data [{arg}]");
49+
50+
await fileWriter.WriteLineAsync(logEvent.RenderMessage());
51+
}
52+
}
53+
}
54+
}
55+
}
56+
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="TestData.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013-2023 Akka.NET project <https://github.com/akkadotnet/akka.net>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
9+
namespace Akka.Logger.Serilog.Tests.Generator
10+
{
11+
internal static class TestData
12+
{
13+
public const bool Boolean = true;
14+
public const byte Byte = 42;
15+
public const sbyte SByte = -42;
16+
public const char Char = 'A';
17+
public const decimal Decimal = 3.1415M;
18+
public const double Double = 3.1415;
19+
public const float Float = 3.1415F;
20+
public const int Int = -42;
21+
public const uint UInt = 42;
22+
public const long Long = -42L;
23+
public const ulong ULong = 42;
24+
public const short Short = -42;
25+
public const ushort UShort = 42;
26+
public const string String = "Fourty Two";
27+
public const EnumInstance Enum = EnumInstance.One;
28+
29+
public static readonly bool[] BooleanArray = { false, true, false };
30+
public static readonly byte[] ByteArray = { 1, 2, 3 };
31+
public static readonly sbyte[] SByteArray = { -1, 2, -3 };
32+
public static readonly char[] CharArray = { '1', '2', '3' };
33+
public static readonly decimal[] DecimalArray = { 1M, -2M, 3M };
34+
public static readonly double[] DoubleArray = { 1.0, -2.0, 3.0 };
35+
public static readonly float[] FloatArray = { 1F, -2F, 3F };
36+
public static readonly int[] IntArray = { 1, -2, 3 };
37+
public static readonly uint[] UIntArray = { 1, 2, 3 };
38+
public static readonly long[] LongArray = { 1L, -2L, 3L };
39+
public static readonly ulong[] ULongArray = { 1L, 2L, 3L };
40+
public static readonly short[] ShortArray = { 1, -2, 3 };
41+
public static readonly ushort[] UShortArray = { 1, 2, 3 };
42+
public static readonly string[] StringArray = { "One", "Two", "Three" };
43+
public static readonly EnumInstance[] EnumArray = { EnumInstance.One, EnumInstance.Two, EnumInstance.Three };
44+
45+
public static readonly List<bool> BooleanList = new List<bool>(BooleanArray);
46+
public static readonly List<byte> ByteList = new List<byte>(ByteArray);
47+
public static readonly List<sbyte> SByteList = new List<sbyte>(SByteArray);
48+
public static readonly List<char> CharList = new List<char>(CharArray);
49+
public static readonly List<decimal> DecimalList = new List<decimal>(DecimalArray);
50+
public static readonly List<double> DoubleList = new List<double>(DoubleArray);
51+
public static readonly List<float> FloatList = new List<float>(FloatArray);
52+
public static readonly List<int> IntList = new List<int>(IntArray);
53+
public static readonly List<uint> UIntList = new List<uint>(UIntArray);
54+
public static readonly List<long> LongList = new List<long>(LongArray);
55+
public static readonly List<ulong> ULongList = new List<ulong>(ULongArray);
56+
public static readonly List<short> ShortList = new List<short>(ShortArray);
57+
public static readonly List<ushort> UShortList = new List<ushort>(UShortArray);
58+
public static readonly List<string> StringList = new List<string>(StringArray);
59+
public static readonly List<EnumInstance> EnumList = new List<EnumInstance>(EnumArray);
60+
61+
public static readonly Dictionary<string, object> PrimitiveDictionary = new Dictionary<string, object>
62+
{
63+
[nameof(Boolean)] = Boolean,
64+
[nameof(Byte)] = Byte,
65+
[nameof(SByte)] = SByte,
66+
[nameof(Char)] = Char,
67+
[nameof(Decimal)] = Decimal,
68+
[nameof(Double)] = Double,
69+
[nameof(Float)] = Float,
70+
[nameof(Int)] = Int,
71+
[nameof(UInt)] = UInt,
72+
[nameof(Long)] = Long,
73+
[nameof(ULong)] = ULong,
74+
[nameof(Short)] = Short,
75+
[nameof(UShort)] = UShort,
76+
[nameof(String)] = String,
77+
[nameof(Enum)] = Enum,
78+
};
79+
80+
public static readonly Dictionary<string, object> ArrayDictionary = new Dictionary<string, object>
81+
{
82+
[nameof(BooleanArray)] = BooleanArray,
83+
[nameof(ByteArray)] = ByteArray,
84+
[nameof(SByteArray)] = SByteArray,
85+
[nameof(CharArray)] = CharArray,
86+
[nameof(DecimalArray)] = DecimalArray,
87+
[nameof(DoubleArray)] = DoubleArray,
88+
[nameof(FloatArray)] = FloatArray,
89+
[nameof(IntArray)] = IntArray,
90+
[nameof(UIntArray)] = UIntArray,
91+
[nameof(LongArray)] = LongArray,
92+
[nameof(ULongArray)] = ULongArray,
93+
[nameof(ShortArray)] = ShortArray,
94+
[nameof(UShortArray)] = UShortArray,
95+
[nameof(StringArray)] = StringArray,
96+
[nameof(EnumArray)] = EnumArray,
97+
};
98+
99+
public static readonly Dictionary<string, object> ListDictionary = new Dictionary<string, object>
100+
{
101+
[nameof(BooleanList)] = BooleanList,
102+
[nameof(ByteList)] = ByteList,
103+
[nameof(SByteList)] = SByteList,
104+
[nameof(CharList)] = CharList,
105+
[nameof(DecimalList)] = DecimalList,
106+
[nameof(DoubleList)] = DoubleList,
107+
[nameof(FloatList)] = FloatList,
108+
[nameof(IntList)] = IntList,
109+
[nameof(UIntList)] = UIntList,
110+
[nameof(LongList)] = LongList,
111+
[nameof(ULongList)] = ULongList,
112+
[nameof(ShortList)] = ShortList,
113+
[nameof(UShortList)] = UShortList,
114+
[nameof(StringList)] = StringList,
115+
[nameof(EnumList)] = EnumList,
116+
};
117+
118+
public static readonly PlainClassInstance PlainClassInstance = new PlainClassInstance
119+
{
120+
Boolean = Boolean,
121+
Byte = Byte,
122+
Sbyte = SByte,
123+
Char = Char,
124+
125+
Decimal = Decimal,
126+
Double = Double,
127+
Float = Float,
128+
Int = Int,
129+
130+
UInt = UInt,
131+
Long = Long,
132+
ULong = ULong,
133+
Short = Short,
134+
135+
UShort = UShort,
136+
String = String,
137+
Enum = Enum
138+
};
139+
140+
public static readonly string[] MessageFormats =
141+
{
142+
$"{nameof(Boolean)}: {{Boolean}}",
143+
$"{nameof(Byte)}: {{Byte}}",
144+
$"{nameof(SByte)}: {{SByte}}",
145+
$"{nameof(Char)}: {{Char}}",
146+
147+
$"{nameof(Decimal)}: {{Decimal}}",
148+
$"{nameof(Double)}: {{Double}}",
149+
$"{nameof(Float)}: {{Float}}",
150+
$"{nameof(Int)}: {{Int}}",
151+
152+
$"{nameof(UInt)}: {{UInt}}",
153+
$"{nameof(Long)}: {{Long}}",
154+
$"{nameof(ULong)}: {{ULong}}",
155+
$"{nameof(Short)}: {{Short}}",
156+
157+
$"{nameof(UShort)}: {{UShort}}",
158+
$"{nameof(String)}: {{String}}",
159+
$"{nameof(Enum)}: {{Enum}}",
160+
161+
162+
$"{nameof(BooleanArray)}: {{BooleanArray}}",
163+
$"{nameof(ByteArray)}: {{ByteArray}}",
164+
$"{nameof(SByteArray)}: {{SByteArray}}",
165+
$"{nameof(CharArray)}: {{CharArray}}",
166+
167+
$"{nameof(DecimalArray)}: {{DecimalArray}}",
168+
$"{nameof(DoubleArray)}: {{DoubleArray}}",
169+
$"{nameof(FloatArray)}: {{FloatArray}}",
170+
$"{nameof(IntArray)}: {{IntArray}}",
171+
172+
$"{nameof(UIntArray)}: {{UIntArray}}",
173+
$"{nameof(LongArray)}: {{LongArray}}",
174+
$"{nameof(ULongArray)}: {{ULongArray}}",
175+
$"{nameof(ShortArray)}: {{ShortArray}}",
176+
177+
$"{nameof(UShortArray)}: {{UShortArray}}",
178+
$"{nameof(StringArray)}: {{StringArray}}",
179+
$"{nameof(EnumArray)}: {{EnumArray}}",
180+
181+
182+
$"{nameof(BooleanList)}: {{BooleanList}}",
183+
$"{nameof(ByteList)}: {{ByteList}}",
184+
$"{nameof(SByteList)}: {{SByteList}}",
185+
$"{nameof(CharList)}: {{CharList}}",
186+
187+
$"{nameof(DecimalList)}: {{DecimalList}}",
188+
$"{nameof(DoubleList)}: {{DoubleList}}",
189+
$"{nameof(FloatList)}: {{FloatList}}",
190+
$"{nameof(IntList)}: {{IntList}}",
191+
192+
$"{nameof(UIntList)}: {{UIntList}}",
193+
$"{nameof(LongList)}: {{LongList}}",
194+
$"{nameof(ULongList)}: {{ULongList}}",
195+
$"{nameof(ShortList)}: {{ShortList}}",
196+
197+
$"{nameof(UShortList)}: {{UShortList}}",
198+
$"{nameof(StringList)}: {{StringList}}",
199+
$"{nameof(EnumList)}: {{EnumList}}",
200+
201+
$"{nameof(PrimitiveDictionary)}: {{PrimitiveDictionary}}",
202+
$"{nameof(ArrayDictionary)}: {{ArrayDictionary}}",
203+
$"{nameof(ListDictionary)}: {{ListDictionary}}",
204+
205+
$"{nameof(PlainClassInstance)}: {{PlainClassInstance}}",
206+
};
207+
208+
public static readonly object[][] Args =
209+
{
210+
new object[]{Boolean},
211+
new object[]{Byte},
212+
new object[]{SByte},
213+
new object[]{Char},
214+
215+
new object[]{Decimal},
216+
new object[]{Double},
217+
new object[]{Float},
218+
new object[]{Int},
219+
220+
new object[]{UInt},
221+
new object[]{Long},
222+
new object[]{ULong},
223+
new object[]{Short},
224+
225+
new object[]{UShort},
226+
new object[]{String},
227+
new object[]{Enum},
228+
229+
230+
new object[]{BooleanArray},
231+
new object[]{ByteArray},
232+
new object[]{SByteArray},
233+
new object[]{CharArray},
234+
235+
new object[]{DecimalArray},
236+
new object[]{DoubleArray},
237+
new object[]{FloatArray},
238+
new object[]{IntArray},
239+
240+
new object[]{UIntArray},
241+
new object[]{LongArray},
242+
new object[]{ULongArray},
243+
new object[]{ShortArray},
244+
245+
new object[]{UShortArray},
246+
new object[]{StringArray},
247+
new object[]{EnumArray},
248+
249+
250+
new object[]{BooleanList},
251+
new object[]{ByteList},
252+
new object[]{SByteList},
253+
new object[]{CharList},
254+
255+
new object[]{DecimalList},
256+
new object[]{DoubleList},
257+
new object[]{FloatList},
258+
new object[]{IntList},
259+
260+
new object[]{UIntList},
261+
new object[]{LongList},
262+
new object[]{ULongList},
263+
new object[]{ShortList},
264+
265+
new object[]{UShortList},
266+
new object[]{StringList},
267+
new object[]{EnumList},
268+
269+
270+
new object[]{PrimitiveDictionary},
271+
new object[]{ArrayDictionary},
272+
new object[]{ListDictionary},
273+
new object[]{PlainClassInstance},
274+
};
275+
}
276+
277+
internal enum EnumInstance
278+
{
279+
One,
280+
Two,
281+
Three
282+
}
283+
284+
// ReSharper disable UnusedAutoPropertyAccessor.Global
285+
internal class PlainClassInstance
286+
{
287+
public bool Boolean { get; set; }
288+
public byte Byte { get; set; }
289+
public sbyte Sbyte { get; set; }
290+
public char Char { get; set; }
291+
public decimal Decimal { get; set; }
292+
public double Double { get; set; }
293+
public float Float { get; set; }
294+
public int Int { get; set; }
295+
public uint UInt { get; set; }
296+
public long Long { get; set; }
297+
public ulong ULong { get; set; }
298+
public short Short { get; set; }
299+
public ushort UShort { get; set; }
300+
public string String { get; set; }
301+
public EnumInstance Enum { get; set; }
302+
}
303+
}
304+

0 commit comments

Comments
 (0)