예제 #1
0
        public virtual ResultSingle <T> ReceiveSingle <T>() where T : CloudObject, new()
        {
            // The client sends back a result. the result has
            // a code and other detail to indicate whether the
            // result was a success. the data secion stores the
            // query result. The result is single if only one
            // result is sent and multiple if it sends back a
            // collection of data.

            var message = _queueServer.GetMessage();

            ResultSingle <T> result = null;

            if (message != null)
            {
                IBasicProperties props = message.BasicProperties;
                _queueServer.LastCorrelationId = props.CorrelationId;

                byte[] body = message.Body;

                T   seed        = new T();
                var messageBody = Encoding.UTF8.GetString(body);
                result = ResultSingle <T> .ConvertObject(messageBody, seed);
            }

            return(result);
        }
예제 #2
0
        private async Task <ResultSingle <ObjectT> > GetAsync <ObjectT>(ObjectT seed, IFlurlRequest flurlRequest)
            where ObjectT : ICloudObject, new()
        {
            string json = await flurlRequest.GetStringAsync();

            return(ResultSingle <ObjectT> .ConvertObject(json, seed));
        }
예제 #3
0
        private async Task <ResultSingle <ObjectT> > DeleteAsync <ObjectT>(ObjectT seed, IFlurlRequest flurlRequest)
            where ObjectT : ICloudObject, new()
        {
            string json = await flurlRequest.SendJsonAsync(
                HttpMethod.Delete, seed)
                          .ReceiveString();

            return(ResultSingle <ObjectT> .ConvertObject(json, seed));
        }
예제 #4
0
        public void TestSearch()
        {
            // Arrange
            var mockRuntime = new Mock <Runtime>(
                QueueMode.Server | QueueMode.Client,
                180, Enviorenment.Development
                )
            {
                CallBase = true
            };

            mockRuntime.Setup(x => x.ReceiveSingle <SearchResult>())
            .Returns(ResultSingle <SearchResult> .ConvertObject(
                         GetInput("test-input-a"), new SearchResult()));
            mockRuntime.Setup(x => x.ReceiveSingle <SearchResult>())
            .Returns(ResultSingle <SearchResult> .ConvertObject(
                         GetInput("test-input-b"), new SearchResult()));

            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .BuildServiceProvider();

            var factory = serviceProvider.GetService <ILoggerFactory>();

            var logger = factory.CreateLogger <SearchController>();

            var controller = new SearchController(
                logger, mockRuntime.Object);

            // Act
            var result = controller.Get("docker");

            // Assert
            var okResult = result as JsonResult;

            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
            Assert.IsType <Result <List <SearchResult> > >(okResult.Value);
        }