NUnit.Framework.Assert.IsNotNull(object)

Here are the examples of the csharp api NUnit.Framework.Assert.IsNotNull(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4552 Examples 7

19 Source : RulesAndDefaultConventions.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var container = new Container(rules => rules
            .WithConcreteTypeDynamicRegistrations((serviceType, serviceKey) => true, Reuse.Singleton));

        container.Register<ICar, FastCar>();
        // but no Driver registration!

        // Driver is created by container
        var car = container.Resolve<ICar>();
        replacedert.IsNotNull(car.Driver);
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container();
        c.Register<IDependency, Dep>();
        c.Register<Foo>(made: Made.Of(() => new Foo(Arg.Of<IDependency>())));
        replacedert.IsNotNull(c.Resolve<Foo>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container();
        c.Register<IDependency, Dep>();
        c.Register<Foo>(made: Made.Of(typeof(Foo).GetConstructor(new[] { typeof(IDependency) })));
        replacedert.IsNotNull(c.Resolve<Foo>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container();
        c.Register<IDependency<int>, Dep<int>>();
        c.Register(typeof(Foo<>), made: Made.Of(typeof(Foo<>).GetConstructors()[0]));
        replacedert.IsNotNull(c.Resolve<Foo<int>>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container();
        c.Register<IDependency, Dep>();
        c.Register<Foo>(made: FactoryMethod.ConstructorWithResolvableArguments);
        replacedert.IsNotNull(c.Resolve<Foo>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container(rules => rules.With(FactoryMethod.ConstructorWithResolvableArguments));
        c.Register<IDependency, Dep>();
        c.Register<Foo>(); // no need to specify how to select constructor
        replacedert.IsNotNull(c.Resolve<Foo>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container();
        c.Register<Repo>();
        c.Register<IFoo>(made: Made.Of(() => FooFactory.CreateFoo(Arg.Of<Repo>())));
        replacedert.IsNotNull(c.Resolve<IFoo>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container();
        c.Register<IFooFactory, FooFactory>(Reuse.Singleton);
        c.Register<IDependency, Dep>();
        c.Register<Repo>();
        c.Register<IFoo>(made: Made.Of(r => ServiceInfo.Of<IFooFactory>(), f => f.CreateFoo(Arg.Of<Repo>())));
        replacedert.IsNotNull(c.Resolve<IFoo>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var c = new Container();
        c.Register<Repo>();
        c.Register<FooFactory>(Reuse.Singleton);
        c.Register<IFoo>(made: Made.Of(r => ServiceInfo.Of<FooFactory>(), f => f.Foo));
        replacedert.IsNotNull(c.Resolve<IFoo>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<Foo>();
        container.Register(typeof(Factory<>));
        container.Register(typeof(IService<,>), 
            made: Made.Of(typeof(Factory<>).GetSingleMethodOrNull("Create"), ServiceInfo.Of(typeof(Factory<>))));

        replacedert.IsNotNull(container.Resolve<IService<Foo, string>>());
    }

19 Source : SelectConstructorOrFactoryMethod.cs
with MIT License
from dadhi

[Test]
    public void Example()
    {
        var container = new Container().WithMefAttributedModel();

        container.RegisterExports(typeof(Factory<>), typeof(Foo), typeof(FooDecorator));

        replacedert.IsNotNull(container.Resolve<IService<Foo, string>>());
    }

19 Source : SpecifyDependencyAndPrimitiveValues.cs
with MIT License
from dadhi

[Test] public void Example()
    {
        var container = new Container();

        container.Register<Foo>(made: Made.Of(() => 
            new Foo(Arg.Of<IDependency>(IfUnresolved.ReturnDefault))));

        var foo = container.Resolve<Foo>(ifUnresolved: IfUnresolved.Throw);
        // IfUnresolved.Throw is the default so the alternative is just a
        foo = container.Resolve<Foo>();

        replacedert.IsNotNull(foo);
        replacedert.IsNull(foo.Dependency);
    }

19 Source : SpecifyDependencyAndPrimitiveValues.cs
with MIT License
from dadhi

[Test] public void Example()
    {
        var container = new Container();

        container.Register<Bar>(made: Made.Of(() =>
            new Bar() { Dependency = Arg.Of<IDependency>(IfUnresolved.Throw) }));

        var ex = replacedert.Throws<ContainerException>(() =>
            container.Resolve<Bar>());
        replacedert.AreEqual(Error.NameOf(Error.UnableToResolveUnknownService), ex.ErrorName);

        // compare it to the default behavior:

        container.Register<Bar>(ifAlreadyRegistered: IfAlreadyRegistered.Replace);
        var bar = container.Resolve<Bar>();
        replacedert.IsNotNull(bar);
        replacedert.IsNull(bar.Dependency);
    }

19 Source : SpecifyDependencyAndPrimitiveValues.cs
with MIT License
from dadhi

[Test]
    public void Solution()
    { 
        var c = new Container();
        c.Register<ITest, A>(serviceKey: "a");
        c.Register<ITest, B>(serviceKey: "b");

        c.Register<ExampleClreplaced>(made:
            Made.Of(parameters: Parameters.Of
                .Name("a", serviceKey: "a")
                .Name("b", serviceKey: "b")));

        var example = c.Resolve<ExampleClreplaced>();
        replacedert.IsNotNull(example);
    }

19 Source : SpecifyDependencyAndPrimitiveValues.cs
with MIT License
from dadhi

[Test]
    public void Solution_drop_MadeOf_part()
    { 
        var c = new Container();
        c.Register<ITest, A>(serviceKey: "a");
        c.Register<ITest, B>(serviceKey: "b");

        c.Register<ExampleClreplaced>(made: Parameters.Of // drop Made.Of
            .Name("a", serviceKey: "a")
            .Name("b", serviceKey: "b"));

        replacedert.IsNotNull(c.Resolve<ExampleClreplaced>());
    }

19 Source : SpecifyDependencyAndPrimitiveValues.cs
with MIT License
from dadhi

[Test]
    public void Solution_matching_all_registration_parameters()
    { 
        var c = new Container();
        c.Register<ITest, A>(serviceKey: "a");
        c.Register<ITest, B>(serviceKey: "b");

        c.Register<ExampleClreplaced>(made: Parameters.Of.Details(
            (req, parInfo) => ServiceDetails.Of(serviceKey: parInfo.Name)));

        replacedert.IsNotNull(c.Resolve<ExampleClreplaced>());
    }

19 Source : SpecifyDependencyAndPrimitiveValues.cs
with MIT License
from dadhi

[Test]
    public void Solution_with_strongly_typed_parameters()
    { 
        var c = new Container();
        c.Register<ITest, A>(serviceKey: "a");
        c.Register<ITest, B>(serviceKey: "b");

        c.Register<ExampleClreplaced>(made: Made.Of(() =>
            new ExampleClreplaced(
                Arg.Of<ITest>("a"),
                Arg.Of<ITest>("b"))));

        replacedert.IsNotNull(c.Resolve<ExampleClreplaced>());
    }

19 Source : SpecifyDependencyAndPrimitiveValues.cs
with MIT License
from dadhi

[Test]
    public void Solution_with_the_rule_applied_on_container_level()
    { 
        var c = new Container(rules =>
            rules.With(parameters:
                Parameters.Of.Details(
                    (req, parInfo) => req.ServiceType == typeof(ExampleClreplaced) 
                        ? ServiceDetails.Of(serviceKey: parInfo.Name) 
                        : null)));

        c.Register<ITest, A>(serviceKey: "a");
        c.Register<ITest, B>(serviceKey: "b");
        c.Register<ExampleClreplaced>();

        replacedert.IsNotNull(c.Resolve<ExampleClreplaced>());
    }

19 Source : Wrappers.cs
with MIT License
from dadhi

[Test] public void Example()
    {
        var container = new Container(rules => rules.WithFuncAndLazyWithoutRegistration());
        var getA = container.Resolve<Func<A>>();

        // later register an `A`
        container.Register<A>();
        var a = getA();
        replacedert.IsNotNull(a);
    }

19 Source : Wrappers.cs
with MIT License
from dadhi

[Test] public void Example()
    {
        var container = new Container();
        container.Register<A>();

        // Can be used, the argument will be ignored
        var getA = container.Resolve<Func<string, A>>();

        replacedert.IsNotNull(getA("ignore me"));
    }

19 Source : ReducedLoadTest.cs
with MIT License
from dadhi

[Test]
        public void Test_with_UseDecorateeReuse_decorators_Examine_expression_and_the_split_graph()
        {
            var container = new Container(rules => rules
                .WithoutInterpretationForTheFirstResolution() // compile on the first iteration
                .WithUseDecorateeReuseForDecorators()
                .With(FactoryMethod.ConstructorWithResolvableArguments))
                .WithWebApi(new HttpConfiguration());

            Registrations.RegisterTypes(container, false);

            using (var scope = container.OpenScope(Reuse.WebRequestScopeName))
            {
                var service = scope.Resolve(typeof(EmailController));
                replacedert.IsNotNull(service);

                var expr = scope.Resolve<LambdaExpression>(typeof(EmailController));
                replacedert.IsNotNull(expr);

                var code = expr.ToCodeString(new StringBuilder(100000), 2, true, Abbreviate).ToString();
                var nestedLambdas = code.Count(c => c == '$');

                // the number when split by `dependencyCount >= 256`
                replacedert.AreEqual(67, nestedLambdas);
            }
        }

19 Source : ReducedLoadTest.cs
with MIT License
from dadhi

[Test]
        public void Test_with_UseDecorateeReuse_decorators_Examine_expression_and_the_split_graph_without_FEC()
        {
            var container = new Container(rules => rules
                .WithoutFastExpressionCompiler()
                .WithoutInterpretationForTheFirstResolution() // compile on the first iteration
                .WithUseDecorateeReuseForDecorators()
                .With(FactoryMethod.ConstructorWithResolvableArguments))
                .WithWebApi(new HttpConfiguration());

            Registrations.RegisterTypes(container, false);

            using (var scope = container.OpenScope(Reuse.WebRequestScopeName))
            {
                var service = scope.Resolve(typeof(EmailController));
                replacedert.IsNotNull(service);

                var expr = scope.Resolve<LambdaExpression>(typeof(EmailController));
                replacedert.IsNotNull(expr);

                var code = expr.ToCodeString(new StringBuilder(100000), 2, true, Abbreviate).ToString();
                var nestedLambdas = code.Count(c => c == '$');
                replacedert.AreEqual(2, nestedLambdas);

                Stringreplacedert.Contains("\"Resolve\"", code);
            }
        }

19 Source : WrapAsLazyTests.cs
with MIT License
from dadhi

[Test]
        public void Resolve_array_works_with_lazy_proxy_via_ProxyGenerator()
        {
            var container = new Container();
            container.Register<ICommand, SampleCommand>();
            container.Register<ICommand, AnotherCommand>();
            container.ResolveAsLazy<ICommand>();
            SampleCommand.Created = false;
            AnotherCommand.Created = false;

            // everything resolves fine
            var commands = container.Resolve<ICommand[]>();
            replacedert.AreEqual(2, commands.Length);
            replacedert.IsNotNull(commands[0]);
            replacedert.IsNotNull(commands[1]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[0]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[1]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[0]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[1]);
            replacedert.IsFalse(SampleCommand.Created);
            replacedert.IsFalse(AnotherCommand.Created);

            // and executes as well
            var res1 = commands[0].Execute(10);
            var res2 = commands[1].Execute(10);
            replacedert.AreEqual(50, res1 + res2);
            replacedert.IsTrue(SampleCommand.Created);
            replacedert.IsTrue(AnotherCommand.Created);
        }

19 Source : WrapAsLazyTests.cs
with MIT License
from dadhi

[Test]
        public void Resolve_array_works_with_lazy_proxy_via_DefaultProxyBuilder()
        {
            var container = new Container();
            container.Register<ICommand, SampleCommand>();
            container.Register<ICommand, AnotherCommand>();
            container.ResolveAsLazyViaProxyBuilder(typeof(ICommand));
            SampleCommand.Created = false;
            AnotherCommand.Created = false;

            // everything resolves fine
            var commands = container.Resolve<ICommand[]>();
            replacedert.AreEqual(2, commands.Length);
            replacedert.IsNotNull(commands[0]);
            replacedert.IsNotNull(commands[1]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[0]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[1]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[0]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[1]);
            replacedert.IsFalse(SampleCommand.Created);
            replacedert.IsFalse(AnotherCommand.Created);

            // and executes as well
            var res1 = commands[0].Execute(10);
            var res2 = commands[1].Execute(10);
            replacedert.AreEqual(50, res1 + res2);
            replacedert.IsTrue(SampleCommand.Created);
            replacedert.IsTrue(AnotherCommand.Created);
        }

19 Source : WrapAsLazyTests.cs
with MIT License
from dadhi

[Test]
        public void ResolveMany_works_with_lazy_proxy_via_ProxyGenerator()
        {
            var container = new Container();
            container.Register<ICommand, SampleCommand>();
            container.Register<ICommand, AnotherCommand>();
            container.ResolveAsLazy<ICommand>();
            SampleCommand.Created = false;
            AnotherCommand.Created = false;

            // everything resolves fine
            var commands = container.ResolveMany<ICommand>().ToArray();
            replacedert.AreEqual(2, commands.Length);
            replacedert.IsNotNull(commands[0]);
            replacedert.IsNotNull(commands[1]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[0]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[1]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[0]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[1]);
            replacedert.IsFalse(SampleCommand.Created);
            replacedert.IsFalse(AnotherCommand.Created);

            // and executes as well
            var res1 = commands[0].Execute(10);
            var res2 = commands[1].Execute(10);
            replacedert.AreEqual(50, res1 + res2);
            replacedert.IsTrue(SampleCommand.Created);
            replacedert.IsTrue(AnotherCommand.Created);
        }

19 Source : WrapAsLazyTests.cs
with MIT License
from dadhi

[Test]
        public void ResolveMany_works_with_lazy_proxy_via_DefaultProxyBuilder()
        {
            var container = new Container();
            container.Register<ICommand, SampleCommand>();
            container.Register<ICommand, AnotherCommand>();
            container.ResolveAsLazyViaProxyBuilder(typeof(ICommand));
            SampleCommand.Created = false;
            AnotherCommand.Created = false;

            // everything resolves fine
            var commands = container.ResolveMany<ICommand>().ToArray();
            replacedert.AreEqual(2, commands.Length);
            replacedert.IsNotNull(commands[0]);
            replacedert.IsNotNull(commands[1]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[0]);
            replacedert.IsNotInstanceOf<SampleCommand>(commands[1]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[0]);
            replacedert.IsNotInstanceOf<AnotherCommand>(commands[1]);
            replacedert.IsFalse(SampleCommand.Created);
            replacedert.IsFalse(AnotherCommand.Created);

            // and executes as well
            var res1 = commands[0].Execute(10);
            var res2 = commands[1].Execute(10);
            replacedert.AreEqual(50, res1 + res2);
            replacedert.IsTrue(SampleCommand.Created);
            replacedert.IsTrue(AnotherCommand.Created);
        }

19 Source : ConstructorSelectionTests.cs
with MIT License
from dadhi

[Test]
        public void It_is_possible_to_register_and_resolve_service_with_internal_constructor()
        {
            var container = new Container();
            container.Register<IService, SomeService>();

            container.Register<ClreplacedWithInternalConstructor>(made: Made.Of(t => t.SingleConstructor(true)));

            var obj = container.Resolve<ClreplacedWithInternalConstructor>();
            replacedert.IsNotNull(obj);
        }

19 Source : GHIssue191_Optional_IResolverContext_argument_in_Func_of_service.cs
with MIT License
from dadhi

[Test]
        public void Can_resolve_as_FactoryDelegate()
        {
            var container = new Container();

            container.Register<A>();
            container.Register<B>();

            var f = container.Resolve<FactoryDelegate>(typeof(B));
            var b = f(container) as B;

            replacedert.IsNotNull(b);
        }

19 Source : GHIssue191_Optional_IResolverContext_argument_in_Func_of_service.cs
with MIT License
from dadhi

[Test]
        public void ResolverContext_is_ignored_in_resolved_Func()
        {
            var container = new Container();

            container.Register<A>();
            container.Register<B>();

            var f = container.Resolve<Func<IResolverContext, B>>();
            var b = f(container);

            replacedert.IsNotNull(b);
        }

19 Source : GHIssue191_Optional_IResolverContext_argument_in_Func_of_service.cs
with MIT License
from dadhi

[Test]
        public void ResolverContext_is_ignored_in_injected_Func()
        {
            var container = new Container();

            container.Register<A>();
            container.Register<C>();

            var c = container.Resolve<C>();
            replacedert.IsNotNull(c);
            replacedert.IsInstanceOf<A>(c.F(container));
        }

19 Source : GHIssue198_Open_generics_resolve_fails_if_there_is_a_static_constructor.cs
with MIT License
from dadhi

[Test]
        public void Should_select_the_default_non_static_constructor()
        {
            var container = new Container();
            container.Register(typeof(ITest<>), typeof(Test<>), Reuse.Singleton);
            var resolved = container.Resolve<ITest<string>>();
            replacedert.IsNotNull(resolved);
        }

19 Source : GHIssue211_FEC_sometimes_is_20_precent_slower.cs
with MIT License
from dadhi

[Test]
        public void Should_get_a_singleton_constant_expression_from_the_cache()
        {
            var c = new Container();

            c.Register<A>();
            c.Register<B>(Reuse.Singleton);

            var a = c.Resolve<A>();

            replacedert.IsNotNull(a);
        }

19 Source : GHIssue307_Lift_up_the_requirement_for_the_Export_attribute_for_RegisterExports.cs
with MIT License
from dadhi

[Test]
        public void Test() 
        {
            var c = new Container();

            c.RegisterExportsAndTypes(typeof(A), typeof(B));

            var a = c.Resolve<A>();
            replacedert.IsNotNull(a);
        }

19 Source : GHIssue347_The_AsResolutionCall_option_and_or_WithFuncAndLazyWithoutRegistration_rule_are_not_respected.cs
with MIT License
from dadhi

[Test]
        public void RecursiveDependencyIssue_with_asResolutionCall()
        {
            var container = new Container();
            container.Register<A>(Reuse.Singleton);
            container.Register<B>();
            container.Register<C>(setup: Setup.With(asResolutionCall: true));

            var serviceA = container.Resolve<A>();
            replacedert.IsNotNull(serviceA);

            var actual = serviceA.Get(); 
            replacedert.AreSame(actual, serviceA);
        }

19 Source : GHIssue347_The_AsResolutionCall_option_and_or_WithFuncAndLazyWithoutRegistration_rule_are_not_respected.cs
with MIT License
from dadhi

[Test]
        public void RecursiveDependencyIssue_WithFuncAndLazyWithoutRegistration()
        {
            var container = new Container(rules => rules.WithFuncAndLazyWithoutRegistration());
            container.Register<A>(Reuse.Singleton);
            container.Register<B>();
            container.Register<C>();

            var serviceA = container.Resolve<A>();
            replacedert.IsNotNull(serviceA);

            var actual = serviceA.Get(); 
            replacedert.AreSame(actual, serviceA);
        }

19 Source : GHIssue352_Consider_resolving_the_variance_compatible_open_generic_the_same_as_for_collection_of_open_generics.cs
with MIT License
from dadhi

[Test]
        public void Contravariant_handler_can_be_Resolved_with_a_single_Resolve()
        {
            var container = new Container(rules => rules
                .With(FactoryMethod.ConstructorWithResolvableArguments)
                .WithVariantGenericTypesInResolve()
                .WithoutThrowOnRegisteringDisposableTransient());

            container.RegisterMany(new[] { typeof(GetInformationHandler).replacedembly }, Registrator.Interfaces, made: PropertiesAndFields.Auto);
            container.Register<MessageMediator>();

            // But this does not work!
            var handler = container.Resolve<IMessageHandler<PermissionedGetInformationRequest, DataIWantView>>();
            var result = handler.Handle(new PermissionedGetInformationRequest(), default);
            replacedert.IsNotNull(result);

            // and this does not work!
            var m = container.Resolve<MessageMediator>();
            var task = m.Send<PermissionedGetInformationRequest, DataIWantView>(new PermissionedGetInformationRequest(), default);
            replacedert.IsNotNull(task);
        }

19 Source : GHIssue352_Consider_resolving_the_variance_compatible_open_generic_the_same_as_for_collection_of_open_generics.cs
with MIT License
from dadhi

[Test]
        public void Contravariant_handler_can_be_Resolved_with_a_single_Resolve_even_with_MS_DI_rules()
        {
            var container = new Container(rules => rules
                .WithMicrosoftDependencyInjectionRules()
                .WithVariantGenericTypesInResolve());

            container.RegisterMany(new[] { typeof(GetInformationHandler).replacedembly }, Registrator.Interfaces, made: PropertiesAndFields.Auto);
            container.Register<MessageMediator>();

            // But this does not work!
            var handler = container.Resolve<IMessageHandler<PermissionedGetInformationRequest, DataIWantView>>();
            var result = handler.Handle(new PermissionedGetInformationRequest(), default);
            replacedert.IsNotNull(result);

            // and this does not work!
            var m = container.Resolve<MessageMediator>();
            var task = m.Send<PermissionedGetInformationRequest, DataIWantView>(new PermissionedGetInformationRequest(), default);
            replacedert.IsNotNull(task);
        }

19 Source : GHIssue352_Consider_resolving_the_variance_compatible_open_generic_the_same_as_for_collection_of_open_generics.cs
with MIT License
from dadhi

[Test]
        public void Contravariant_handler_should_be_Resolved_in_collection()
        {
            var container = new Container(rules => rules
                .With(FactoryMethod.ConstructorWithResolvableArguments)
                .WithoutThrowOnRegisteringDisposableTransient());

            container.RegisterMany(new[] { typeof(GetInformationHandler).replacedembly }, Registrator.Interfaces, made: PropertiesAndFields.Auto);

            // This works.
            var handlers = container.Resolve<IMessageHandler<PermissionedGetInformationRequest, DataIWantView>[]>();
            replacedert.AreEqual(1, handlers.Length);
            var result = handlers[0].Handle(new PermissionedGetInformationRequest(), default);
            replacedert.IsNotNull(result);
        }

19 Source : GHIssue352_Consider_resolving_the_variance_compatible_open_generic_the_same_as_for_collection_of_open_generics.cs
with MIT License
from dadhi

[Test]
        public void Contravariant_handler_should_be_Resolved_in_collection_and_the_variant_resolve_should_not_affect_it()
        {
            var container = new Container(rules => rules
                .WithVariantGenericTypesInResolve()
                .With(FactoryMethod.ConstructorWithResolvableArguments)
                .WithoutThrowOnRegisteringDisposableTransient());

            container.RegisterMany(new[] { typeof(GetInformationHandler).replacedembly }, Registrator.Interfaces, made: PropertiesAndFields.Auto);

            // This works.
            var handlers = container.Resolve<IMessageHandler<PermissionedGetInformationRequest, DataIWantView>[]>();
            replacedert.AreEqual(1, handlers.Length);
            var result = handlers[0].Handle(new PermissionedGetInformationRequest(), default);
            replacedert.IsNotNull(result);
        }

19 Source : GHIssue399_Func_dependency_on_Singleton_resolved_under_scope_breaks_after_disposing_scope_when_WithFuncAndLazyWithoutRegistration.cs
with MIT License
from dadhi

[Test]
        public void Test1()
        {
            var container = new Container(rules => rules.WithFuncAndLazyWithoutRegistration());

            container.Register<DepFactory>(Reuse.Singleton);
            container.Register<Dep>(Reuse.Transient);

            DepFactory factory = null;

            using (var scope = container.OpenScope())
            {
                factory = scope.Resolve<DepFactory>();
            }

            var dep = factory.Create();
            replacedert.IsNotNull(dep);

            container.Dispose();
        }

19 Source : GHIssue45_Consider_expression_interpretation_to_speed_up_first_time_resolution.cs
with MIT License
from dadhi

[Test]
        public void Interpreting_scoped_registered_delegates()
        {
            var container = new Container();

            container.Register<R>(Reuse.Scoped);

            container.RegisterDelegate(_ => new X(), Reuse.Scoped);
            container.RegisterDelegate(_ => new Y(), Reuse.ScopedOrSingleton);
            container.RegisterInstance(42);
            container.Register<S>(Reuse.Scoped);

            using (var scope = container.OpenScope())
            {
                var r = scope.Resolve<R>();

                replacedert.IsNotNull(r.X);
                replacedert.IsNotNull(r.Y);
                replacedert.AreEqual(42, r.Unknown);
                replacedert.AreEqual(42, r.S.Unknown);
            }
        }

19 Source : GHIssue4_Rule_for_Func_and_Lazy_to_be_resolved_even_without_requested_service_registered.cs
with MIT License
from dadhi

[Test]
        public void Func_dependency_of_not_registered_service_should_work()
        {
            var c = new Container(rules => rules.WithFuncAndLazyWithoutRegistration());

            c.Register<A>();
            var a = c.Resolve<A>();

            c.Register<B>();

            var b = a.LateResolveB();
            replacedert.IsNotNull(b);
        }

19 Source : Issue123_TipsForMigrationFromAutofac.cs
with MIT License
from dadhi

[Test]
        public void AsImplementedInterfaces()
        {
            var container = new Container();

            container.RegisterMany<FooBar>(serviceTypeCondition: type => type.IsInterface, reuse: Reuse.Singleton);

            replacedert.IsNotNull(container.Resolve<IFoo>());
            replacedert.IsNotNull(container.Resolve<IBar>());
            
            replacedert.Null(container.Resolve<FooBar>(IfUnresolved.ReturnDefault));
        }

19 Source : Issue123_TipsForMigrationFromAutofac.cs
with MIT License
from dadhi

[Test]
        public void Autofac_as_self()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<ANestedDep>().replacedelf();
            var container = builder.Build();

            var x = container.Resolve<ANestedDep>();

            replacedert.IsNotNull(x);
        }

19 Source : Issue148_NestedOptionalDependenciesPreventTheOuterDependencyFromInstantiating.cs
with MIT License
from dadhi

[Test]
        public void Should_use_optional_parameter_if_registered_in_nested_dependency()
        {
            var c = new Container();
            c.Register<F>(reuse: Reuse.Transient);
            c.Register<D>(reuse: Reuse.Transient);

            var x = c.Resolve<F>(); // x.D == null

            replacedert.IsNotNull(x.D);
        }

19 Source : Issue169_FalseAlarmCheckingScopeLifetimeConsistencyForFuncWrapper.cs
with MIT License
from dadhi

[Test]
        public void Test()
        {
            var ctr = new Container( Rules.Default.With(
                    propertiesAndFields: PropertiesAndFields.Auto ));

            ctr.Register<C>( reuse: Reuse.Singleton );

            var shortReuse = new ShortReuse();
            ctr.Register<B>( reuse: shortReuse );
            ctr.Register<D>( reuse: shortReuse );

            var c = ctr.Resolve<C>();
            var d = c.D();
            replacedert.IsNotNull(d.B.Value);
        }

19 Source : Issue178_FallbackContainerDisposesInstanceRegisteredInParent.cs
with MIT License
from dadhi

[Test]
        public void Test_WithPreventDisposalAndReplace()
        {
            var container = new Container();

            var a = new A();

            container.RegisterInstance<IA>(a, setup: Setup.With(preventDisposal: true));

            using (var c2 = container.CreateFacade())
            {
                c2.Register<B>(serviceKey: ContainerTools.FacadeKey);
                var b1 = c2.Resolve<B>();
                replacedert.IsNotNull(b1.A);
            }

            replacedert.IsFalse(a.IsDisposed);
        }

19 Source : Issue184_ReuseInNamedChildrenOfNamedScopes.cs
with MIT License
from dadhi

[Test]
        public void Test()
        {
            var container = new Container(Rules.Default
                // What is the scopeName? How it relates to scopes below?
                //.WithDefaultReuseInsteadOfTransient(Reuse.InCurrentNamedScope(scopeName)) 
                .With(propertiesAndFields: PropertiesAndFields.Auto)
                .WithoutThrowOnRegisteringDisposableTransient());

            container.Register(typeof(IFoo), typeof(Foo), Reuse.InCurrentNamedScope("Parent"));
            container.Register(typeof(IBar), typeof(Bar), Reuse.InCurrentNamedScope("Child"));

            var parentScope = container.OpenScope("Parent");
            var childScope = parentScope.OpenScope("Child");

            var bar = childScope.Resolve<IBar>();
            replacedert.IsNotNull(bar);
            replacedert.IsNotNull(bar.Foo);

            var parentFoo = parentScope.Resolve<IFoo>();
            replacedert.IsNotNull(parentFoo);
        }

19 Source : Issue213_LazySingletonsShouldBeResolvedAfterContainerIsDisposed.cs
with MIT License
from dadhi

[Test]
        public void LazySingletons_Should_Resolve_After_Container_Disposed()
        {
            var container = new Container();

            container.Register<Truc>(Reuse.Singleton, setup: Setup.With(preventDisposal: true));
            container.Register<Machine>(Reuse.Singleton);
            container.Register<Bidule>(Reuse.Scoped);

            Machine machine;
            using (var scope = container.OpenScope())
            {
                machine = scope.Resolve<Bidule>().Machine;
                replacedert.IsNotNull(machine);
            }

            replacedert.IsNotNull(machine.Truc);
        }

19 Source : Issue281_MakeAutofacMigrationEasier.cs
with MIT License
from dadhi

[Test]
        public void Test_CustomDelegate_Autofac()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<A>();
            builder.RegisterType<B>();
            builder.RegisterType<C>();
            builder.RegisterType<D>();

            using (var container = builder.Build())
            {
                var d = container.Resolve<D>();
                var c = d.CreateC();

                replacedert.IsNotNull(c.A);
                replacedert.IsNotNull(c.B);
            }
        }

See More Examples