From 7d70c89e2e267e6211343a70cb5f4e5170f877f2 Mon Sep 17 00:00:00 2001 From: Aragas Date: Sat, 11 Dec 2021 00:05:53 +0300 Subject: [PATCH] Fixed tests --- .../DependencyInjectionTests.cs | 4 +- .../SaveSystem/JsonSerializationTests.cs | 38 ++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs b/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs index 7f73b269..21826f7d 100644 --- a/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs +++ b/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs @@ -131,8 +131,10 @@ public void CampaignDescriptor_Test() var hero = (Hero) FormatterServices.GetUninitializedObject(typeof(Hero)); #if e143 || e150 || e151 || e152 || e153 || e154 || e155 || e156 || e157 || e158 || e159 AccessTools.Field(typeof(Hero), "Name").SetValue(hero, new TextObject("TestHero")); -#elif e1510 || e160 || e161 || e162 || e163 || e164 || e165 || e170 +#elif e1510 || e160 || e161 || e162 || e163 || e164 || e165 AccessTools.Property(typeof(Hero), "Name").SetValue(hero, new TextObject("TestHero")); +#elif e170 + AccessTools.Field(typeof(Hero), "_name").SetValue(hero, new TextObject("TestHero")); #else #error ConstGameVersionWithPrefix is not handled! #endif diff --git a/tests/Bannerlord.ButterLib.Tests/SaveSystem/JsonSerializationTests.cs b/tests/Bannerlord.ButterLib.Tests/SaveSystem/JsonSerializationTests.cs index cc3daa7b..b3eec291 100644 --- a/tests/Bannerlord.ButterLib.Tests/SaveSystem/JsonSerializationTests.cs +++ b/tests/Bannerlord.ButterLib.Tests/SaveSystem/JsonSerializationTests.cs @@ -64,12 +64,22 @@ public void CheckForUnsupportedSaveableClassTypes_Test() var saveableClassTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => { - IEnumerable Filter(Type[] types) + IEnumerable Filter(IEnumerable types) { - return types.Where(t => t is not null && !t.IsAbstract && !t.IsGenericType && - t.GetMembers().Any(m => m.GetCustomAttributes(true).Any( - att => att.GetType() == typeof(SaveableFieldAttribute) || - att.GetType() == typeof(SaveablePropertyAttribute)))); + return types.Where(t => + { + try + { + return t is not null && !t.IsAbstract && !t.IsGenericType && + t.GetMembers().Any(m => m.GetCustomAttributes(true).Any( + att => att.GetType() == typeof(SaveableFieldAttribute) || + att.GetType() == typeof(SaveablePropertyAttribute))); + } + catch (FileNotFoundException e) + { + return false; + } + }); } try { @@ -123,10 +133,20 @@ public void CheckForUnsupportedSaveableMembers_Test() { IEnumerable Filter(Type[] types) { - return types.Where(t => t is not null && !t.IsAbstract && !t.IsGenericType && - t.GetMembers().Any(m => m.GetCustomAttributes(true).Any( - att => att.GetType() == typeof(SaveableFieldAttribute) || - att.GetType() == typeof(SaveablePropertyAttribute)))); + return types.Where(t => + { + try + { + return t is not null && !t.IsAbstract && !t.IsGenericType && + t.GetMembers().Any(m => m.GetCustomAttributes(true).Any( + att => att.GetType() == typeof(SaveableFieldAttribute) || + att.GetType() == typeof(SaveablePropertyAttribute))); + } + catch (FileNotFoundException e) + { + return false; + } + }); } try {