Beispiel #1
0
 /// <summary>
 /// Sends content back to the caller.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="content"></param>
 /// <param name="mimeType"></param>
 private static void SendContent(PipelineResponse response, byte[] content, string mimeType)
 {
     response.ContentType   = mimeType;
     response.StatusCode    = (int)HttpStatusCode.OK;
     response.ContentLength = content.Length;
     response.Body.Write(content, 0, content.Length);
 }
Beispiel #2
0
        public Task <PipelineResponse <CreateModelRetriever.Response> > Retrieve(ModelRequest input)
        {
            // var response = PipelineResponse<CreateModelPipeline.Response, string>.Fail("error-response");
            var response = PipelineResponse.Ok <CreateModelRetriever.Response>(new CreateModelRetriever.Response("new-model-id"));

            return(Task.FromResult(response));
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        public MockOwinEnvironment()
        {
            Request  = new PipelineRequest(Environment);
            Response = new PipelineResponse(Environment);

            AddRequiredFields();
        }
Beispiel #4
0
        public void PipelineResponse_Constructor_Initialises_To_Known_State()
        {
            Assert.AreSame(_Environment, _Response.Environment);

            var defaultCtor = new PipelineResponse();

            Assert.IsNotNull(defaultCtor.Environment);
        }
Beispiel #5
0
            public Task <PipelineResponse <ModelResponse> > Retrieve(ModelRequest input)
            {
                _times++;

                return(Task.FromResult(PipelineResponse.Ok(new ModelResponse {
                    Name = _times.ToString()
                })));
            }
            public Task <PipelineResponse <ModelResponse> > Retrieve(BodyRequest input)
            {
                var response = new ModelResponse
                {
                    Name = $"Id = {input.Id}, Body = {input.Body}",
                };

                return(Task.FromResult(PipelineResponse.Ok(response)));
            }
Beispiel #7
0
 public async Task <PipelineResponse <TOut> > Run(Func <Task <PipelineResponse <TOut> > > func)
 {
     try
     {
         return(await func());
     }
     catch (System.Exception ex)
     {
         return(PipelineResponse.Fail <TOut>(ex, "Unhandled exception"));
     }
 }
Beispiel #8
0
 public PipelineEventArgs(Job job, PipelineEvents events, List <string> moduleCollection, HttpClient httpClient, IModel rabbitChannel)
 {
     Job              = job;
     Events           = events;
     ModuleCollection = moduleCollection;
     HttpClient       = httpClient;
     RabbitChannel    = rabbitChannel;
     Response         = string.Empty;
     PipelineResponse = PipelineResponse.Ignore;
     Transition       = Transition.New;
 }
Beispiel #9
0
 public static async Task ParseResponse(HttpContext context, PipelineResponse <ModelResponse> response)
 {
     if (response.Success)
     {
         context.Response.StatusCode = (int)HttpStatusCode.OK;
         await context.Response.WriteAsync(response.Result.Name);
     }
     else
     {
         context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
     }
 }
Beispiel #10
0
            public async Task <PipelineResponse <ModelResponse> > Retrieve(ModelRequest input)
            {
                try
                {
                    var response = await _dbThing.GetModel(input);

                    return(PipelineResponse.Ok <ModelResponse>(response));
                }
                catch (Exception ex)
                {
                    return(PipelineResponse.Fail <ModelResponse>(ex, "Unhandled exception"));
                }
            }
Beispiel #11
0
 public static async Task ParseResponse(HttpContext context, PipelineResponse <ModelResponse> response)
 {
     if (response.Success)
     {
         context.Response.StatusCode = (int)HttpStatusCode.OK;
         await context.Response.WriteAsync(response.Result.Name);
     }
     else
     {
         context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
         await context.Response.WriteAsync(response.Error.ErrorMessage);
     }
 }
Beispiel #12
0
        public static Task ParseCreateModelResponse(HttpContext context, PipelineResponse <CreateModelRetriever.Response> response)
        {
            if (response.Success)
            {
                context.Response.StatusCode = (int)HttpStatusCode.OK;
                context.Response.WriteAsync(response.Result.Id);
            }
            else
            {
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                context.Response.WriteAsync(response.Error.ErrorMessage);
            }

            return(Task.CompletedTask);
        }
Beispiel #13
0
        public async Task Pipeline()
        {
            //Arrange
            var sut            = GetSut();
            var expectedResult = new PipelineResponse {
                Result = " Pipeline behaviour start PipelinePreProcessor AnotherPipelinePreProcessor HANDLER PipelinePostProcessor AnotherPipelinePostProcessor Pipeline behaviour end", Success = true
            };

            //Act
            var result = await sut.Send(new PipelineRequest { Name = "" });

            //Assert
            Assert.That(result.Success, Is.EqualTo(expectedResult.Success));
            Assert.That(result.Result, Is.EqualTo(expectedResult.Result));
        }
Beispiel #14
0
 public static async Task SetGetUserResponse(HttpContext context, PipelineResponse <GetUserResponse> response)
 {
     if (response.Success)
     {
         await context.Response.WriteAsJsonAsync(response.Result);
     }
     else
     {
         if (response.Error.ErrorMessage == GetUserInteractor.ErrorsNoUser)
         {
             context.Response.StatusCode = (int)HttpStatusCode.NotFound;
             await context.Response.WriteAsync(response.Error.ErrorMessage);
         }
         else
         {
             context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
             await context.Response.WriteAsync(response.Error.ErrorMessage);
         }
     }
 }
Beispiel #15
0
        /// <summary>
        /// Executes pipeline handler collection one-by-one.
        /// </summary>
        /// <param name="turnContext"></param>
        /// <param name="requestState"></param>
        /// <returns></returns>
        public async Task <PipelineResponse> Execute(ITurnContext turnContext, RequestState requestState)
        {
            var res = new PipelineResponse();

            foreach (var handler in Pipeline)
            {
                try
                {
                    res.Result = await handler.Execute(turnContext, requestState);
                }
                catch (Exception e)
                {
                    logger.Error(e);
                    res.Result = ResponseType.Error;
                }
                res.Count++;
                if (res.Result != ResponseType.Continue)
                {
                    break;
                }
            }
            return(res);
        }
Beispiel #16
0
 internal static Task SetFromModelResponse(HttpContext arg1, PipelineResponse <ModelResponse> arg2)
 {
     throw new NotImplementedException();
 }
            public async Task <PipelineResponse <List <ModelResponse> > > Retrieve()
            {
                var result = await _dbThing.GetAll();

                return(PipelineResponse.Ok(result));
            }
            public async Task <PipelineResponse <ModelResponse> > Retrieve(ModelRequest input)
            {
                var result = await _dbThing.GetModel(input);

                return(PipelineResponse.Ok(result));
            }
Beispiel #19
0
 /// <summary>
 /// Creates a new object.
 /// </summary>
 /// <param name="pipelineResponse"></param>
 public Response(PipelineResponse pipelineResponse)
 {
     _Response = pipelineResponse;
 }
Beispiel #20
0
        public async Task <PipelineResponse <TOut> > Retrieve(TIn input)
        {
            var result = await _retriever(input);

            return(PipelineResponse.Ok(result));
        }
Beispiel #21
0
        public async Task <PipelineResponse <CreateUserResponse> > Retrieve(CreateUserRequest request)
        {
            var id = await _database.Create(request.Name);

            return(PipelineResponse.Ok(new CreateUserResponse(id)));
        }
Beispiel #22
0
 public void TestInitialise()
 {
     _Environment = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
     _Response    = new PipelineResponse(_Environment);
     _Environment["owin.ResponseHeaders"] = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase);
 }