Beispiel #1
0
        public void DisposeOfScopeDisposesContainer()
        {
            var container = new Mock <IContainer>();

            container.Setup(c => c.Dispose()).Verifiable();

            var scope = new AutoPocoDependencyScope(container.Object);

            scope.Dispose();

            container.Verify();
        }
Beispiel #2
0
        public void GetSingleService()
        {
            var service   = new Class1();
            var container = new Mock <IContainer>();

            container.Setup(c => c.GetService(typeof(IInterface1)))
            .Returns(service);

            var scope  = new AutoPocoDependencyScope(container.Object);
            var result = scope.GetService(typeof(IInterface1));

            Assert.AreEqual(service, result);
        }
Beispiel #3
0
        public void PassContainerFromOwinToRequest()
        {
            var handler   = new PublicHandler();
            var request   = new HttpRequestMessage();
            var container = new Mock <IContainer>();

            container.Setup(c => c.GetService(typeof(Class1)))
            .Returns("container");

            var owinContext = new OwinContext();

            owinContext.Set("autopoco:container", container.Object);

            request.Properties["MS_OwinContext"] = owinContext;

            handler.SendAsyncPublic(request).Wait();

            AutoPocoDependencyScope result = (AutoPocoDependencyScope)request.Properties[HttpPropertyKeys.DependencyScope];

            Assert.AreEqual("container", result.GetService(typeof(Class1)));
        }