Beispiel #1
0
        public void ServiceScoped_registrations_create_different_instances_for_different_service_instances()
        {
            var hostInfo = DreamTestHelper.CreateRandomPortHost(new XDoc("config")
                                                                .Start("components")
                                                                .Start("component")
                                                                .Attr("scope", "service")
                                                                .Attr("implementation", typeof(LifetimeTest).AssemblyQualifiedName)
                                                                .Attr("type", typeof(ILifetimeTest).AssemblyQualifiedName)
                                                                .End()
                                                                .End());
            var service1 = DreamTestHelper.CreateService(
                hostInfo,
                typeof(ContainerTestService),
                "test1",
                new XDoc("config").Elem("servicescopetest", true));

            CheckResponse(service1.AtLocalHost.At("servicescope").Get(new Result <DreamMessage>()).Wait());
            var service2 = DreamTestHelper.CreateService(
                hostInfo,
                typeof(ContainerTestService),
                "test2",
                new XDoc("config").Elem("servicescopetest", true));

            CheckResponse(service2.AtLocalHost.At("servicescope").Get(new Result <DreamMessage>()).Wait());
            var serviceScoped1 = ContainerTestService.ServiceScope[service1.AtLocalHost.Uri.Path];
            var serviceScoped2 = ContainerTestService.ServiceScope[service2.AtLocalHost.Uri.Path];

            Assert.IsNotNull(serviceScoped1);
            Assert.IsNotNull(serviceScoped2);
            Assert.AreNotSame(serviceScoped1, serviceScoped2);
            Assert.IsFalse(serviceScoped1.IsDisposed);
            Assert.IsFalse(serviceScoped2.IsDisposed);
        }
Beispiel #2
0
        public void Can_shadow_service_registration()
        {
            var hostInfo = DreamTestHelper.CreateRandomPortHost(new XDoc("config")
                                                                .Start("components")
                                                                .Start("component")
                                                                .Attr("implementation", typeof(Foo).AssemblyQualifiedName)
                                                                .Attr("type", typeof(IFoo).AssemblyQualifiedName)
                                                                .End()
                                                                .End());
            var service = DreamTestHelper.CreateService(hostInfo, typeof(ContainerTestService), "test", new XDoc("config")
                                                        .Start("components")
                                                        .Start("component")
                                                        .Attr("scope", "service")
                                                        .Attr("implementation", typeof(Fu).AssemblyQualifiedName)
                                                        .Attr("type", typeof(IFoo).AssemblyQualifiedName)
                                                        .End()
                                                        .Start("component")
                                                        .Attr("scope", "request")
                                                        .Attr("implementation", typeof(Faux).AssemblyQualifiedName)
                                                        .Attr("type", typeof(IFoo).AssemblyQualifiedName)
                                                        .End()
                                                        .End());

            CheckResponse(service.AtLocalHost.At("shadow").Get(new Result <DreamMessage>()).Wait());
            Assert.IsNotNull(ContainerTestService.Shadowed);
            Assert.AreEqual(typeof(Faux), ContainerTestService.Shadowed.GetType());
        }
 public void Can_throw_in_Start_with_exception_translators_in_place()
 {
     try {
         _serviceInfo = DreamTestHelper.CreateService(_hostInfo, typeof(TestExceptionalService), "throwsonstart", new XDoc("config").Elem("throw-on-start", true));
         Assert.Fail("didn't throw on start");
     } catch (Exception e) {
         Assert.IsTrue(e.Message.EndsWith("BadRequest: throwing in service start"), e.Message);
     }
 }
Beispiel #4
0
        public void Child_that_fails_first_time_around_can_still_be_created()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "empty")
                          .Elem("sid", "sid://mindtouch.com/TestParentService");
            var  serviceInfo = DreamTestHelper.CreateService(_hostInfo, config);
            Plug parent      = serviceInfo.WithPrivateKey().AtLocalHost;
            var  response    = parent.At("createandretychild").GetAsync().Wait();

            Assert.IsTrue(response.IsSuccessful, response.ToText());
        }
Beispiel #5
0
        public void Can_register_at_service_level()
        {
            var hostInfo = DreamTestHelper.CreateRandomPortHost();
            var service  = DreamTestHelper.CreateService(hostInfo, typeof(ContainerTestService), "test", new XDoc("config")
                                                         .Start("components")
                                                         .Start("component")
                                                         .Attr("implementation", typeof(Foo).AssemblyQualifiedName)
                                                         .Attr("type", typeof(IFoo).AssemblyQualifiedName)
                                                         .End()
                                                         .End());

            CheckResponse(service.AtLocalHost.At("registerfoo").Get(new Result <DreamMessage>()).Wait());
        }
