public void DistanceMatrix_Test() { using var harmony = new HarmonyDisposable($"{nameof(DependencyInjectionTests)}.{nameof(DistanceMatrix_Test)}"); harmony.Patch(SymbolExtensions2.GetPropertyInfo(() => Settlement.All).GetMethod, prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedGetSettlementAll))); var serviceProvider = ButterLibSubModule.Instance !.GetServiceProvider() !; var scope = serviceProvider.CreateScope(); var distanceMatrix = scope.ServiceProvider.GetRequiredService <DistanceMatrix <Settlement> >(); Assert.NotNull(distanceMatrix); Assert.True(distanceMatrix.GetType().GetGenericTypeDefinition() == typeof(DistanceMatrixImplementation <>)); Assert.AreEqual(distanceMatrix.GetType().GenericTypeArguments, new[] { typeof(Settlement) }); var distanceMatrix1 = Bannerlord.ButterLib.DistanceMatrix.DistanceMatrix.Create <Settlement>() !; Assert.NotNull(distanceMatrix1); Assert.True(distanceMatrix1.GetType().GetGenericTypeDefinition() == typeof(DistanceMatrixImplementation <>)); Assert.AreEqual(distanceMatrix1.GetType().GenericTypeArguments, new[] { typeof(Settlement) }); var distanceMatrix2 = Bannerlord.ButterLib.DistanceMatrix.DistanceMatrix <Settlement> .Create() !; Assert.NotNull(distanceMatrix2); Assert.True(distanceMatrix2.GetType().GetGenericTypeDefinition() == typeof(DistanceMatrixImplementation <>)); Assert.AreEqual(distanceMatrix2.GetType().GenericTypeArguments, new[] { typeof(Settlement) }); }
public void CampaignDescriptor_Test() { using var harmony = new HarmonyDisposable($"{nameof(DependencyInjectionTests)}.{nameof(CampaignDescriptor_Test)}"); harmony.Patch(AccessTools.DeclaredPropertyGetter(typeof(CampaignTime), "CurrentTicks"), prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedCurrentTicks))); harmony.Patch(SymbolExtensions.GetMethodInfo(() => CharacterCode.CreateFrom((BasicCharacterObject)null !)), prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedCreateFrom))); 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 AccessTools.Property(typeof(Hero), "Name").SetValue(hero, new TextObject("TestHero")); #else #error ConstGameVersionWithPrefix is not handled! #endif AccessTools.Field(typeof(Hero), "_birthDay").SetValue(hero, CampaignTime.YearsFromNow(18)); var campaignDescriptor = CampaignDescriptor.Create(hero); Assert.NotNull(campaignDescriptor); Assert.True(campaignDescriptor is CampaignDescriptorImplementation); }