Walter.BOM Namespace
Walter.Web.FireWall Namespace
ASP-WAF Web application firewall for .Net 6, .Net 5, .Net Standard 2.1 and .Net Core 3.x

MaxMindBuilderExtensions..::..InjectMaxMindGeoProviderInUnitTest<(Of <(<'T>)>)> Method

Easy way for injecting MaxMind into a Unit test

Namespace:  Microsoft.Extensions.DependencyInjection
Assembly:  Walter.Web.FireWall.Geo.MaxMind (in Walter.Web.FireWall.Geo.MaxMind.dll)

Syntax


public static T InjectMaxMindGeoProviderInUnitTest<T>(
	T services,
	DirectoryInfo maxMindFiles,
	IFireWallConfig firewallConfig,
	string geoCityFile,
	string geoCountry,
	string geoASN
)
where T : IServiceCollection

Type Parameters

T

Parameters

services
Type: T
the service to configure
maxMindFiles
Type: DirectoryInfo
the directory that contains the MaxMind files
firewallConfig
Type: IFireWallConfig
The firewall configuration interface to populate for use [IFireWallConfig.CreateForUnitTest()]for implementation details
geoCityFile
Type: String
Geo city file, defaults to GeoLite2-city.mmdb
geoCountry
Type: String
Geo country file, defaults to GeoLite2-Country.mmdb
geoASN
Type: String

Return Value

IServiceCollection to continue

Exceptions


ExceptionCondition
[ConfigurationsException]If the MaxMind file where not found
[ArgumentNullException]if a required argument is not provided

Examples


The following example shows how to inject MaxMind capabilities into your unit test
C#
using Walter;
   [TestClass()]
   public class TestClassNameTests
   {

       [ClassInitialize]
       public static void ClassInitialize(TestContext context)
       {
           var conf = Web.FireWall.IFireWallConfig.CreateForUnitTest();
           var serviceProvider = new ServiceCollection();
               serviceProvider.AddMemoryCache()
               .InjectMaxMindGeoProviderInUnitTest(new System.IO.DirectoryInfo(@"D:\MaxMind"), firewallConfig:conf);
               DIContainer.ServiceProvider = serviceProvider.BuildServiceProvider();
       }
       [TestMethod()]
       public void TestMethod()
       {
           var geo = DIContainer.GetDefaultInstanceOrNull<IGeoFactory>();
       }
   }