public void run_aggregated_query_through_http_endpoint()
        {
            var query = new AggregatedQuery();

            query.AddQuery(new AggregationEndpoint.Query1 {
                Name = "Jeremy Maclin"
            });
            query.Resource <AggregationEndpoint.Resource2>();
            query.AddQuery(new AggregationEndpoint.Input2());
            query.Resource <AggregationEndpoint.Resource4>();

            TestHost.Scenario(_ =>
            {
                _.Post.Json(query);

                _.StatusCodeShouldBeOk();
                _.ContentTypeShouldBe("application/json");

                var json = _.Response.Body.ReadAsText();

                var response =
                    new JsonSerializer().Deserialize <AggregationResponse>(new JsonTextReader(new StringReader(json)));

                response.responses.Count().ShouldBe(4);
                response.responses.Select(x => x.type)
                .ShouldHaveTheSameElementsAs("resource-1", "resource-2", "resource-3", "resource-4");
            });
        }
        public void use_aggregated_query_reader()
        {
            var query = new AggregatedQuery();

            query.AddQuery(new AggregationEndpoint.Query1 {
                Name = "Jeremy Maclin"
            });
            query.Resource <AggregationEndpoint.Resource2>();
            query.AddQuery(new AggregationEndpoint.Input2());
            query.Resource <AggregationEndpoint.Resource4>();

            var json = JsonUtil.ToJson(query);

            var messageTypes = TestHost.Service <IClientMessageCache>();

            var readQuery = new AggregatedQueryReader().Read(new JsonSerializer(), messageTypes, json);

            readQuery.ShouldNotBeNull();
            readQuery.queries[0].type.ShouldBe("query-1");
            readQuery.queries[0].query.ShouldBeOfType <AggregationEndpoint.Query1>()
            .Name.ShouldBe("Jeremy Maclin");

            readQuery.queries[1].type.ShouldBe("resource-2");
            readQuery.queries[2].type.ShouldBe("input-2");
            readQuery.queries[3].query.ShouldBeNull();
        }
        public void aggregate_request_through_the_initial_endpoint()
        {
            var container = TestHost.Service <IContainer>();

            using (var nested = container.GetNestedContainer())
            {
                var aggregator = nested.GetInstance <Aggregator>();

                var query = new AggregatedQuery();
                query.AddQuery(new AggregationEndpoint.Query1 {
                    Name = "Jeremy Maclin"
                });
                query.Resource <AggregationEndpoint.Resource2>();
                query.AddQuery(new AggregationEndpoint.Input2());
                query.Resource <AggregationEndpoint.Resource4>();

                var aggregatedResponse = aggregator.QueryAggregate(query).GetAwaiter().GetResult();

                aggregatedResponse.responses[0].result.ShouldBeOfType <AggregationEndpoint.Resource1>()
                .Name.ShouldBe("Jeremy Maclin");

                aggregatedResponse.responses[1].result.ShouldBeOfType <AggregationEndpoint.Resource2>();
                aggregatedResponse.responses[2].result.ShouldBeOfType <AggregationEndpoint.Resource3>();
                aggregatedResponse.responses[3].result.ShouldBeOfType <AggregationEndpoint.Resource4>();
            }
        }
        public void use_aggregated_query_reader()
        {
            var query = new AggregatedQuery();
            query.AddQuery(new AggregationEndpoint.Query1 { Name = "Jeremy Maclin" });
            query.Resource<AggregationEndpoint.Resource2>();
            query.AddQuery(new AggregationEndpoint.Input2());
            query.Resource<AggregationEndpoint.Resource4>();

            var json = JsonUtil.ToJson(query);

            var messageTypes = TestHost.Service<IClientMessageCache>();

            var readQuery = new AggregatedQueryReader().Read(new JsonSerializer(), messageTypes, json);

            readQuery.ShouldNotBeNull();
            readQuery.queries[0].type.ShouldEqual("query-1");
            readQuery.queries[0].query.ShouldBeOfType<AggregationEndpoint.Query1>()
                .Name.ShouldEqual("Jeremy Maclin");

            readQuery.queries[1].type.ShouldEqual("resource-2");
            readQuery.queries[2].type.ShouldEqual("input-2");
            readQuery.queries[3].query.ShouldBeNull();
        }
        public void run_aggregated_query_through_http_endpoint()
        {
            var query = new AggregatedQuery();
            query.AddQuery(new AggregationEndpoint.Query1 { Name = "Jeremy Maclin" });
            query.Resource<AggregationEndpoint.Resource2>();
            query.AddQuery(new AggregationEndpoint.Input2());
            query.Resource<AggregationEndpoint.Resource4>();

            TestHost.Scenario(_ =>
            {
                _.JsonData(query);

                _.StatusCodeShouldBeOk();
                _.ContentTypeShouldBe("application/json");

                var json = _.Response.Body.ReadAsText();

                var response =
                    new JsonSerializer().Deserialize<AggregationResponse>(new JsonTextReader(new StringReader(json)));

                response.responses.Count().ShouldEqual(4);
                response.responses.Select(x => x.type)
                    .ShouldHaveTheSameElementsAs("resource-1", "resource-2", "resource-3", "resource-4");
            });
        }
        public void aggregate_request_through_the_initial_endpoint()
        {
            var container = TestHost.Service<IContainer>();

            using (var nested = container.GetNestedContainer())
            {
                var aggregator = nested.GetInstance<Aggregator>();

                var query = new AggregatedQuery();
                query.AddQuery(new AggregationEndpoint.Query1 { Name = "Jeremy Maclin" });
                query.Resource<AggregationEndpoint.Resource2>();
                query.AddQuery(new AggregationEndpoint.Input2());
                query.Resource<AggregationEndpoint.Resource4>();

                var aggregatedResponse = aggregator.QueryAggregate(query);

                aggregatedResponse.responses[0].result.ShouldBeOfType<AggregationEndpoint.Resource1>()
                    .Name.ShouldEqual("Jeremy Maclin");

                aggregatedResponse.responses[1].result.ShouldBeOfType<AggregationEndpoint.Resource2>();
                aggregatedResponse.responses[2].result.ShouldBeOfType<AggregationEndpoint.Resource3>();
                aggregatedResponse.responses[3].result.ShouldBeOfType<AggregationEndpoint.Resource4>();
            }
        }