Ejemplo n.º 1
0
        public async Task ProcessAsync_SessionCloseHeader_FinishTransport()
        {
            // Arrange
            var session = new Session()
            {
                Id    = EnvelopeId.NewId(),
                State = SessionState.Established
            };

            EmulatedTransport
            .Setup(e => e.GetSessionAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(session);

            Processor1HttpRequest.Headers.Add(Constants.SESSION_HEADER, Constants.CLOSE_HEADER_VALUE);

            var processorResponse = new HttpResponse(Processor1HttpRequest.CorrelatorId, HttpStatusCode.OK);

            Processor1
            .Setup(p => p.ProcessAsync(Processor1HttpRequest, It.IsAny <UriTemplateMatch>(), It.IsAny <ITransportSession>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(processorResponse)
            .Verifiable();

            // Act
            await Target.StartAsync();

            HttpServerRequestBuffer.Post(Processor1HttpRequest);

            // Assert
            var actualResponse = await HttpServerResponse;

            Processor1.Verify();
            actualResponse.ShouldBe(processorResponse);
            EmulatedTransport.Verify(t => t.FinishAsync(It.IsAny <CancellationToken>()), Times.Once());
            HttpTransportProvider.Verify(h => h.GetTransport(Principal.Object, false), Times.Once());
        }
Ejemplo n.º 2
0
        public async Task ProcessAsync_ProcessorRaisesException_ReturnsInternalServerError()
        {
            // Arrange
            var session = new Session()
            {
                Id    = EnvelopeId.NewId(),
                State = SessionState.Established
            };

            EmulatedTransport
            .Setup(e => e.GetSessionAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(session);

            var exceptionMessage = Dummy.CreateRandomString(100);

            Processor1
            .Setup(p => p.ProcessAsync(Processor1HttpRequest, It.IsAny <UriTemplateMatch>(), It.IsAny <ITransportSession>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception(exceptionMessage))
            .Verifiable();


            // Act
            await Target.StartAsync();

            HttpServerRequestBuffer.Post(Processor1HttpRequest);

            // Assert
            var actualResponse = await HttpServerResponse;

            actualResponse.StatusCode.ShouldBe(HttpStatusCode.InternalServerError);
            actualResponse.BodyStream.ShouldNotBe(null);

            var reader = new StreamReader(actualResponse.BodyStream);
            var body   = reader.ReadToEnd();

            body.ShouldContain(exceptionMessage);

            Processor1.Verify();
        }
Ejemplo n.º 3
0
        public async Task ProcessAsync_ValidUrlAuthenticatedUser_CallProcessorAndKeepSession()
        {
            // Arrange
            var session = new Session()
            {
                Id    = EnvelopeId.NewId().ToString(),
                State = SessionState.Established
            };

            EmulatedTransport
            .Setup(e => e.GetSessionAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(session);

            var processorResponse = new HttpResponse(Processor1HttpRequest.CorrelatorId, HttpStatusCode.OK);

            Processor1
            .Setup(p => p.ProcessAsync(Processor1HttpRequest, It.IsAny <UriTemplateMatch>(), It.IsAny <ITransportSession>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(processorResponse)
            .Verifiable();

            // Act
            await Target.StartAsync();

            HttpServerRequestBuffer.Post(Processor1HttpRequest);

            // Assert
            var actualResponse = await HttpServerResponse;

            Processor1.Verify();
            actualResponse.ShouldBe(processorResponse);
            EmulatedTransport.Verify(t => t.FinishAsync(It.IsAny <CancellationToken>()), Times.Never());
            actualResponse.Headers.Get(Constants.SESSION_EXPIRATION_HEADER).ShouldNotBe(null);
            var actualSessionExpiration = DateTimeOffset.Parse(actualResponse.Headers.Get(Constants.SESSION_EXPIRATION_HEADER));

            actualSessionExpiration.ShouldBe(SessionExpiration);
            HttpTransportProvider.Verify(h => h.GetTransport(Principal.Object, true), Times.Once());
        }