示例#1
0
        public LimitsHttpServiceV1Test()
        {
            _persistence = new LimitsMemoryPersistence();
            _controller  = new LimitsController();
            _service     = new LimitsHttpServiceV1();

            IReferences references = References.FromTuples(
                new Descriptor("pip-services-limits-dotnet", "persistence", "memory", "default", "1.0"), _persistence,
                new Descriptor("pip-services-limits-dotnet", "controller", "default", "default", "1.0"), _controller,
                new Descriptor("pip-services-limits-dotnet", "service", "http", "default", "1.0"), _service
                );

            _controller.SetReferences(references);

            _persistence.OpenAsync(null).Wait();

            _service.Configure(HttpConfig);
            _service.SetReferences(references);
            _service.OpenAsync(null).Wait();
        }
示例#2
0
        public LimitsHttpClientV1Test()
        {
            _persistence = new LimitsMemoryPersistence();
            _persistence.Configure(new ConfigParams());

            _controller = new LimitsController();
            _controller.Configure(new ConfigParams());

            _client  = new LimitsHttpClientV1();
            _service = new LimitsHttpServiceV1();


            ConfigParams HttpConfig = ConfigParams.FromTuples(
                "connection.protocol", "http",
                "connection.host", "localhost",
                "connection.port", 3000
                );

            _service.Configure(HttpConfig);
            _client.Configure(HttpConfig);

            _fixture = new LimitsClientV1Fixture(_client);

            IReferences references = References.FromTuples(
                new Descriptor("pip-services-limits-dotnet", "persistence", "memory", "default", "1.0"), _persistence,
                new Descriptor("pip-services-limits-dotnet", "controller", "default", "default", "1.0"), _controller,
                new Descriptor("pip-services-limits-dotnet", "client", "http", "default", "1.0"), _client,
                new Descriptor("pip-services-limits-dotnet", "service", "http", "default", "1.0"), _service
                );

            _controller.SetReferences(references);
            _client.SetReferences(references);
            _service.SetReferences(references);

            _persistence.OpenAsync(null).Wait();
            _service.OpenAsync(null).Wait();
            _client.OpenAsync(null).Wait();
        }
示例#3
0
        public LimitsDirectClientV1Test()
        {
            _persistence = new LimitsMemoryPersistence();
            _persistence.Configure(new ConfigParams());

            _controller = new LimitsController();
            _controller.Configure(new ConfigParams());

            _client = new LimitsDirectClientV1();

            IReferences references = References.FromTuples(
                new Descriptor("pip-services-limits-dotnet", "persistence", "memory", "default", "1.0"), _persistence,
                new Descriptor("pip-services-limits-dotnet", "controller", "default", "default", "1.0"), _controller,
                new Descriptor("pip-services-limits-dotnet", "client", "direct", "default", "1.0"), _client
                );

            _controller.SetReferences(references);

            _client.SetReferences(references);

            _fixture = new LimitsClientV1Fixture(_client);

            _persistence.OpenAsync(null).Wait();
        }
        private void describe_()
        {
            Mock <IContainerService> mockContainerService = null;
            LimitsController         LimitsController     = null;
            string handle = null;

            Mock <IContainer> mockContainer = null;

            before = () =>
            {
                mockContainerService = new Mock <IContainerService>();
                LimitsController     = new LimitsController(mockContainerService.Object);

                handle = Guid.NewGuid().ToString();

                mockContainer = new Mock <IContainer>();
                mockContainerService.Setup(x => x.GetContainerByHandle(handle)).Returns(mockContainer.Object);
            };

            describe["#LimitMemory"] = () =>
            {
                const ulong       limitInBytes = 876;
                MemoryLimits      limits       = null;
                IHttpActionResult result       = null;

                before = () =>
                {
                    limits = new MemoryLimits {
                        LimitInBytes = limitInBytes
                    };
                };
                act = () =>
                {
                    result = LimitsController.LimitMemory(handle, limits);
                };

                it["sets limits on the container"] = () =>
                {
                    mockContainer.Verify(x => x.LimitMemory(limitInBytes));
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>())).Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };

            describe["#CurrentMemoryLimit"] = () =>
            {
                it["returns the current limit on the container"] = () =>
                {
                    mockContainer.Setup(x => x.CurrentMemoryLimit()).Returns(3072);
                    var result     = LimitsController.CurrentMemoryLimit(handle);
                    var jsonResult = result.should_cast_to <JsonResult <MemoryLimits> >();
                    jsonResult.Content.LimitInBytes.should_be(3072);
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>())).Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        var result = LimitsController.CurrentMemoryLimit(handle);
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };

            describe["#LimitCpu"] = () =>
            {
                IHttpActionResult result = null;
                const int         weight = 5;
                act = () =>
                {
                    var limits = new CpuLimits {
                        Weight = weight
                    };
                    result = LimitsController.LimitCpu(handle, limits);
                };

                it["sets limits on the container"] = () =>
                {
                    mockContainer.Verify(x => x.LimitCpu(weight));
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>())).Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };

            describe["#CurrentCpuLimit"] = () =>
            {
                it["returns the current limit on the container"] = () =>
                {
                    mockContainer.Setup(x => x.CurrentCpuLimit()).Returns(6);
                    var result     = LimitsController.CurrentCpuLimit(handle);
                    var jsonResult = result.should_cast_to <JsonResult <CpuLimits> >();
                    jsonResult.Content.Weight.should_be(6);
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>())).Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        var result = LimitsController.CurrentCpuLimit(handle);
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };

            describe["#LimitDisk"] = () =>
            {
                IHttpActionResult result = null;
                const ulong       bytes  = 5;
                act = () =>
                {
                    var limits = new DiskLimits {
                        ByteHard = bytes
                    };
                    result = LimitsController.LimitDisk(handle, limits);
                };

                it["sets limits on the container"] = () =>
                {
                    mockContainer.Verify(x => x.LimitDisk(bytes));
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>())).Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };

            describe["#CurrentDiskLimit"] = () =>
            {
                it["returns the current limit on the container"] = () =>
                {
                    mockContainer.Setup(x => x.CurrentDiskLimit()).Returns(6);
                    var result     = LimitsController.CurrentDiskLimit(handle);
                    var jsonResult = result.should_cast_to <JsonResult <DiskLimits> >();
                    jsonResult.Content.ByteHard.should_be(6);
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>()))
                        .Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        var result = LimitsController.CurrentDiskLimit(handle);
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };
        }
        public void SetUp()
        {
            _mediator = Substitute.For <IMediator>();

            _sut = new LimitsController(_mediator);
        }