Beispiel #6
0
        public void Creating_two_services_at_same_uri_fails()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "empty")
                          .Elem("sid", "sid://mindtouch.com/TestEmptyService");
            var serviceInfo = DreamTestHelper.CreateService(_hostInfo, config);
            var response    = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();

            Assert.AreEqual("/empty", response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestEmptyService']/path")].Contents);
            try {
                serviceInfo = DreamTestHelper.CreateService(_hostInfo, config);
                Assert.Fail();
            } catch { }
        }
Beispiel #7
0
        public void RequestContainer_can_inject_current_dream_context_into_instances()
        {
            var hostInfo = DreamTestHelper.CreateRandomPortHost();
            var service  = DreamTestHelper.CreateService(hostInfo, typeof(ContainerTestService), "test", new XDoc("config")
                                                         .Start("components")
                                                         .Start("component")
                                                         .Attr("scope", "request")
                                                         .Attr("implementation", typeof(CanIHazDreamContextPleeze).AssemblyQualifiedName)
                                                         .Attr("type", typeof(ICanHazDreamContext).AssemblyQualifiedName)
                                                         .End()
                                                         .End());

            CheckResponse(service.AtLocalHost.At("contextinjection").Get(new Result <DreamMessage>()).Wait());
        }
Beispiel #8
0
        public void Creating_two_child_services_at_same_uri_fails()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "empty")
                          .Elem("sid", "sid://mindtouch.com/TestParentService");
            var  serviceInfo = DreamTestHelper.CreateService(_hostInfo, config);
            Plug parent      = serviceInfo.WithPrivateKey().AtLocalHost;
            var  response    = parent.At("createchild").GetAsync().Wait();

            Assert.IsTrue(response.IsSuccessful, response.ToText());
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(1, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestChildService']")].ListLength);
            response = parent.At("createchild").GetAsync().Wait();
            Assert.IsFalse(response.IsSuccessful, response.ToText());
        }
Beispiel #9
0
        public void Service_level_container_scoped_instances_are_not_disposed_at_end_of_request()
        {
            var hostInfo = DreamTestHelper.CreateRandomPortHost();
            var service  = DreamTestHelper.CreateService(hostInfo, typeof(ContainerTestService), "test", new XDoc("config")
                                                         .Start("components")
                                                         .Start("component")
                                                         .Attr("scope", "service")
                                                         .Attr("implementation", typeof(LifetimeTest).AssemblyQualifiedName)
                                                         .Attr("type", typeof(ILifetimeTest).AssemblyQualifiedName)
                                                         .End()
                                                         .End());

            CheckResponse(service.AtLocalHost.At("lifetime").Get(new Result <DreamMessage>()).Wait());
            Assert.IsNotNull(ContainerTestService.LifetimeTest);
            Assert.IsFalse(ContainerTestService.LifetimeTest.IsDisposed);
        }
