public void Ninject_Container_Fails_Without_Match() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("Does.Not.Work"); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IBadCode>().To<BadCode>(); Assert.Throws<NullReferenceException>(() => container.Kernel.Get<IBadCode>()); }
public void Ninject_Container_Allow_Strict_Matching() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests.Fakes.IBadCode"); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IBadCode>().To<BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get<IBadCode>()); }
public void Ninject_Container_Supports_Aspects() { var ct = new NinjectAspectContainer(); SnapConfiguration.For(ct).Configure(c => { c.IncludeNamespace("Snap.Tests"); c.RegisterInterceptor<HandleErrorInterceptor>(); }); ct.Kernel.Bind<IBadCode>().To<BadCode>(); var badCode = ct.Kernel.Get<IBadCode>(); Assert.DoesNotThrow(badCode.GiddyUp); }
public void Ninject_Container_Allow_Wildcard_Matching() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests*"); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IBadCode>().To<BadCode>(); var badCode = container.Kernel.Get<IBadCode>(); Assert.DoesNotThrow(badCode.GiddyUp); Assert.IsTrue(badCode.GetType().Name.Equals("IBadCodeProxy")); }
public void Type_Inclusion_Adds_Type_By_Names() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeType("SnapTests.Fakes.IBadCode"); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IBadCode>().To<BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get<IBadCode>()); }
public void Namespace_Inclusion_Adds_Namespace_Of_A_Given_Type() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { // have the same namespace as IBadCode c.IncludeNamespaceOf<DummyDependency>(); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IBadCode>().To<BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get<IBadCode>()); }
public void Ninject_Container_Ignores_Types_Without_Decoration() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests*"); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<INotInterceptable>().To<NotInterceptable>(); var code = container.Kernel.Get<INotInterceptable>(); Assert.IsFalse(code.GetType().Name.Equals("INotInterceptableProxy")); }
public void When_resolving_services_from_container_SNAP_should_load_dynamicproxygenassebmly2_in_appdomain_only_once() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespaceOf<IBadCode>(); c.Bind<SecondInterceptor>().To<SecondAttribute>(); c.Bind<FirstInterceptor>().To<FirstAttribute>(); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IOrderedCode>().To<OrderedCode>(); container.Kernel.Bind<IBadCode>().To<BadCode>(); var orderedCode = container.Kernel.Get<IOrderedCode>(); var badCode = container.Kernel.Get<IBadCode>(); orderedCode.RunInOrder(); Assert.AreEqual("First", OrderedCode.Actions[1]); Assert.AreEqual("Second", OrderedCode.Actions[0]); Assert.DoesNotThrow(badCode.GiddyUp); var dynamicProxyGenerationAssemblies = AppDomain.CurrentDomain .GetAssemblies() .Where(assembly => assembly.GetName().Name == "DynamicProxyGenAssembly2") .ToList(); Assert.That(dynamicProxyGenerationAssemblies.Count, Is.EqualTo(2)); // both signed and unsigned. Assert.IsNotNull(dynamicProxyGenerationAssemblies.FirstOrDefault(a => a.GetName().GetPublicKey().Length > 0)); Assert.IsNotNull(dynamicProxyGenerationAssemblies.FirstOrDefault(a => a.GetName().GetPublicKey().Length == 0)); }
public void Ninject_Supports_Types_Without_Interfaces() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests.Fakes*"); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IDependency>().To<DummyDependency>(); container.Kernel.Bind<TypeWithoutInterface>().To<TypeWithoutInterface>(); var typeWithoutInterface = container.Kernel.Get<TypeWithoutInterface>(); Assert.DoesNotThrow(typeWithoutInterface.Foo); Assert.IsTrue(typeWithoutInterface.GetType().Name.Equals("TypeWithoutInterfaceProxy")); container.Kernel.Bind<TypeWithInterfaceInBaseClass>().To<TypeWithInterfaceInBaseClass>(); var typeWithInterfaceInBaseClass = container.Kernel.Get<TypeWithInterfaceInBaseClass>(); Assert.DoesNotThrow(typeWithInterfaceInBaseClass.Foo); Assert.IsTrue(typeWithInterfaceInBaseClass.GetType().Name.Equals("TypeWithInterfaceInBaseClassProxy")); }
public void Ninject_Supports_Resolving_Only_Selected_Aspects_From_Container() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests.*"); c.Bind<FirstInterceptor>().To<FirstAttribute>(); c.Bind<SecondInterceptor>().To<SecondAttribute>(); c.Aspects(typeof(FirstInterceptor)).KeepInContainer(); }); container.Kernel.Bind<IOrderedCode>().To<OrderedCode>(); container.Kernel.Bind<FirstInterceptor>().ToConstant(new FirstInterceptor("first_kept_in_container")); container.Kernel.Bind<SecondInterceptor>().ToConstant(new SecondInterceptor("second_kept_in_container")); var orderedCode = container.Kernel.Get<IOrderedCode>(); orderedCode.RunInOrder(); // first interceptor is resolved from container, while second one is via new() CollectionAssert.AreEquivalent( OrderedCode.Actions, new[] { "first_kept_in_container", "Second" }); }
public void Ninject_Container_Supports_Multiple_Method_Aspects() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests*"); c.Bind<FirstInterceptor>().To<FirstAttribute>(); c.Bind<SecondInterceptor>().To<SecondAttribute>(); }); container.Kernel.Bind<IOrderedCode>().To<OrderedCode>(); var badCode = container.Kernel.Get<IOrderedCode>(); badCode.RunInOrder(); Assert.AreEqual("First", OrderedCode.Actions[0]); Assert.AreEqual("Second", OrderedCode.Actions[1]); }
public void Namespace_Inclusion_Adds_Wildcards() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespaceRoot("SnapTests"); c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>(); }); container.Kernel.Bind<IBadCode>().To<BadCode>(); Assert.DoesNotThrow(() => container.Kernel.Get<IBadCode>()); }
public void Ninject_Container_Supports_Class_Aspects() { var container = new NinjectAspectContainer(); SnapConfiguration.For(container).Configure(c => { c.IncludeNamespace("SnapTests*"); c.Bind<FourthClassInterceptor>().To<FourthClassAttribute> (); }); container.Kernel.Bind<IOrderedCode>().To<ClassOrderedCode>(); var code = container.Kernel.Get<IOrderedCode>(); code.RunInOrder(); Assert.AreEqual("Fourth", OrderedCode.Actions[0]); }