示例#6
0
        private void describe_()
        {
            Mock <IContainerService> mockContainerService = null;
            LimitsController         LimitsController     = null;
            string handle = null;

            Mock <IContainer> mockContainer = null;

            before = () =>
            {
                mockContainerService = new Mock <IContainerService>();
                LimitsController     = new LimitsController(mockContainerService.Object);

                handle = Guid.NewGuid().ToString();

                mockContainer = new Mock <IContainer>();
                mockContainerService.Setup(x => x.GetContainerByHandle(handle)).Returns(mockContainer.Object);
            };

            describe["#CurrentMemoryLimit"] = () =>
            {
                it["returns the current limit on the container"] = () =>
                {
                    mockContainer.Setup(x => x.CurrentMemoryLimit()).Returns(3072);
                    var result     = LimitsController.CurrentMemoryLimit(handle);
                    var jsonResult = result.should_cast_to <JsonResult <MemoryLimits> >();
                    jsonResult.Content.LimitInBytes.should_be(3072);
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>())).Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        var result = LimitsController.CurrentMemoryLimit(handle);
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };

            describe["#CurrentCpuLimit"] = () =>
            {
                it["returns the current limit on the container"] = () =>
                {
                    mockContainer.Setup(x => x.CurrentCpuLimit()).Returns(6);
                    var result     = LimitsController.CurrentCpuLimit(handle);
                    var jsonResult = result.should_cast_to <JsonResult <CpuLimits> >();
                    jsonResult.Content.Weight.should_be(6);
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>())).Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        var result = LimitsController.CurrentCpuLimit(handle);
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };

            describe["#CurrentDiskLimit"] = () =>
            {
                it["returns the current limit on the container"] = () =>
                {
                    mockContainer.Setup(x => x.CurrentDiskLimit()).Returns(6);
                    var result     = LimitsController.CurrentDiskLimit(handle);
                    var jsonResult = result.should_cast_to <JsonResult <DiskLimits> >();
                    jsonResult.Content.ByteHard.should_be(6);
                };

                context["when the container does not exist"] = () =>
                {
                    before = () =>
                    {
                        mockContainerService.Setup(x => x.GetContainerByHandle(It.IsAny <string>()))
                        .Returns(null as IContainer);
                    };

                    it["Returns not found"] = () =>
                    {
                        var result = LimitsController.CurrentDiskLimit(handle);
                        result.should_cast_to <NotFoundResult>();
                    };
                };
            };
        }