Beispiel #10
0
        public void Child_service_throwing_on_start_does_not_grab_the_uri()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "empty")
                          .Elem("sid", "sid://mindtouch.com/TestParentService");
            var  serviceInfo = DreamTestHelper.CreateService(_hostInfo, config);
            Plug parent      = serviceInfo.WithPrivateKey().AtLocalHost;
            var  response    = parent.At("createbadstartchild").With("throw", "true").Get(new Result <DreamMessage>()).Wait();

            Assert.IsFalse(response.IsSuccessful, response.ToText());
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(0, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStartService']")].ListLength);
            response = parent.At("createbadstartchild").With("throw", "false").Get(new Result <DreamMessage>()).Wait();
            Assert.IsTrue(response.IsSuccessful, response.ToText());
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(1, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStartService']")].ListLength);
        }
Beispiel #11
0
        public void Child_service_throwing_on_delete_does_not_prevent_cleanup_and_restart_of_child()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "empty")
                          .Elem("sid", "sid://mindtouch.com/TestParentService");
            var  serviceInfo = DreamTestHelper.CreateService(_hostInfo, config);
            Plug parent      = serviceInfo.WithPrivateKey().AtLocalHost;
            var  response    = parent.At("createbadchild").GetAsync().Wait();

            Assert.IsTrue(response.IsSuccessful, response.ToText());
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(1, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStopService']")].ListLength);
            response = parent.At("destroybadchild").GetAsync().Wait();
            Assert.IsTrue(response.IsSuccessful, response.ToText());
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(0, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStopService']")].ListLength);
        }
Beispiel #12
0
        public void Service_throwing_on_delete_does_not_prevent_cleanup_and_restart()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "bad")
                          .Elem("sid", "sid://mindtouch.com/TestBadStopService");
            var serviceInfo = DreamTestHelper.CreateService(_hostInfo, config);
            var response    = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();

            Assert.AreEqual("/bad", response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStopService']/path")].Contents);
            response = serviceInfo.WithPrivateKey().AtLocalHost.DeleteAsync().Wait();
            Assert.IsTrue(response.IsSuccessful, response.ToText());
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(0, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStopService']")].ListLength);
            DreamTestHelper.CreateService(_hostInfo, config);
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual("/bad", response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStopService']/path")].Contents);
        }
Beispiel #13
0
        public void Can_set_service_scope_registration_on_provided_container()
        {
            var builder = new ContainerBuilder();

            builder.Register <Foo>().As <IFoo>().InScope(DreamContainerScope.Service);
            var hostInfo = DreamTestHelper.CreateRandomPortHost(new XDoc("config"), builder.Build());
            var service  = DreamTestHelper.CreateService(hostInfo, typeof(ContainerTestService), "test");

            CheckResponse(service.AtLocalHost.At("scope").Get(new Result <DreamMessage>()).Wait());
            var serviceScope1 = ContainerTestService.Scoped;

            Assert.IsNotNull(serviceScope1);
            CheckResponse(service.AtLocalHost.At("scope").Get(new Result <DreamMessage>()).Wait());
            var serviceScope2 = ContainerTestService.Scoped;

            Assert.IsNotNull(serviceScope2);
            Assert.AreSame(serviceScope1, serviceScope2);
        }
Beispiel #14
0
        public void Service_throwing_on_start_does_not_grab_the_uri()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "bad")
                          .Elem("throw", "true")
                          .Elem("sid", "sid://mindtouch.com/TestBadStartService");

            try {
                DreamTestHelper.CreateService(_hostInfo, config);
                Assert.Fail("service creation should have failed");
            } catch { }
            var response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();

            Assert.AreEqual(0, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStartService']")].ListLength);
            config = new XDoc("config")
                     .Elem("path", "bad")
                     .Elem("throw", "false")
                     .Elem("sid", "sid://mindtouch.com/TestBadStartService");
            DreamTestHelper.CreateService(_hostInfo, config);
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(1, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStartService']")].ListLength);
        }
Beispiel #15
0
        public void ServiceTest()
        {
            string sid      = "http://services.mindtouch.com/dream/test/2007/03/sample";
            string sidInner = "http://services.mindtouch.com/dream/test/2007/03/sample-inner";

            _host.At("blueprints").Post(new XDoc("blueprint").Elem("assembly", "test.mindtouch.dream").Elem("class", "MindTouch.Dream.Test.SampleService"));
            _host.At("blueprints").Post(new XDoc("blueprint").Elem("assembly", "test.mindtouch.dream").Elem("class", "MindTouch.Dream.Test.SampleInnerService"));
            DreamServiceInfo info = DreamTestHelper.CreateService(_hostinfo,
                                                                  new XDoc("config")
                                                                  .Elem("path", "sample")
                                                                  .Elem("sid", sid)
                                                                  .Start("prologue")
                                                                  .Attr("name", "dummy")
                                                                  .Value("p0")
                                                                  .End()
                                                                  .Start("epilogue")
                                                                  .Attr("name", "dummy")
                                                                  .Value("e0")
                                                                  .End()
                                                                  .Elem("apikey", "xyz"));
            Plug service = info.AtLocalHost.With("apikey", "xyz");

            // TODO (steveb):
            //  1) check that http://localhost:8081/host/services contains the newly started service
            //  2) check that http://localhost:8081/host/services contains the inner service of the newly started service
            //  3) check that http://localhost:8081/host/sample has the expected prologues/epilogues
            //  4) check that http://localhost:8081/host/sample/inner has the 'sample' as owner
            //  5) check that http://localhost:8081/host/sample/inner has the expected prologues/epilogues

            service.Delete();

            //  6) check that http://localhost:8081/host/services does not contain the started service
            //  7) check that http://localhost:8081/host/services does not contain the inner service

            _host.At("blueprints", XUri.DoubleEncodeSegment(sid)).Delete();
            _host.At("blueprints", XUri.DoubleEncodeSegment(sidInner)).Delete();
        }
 public void FixtureSetup()
 {
     _hostInfo    = DreamTestHelper.CreateRandomPortHost();
     _serviceInfo = DreamTestHelper.CreateService(_hostInfo, typeof(TestExceptionalService), "test");
 }
 public void Init()
 {
     _hostInfo = DreamTestHelper.CreateRandomPortHost();
     _parent   = DreamTestHelper.CreateService(_hostInfo, typeof(InheritanceParent), "parent");
     _child    = DreamTestHelper.CreateService(_hostInfo, typeof(InheritanceChild), "child");
 }