diff options
author | crupest <crupest@outlook.com> | 2020-10-31 00:42:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-31 00:42:06 +0800 |
commit | a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f (patch) | |
tree | ee006874b0c93e9bfc76f141a092a8b9585a1f95 /BackEnd/Timeline.Tests/ErrorCodeTest.cs | |
parent | 0c4caaebe2480e77918d5d7df234f0edaeab74ba (diff) | |
parent | 7ce0846d9ec968da3ea4f7ebcc6db26db8e49089 (diff) | |
download | timeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.tar.gz timeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.tar.bz2 timeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.zip |
Merge pull request #161 from crupest/upgrade
Upgrade packages and split front end and back end.
Diffstat (limited to 'BackEnd/Timeline.Tests/ErrorCodeTest.cs')
-rw-r--r-- | BackEnd/Timeline.Tests/ErrorCodeTest.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/ErrorCodeTest.cs b/BackEnd/Timeline.Tests/ErrorCodeTest.cs new file mode 100644 index 00000000..258ebf4e --- /dev/null +++ b/BackEnd/Timeline.Tests/ErrorCodeTest.cs @@ -0,0 +1,53 @@ +using FluentAssertions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using Timeline.Models.Http;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Timeline.Tests
+{
+ public class ErrorCodeTest
+ {
+ private readonly ITestOutputHelper _output;
+
+ public ErrorCodeTest(ITestOutputHelper output)
+ {
+ _output = output;
+ }
+
+ [Fact]
+ public void ShouldWork()
+ {
+ var errorCodes = new Dictionary<int, string>();
+
+ void RecursiveCheckErrorCode(Type type)
+ {
+ foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
+ .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(int)))
+ {
+ var name = type.FullName + "." + field.Name;
+ var value = (int)field.GetRawConstantValue();
+ _output.WriteLine($"Find error code {name} , value is {value}.");
+
+ value.Should().BeInRange(1000_0000, 9999_9999, "Error code should have exactly 8 digits.");
+
+ errorCodes.Should().NotContainKey(value,
+ "identical error codes are found and conflict paths are {0} and {1}",
+ name, errorCodes.GetValueOrDefault(value));
+
+ errorCodes.Add(value, name);
+ }
+
+ foreach (var nestedType in type.GetNestedTypes())
+ {
+ RecursiveCheckErrorCode(nestedType);
+ }
+ }
+
+ RecursiveCheckErrorCode(typeof(ErrorCodes));
+ }
+ }
+}
|