public static IAppContainer Create(MockAppHostPlugin hostPlugin, IServiceCollection services) { var resolver = new TestTypeResolver(); resolver.AddPlugin(hostPlugin); var container = ContainerSetup.Bootstrap(resolver); container.WithConfig((EnvironmentConfig envConfig) => { var configBuilder = new ConfigurationBuilder(); configBuilder.AddDefaultAppSettings(); envConfig.UseConfiguration(configBuilder.Build()); }) .WithConfig((AutofacRegistrationConfig config) => { config.Build = builder => { builder.Populate(services); }; }) .WithConfig((WebMvcConfig config) => { config.EnableRouteMetadata = true; config.UseServices(services); }); return(container); }
public void TestResXSerializationBinder() { // The ResXSerializationBinder is used during (de)serialization if there is a typeResolver/typeNameConverter for a BinaryFormatted type object[] referenceObjects = { DBNull.Value, // type name must not be set -> UnitySerializationHolder is used #if !(NETCOREAPP2_0 || NETCOREAPP3_0) // '932 | Japanese (Shift-JIS)' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. Encoding.GetEncoding("shift_jis"), // type name must not be set -> encoding type is changed #endif CultureInfo.CurrentCulture, // special handling for culture info new List <int[][, ]> // generic type: system ResXSerializationBinder parses it wrongly, but if versions do not change, it fortunately works due to concatenation { new int[][, ] { new int[, ] { { 11,12 }, { 21, 22 } } } } }; // ReSharper disable once ConvertToLocalFunction - it will be a delegate in the end when passed to the methods #pragma warning disable IDE0039 // Use local function Func <Type, string> typeNameConverter = t => t.AssemblyQualifiedName; #pragma warning restore IDE0039 // Use local function ITypeResolutionService typeResolver = new TestTypeResolver(); #if NETFRAMEWORK SystemSerializeObjects(referenceObjects); #endif KGySerializeObjects(referenceObjects, true, true, typeNameConverter, typeResolver); KGySerializeObjects(referenceObjects, false, true, typeNameConverter, typeResolver); }
public static TestTypeResolver DefaultSettingsConfig(this TestTypeResolver resolver) { resolver.AddPlugin <MockAppHostPlugin>(); resolver.AddPlugin <MockCorePlugin>() .UseSettingsPlugin(); return(resolver); }
public void GetTypeResolution() { TestTypeResolver resolver = new TestTypeResolver(typeof(object)); TypeResolution.Current = new TypeResolutionHandler(resolver.Resolve); Assert.AreSame(typeof(object), TypeResolution.GetType("obj")); Assert.AreEqual("obj", resolver.LastTypeName, "typeName"); Assert.AreEqual(true, resolver.LastThrowOnError, "throwOnError"); Assert.AreEqual(false, resolver.LastIgnoreCase, "ignoreCase"); }
public static IAppContainer CreateContainer() { var resolver = new TestTypeResolver(); AppContainer container = new AppContainer(resolver, setGlobalReference: false); container.UseTestLogger(); resolver.AddPlugin <MockCorePlugin>() .UseRabbitMqPlugin(); return(container); }
/// <summary> /// Creates an instance an AppContainer using an instance of the /// TestTypeResolver class. /// </summary> /// <param name="resolver">Delegate passed an instance of the created /// resolver. The consumer can add mock plug-ins and associated types /// to the resolver for unit-testing.</param> /// <param name="container">Delegate passed an instance of the created /// AppContainer for additional consumer configuration.</param> /// <returns>Reference to object that can be used to act on the configured /// application container.</returns> public static ContainerTest Arrange(Action <TestTypeResolver> resolver, Action <IAppContainer> container = null) { Check.NotNull(resolver, nameof(resolver), "configuration delegate not specified"); var typeResolver = new TestTypeResolver(); var appcontainer = new AppContainer(typeResolver, setGlobalReference: false); resolver(typeResolver); container?.Invoke(appcontainer); return(new ContainerTest(appcontainer)); }
// Creates a configured mock plug-in with the needed RabbitMQ plug-in components. public static ContainerTest Arrange(Action <TestTypeResolver> config) { var resolver = new TestTypeResolver(); AppContainer container = new AppContainer(resolver, setGlobalReference: false); resolver.AddPlugin <MockCorePlugin>() .UseRabbitMqPlugin(); config(resolver); container.UseTestLogger(); return(new ContainerTest(container)); }
void CompileDsdlTypes() { var resolver = new TestTypeResolver(_types); resolver.ResolveAll(); }