public async Task LmiWebhookHttpTriggerPostForSubscriptionValidationReturnsExpectedResultCode(WebhookCommand webhookCommand)
        {
            // Arrange
            var expectedResult      = HttpStatusCode.Accepted;
            var function            = new LmiWebhookHttpTrigger(fakeLogger, draftEnvironmentValues, fakeLmiWebhookReceiverService);
            var request             = BuildRequestWithValidBody("a request body");
            var webhookRequestModel = new WebhookRequestModel
            {
                WebhookCommand = webhookCommand,
            };

            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).Returns(webhookRequestModel);
            A.CallTo(() => fakeDurableOrchestrationClient.StartNewAsync(A <string> .Ignored, A <SocRequestModel> .Ignored)).Returns("An instance id");
            A.CallTo(() => fakeDurableOrchestrationClient.CreateCheckStatusResponse(A <HttpRequest> .Ignored, A <string> .Ignored, A <bool> .Ignored)).Returns(new AcceptedResult());

            // Act
            var result = await function.Run(request, fakeDurableOrchestrationClient).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDurableOrchestrationClient.StartNewAsync(A <string> .Ignored, A <SocRequestModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDurableOrchestrationClient.CreateCheckStatusResponse(A <HttpRequest> .Ignored, A <string> .Ignored, A <bool> .Ignored)).MustHaveHappenedOnceExactly();
            var statusResult = Assert.IsType <AcceptedResult>(result);

            Assert.Equal((int)expectedResult, statusResult.StatusCode);
        }
        public async Task LmiWebhookHttpTriggerPostForSubscriptionValidationReturnsExpectedResultCode(WebhookCommand webhookCommand, int forAllCount, int forSocCount)
        {
            // Arrange
            var expectedResult      = HttpStatusCode.Created;
            var function            = new LmiWebhookHttpTrigger(fakeLogger, draftEnvironmentValues, fakeLmiWebhookReceiverService);
            var request             = BuildRequestWithValidBody("a request body");
            var webhookRequestModel = new WebhookRequestModel
            {
                WebhookCommand = webhookCommand,
                ContentId      = Guid.NewGuid(),
            };

            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).Returns(webhookRequestModel);
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportAll()).Returns(HttpStatusCode.Created);
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportSoc(A <Guid> .Ignored)).Returns(HttpStatusCode.Created);

            // Act
            var result = await function.Run(request).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportAll()).MustHaveHappened(forAllCount, Times.Exactly);
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportSoc(A <Guid> .Ignored)).MustHaveHappened(forSocCount, Times.Exactly);
            var statusResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)expectedResult, statusResult.StatusCode);
        }
        public async Task LmiWebhookHttpTriggerPostWithNoBodyReturnsBadRequest()
        {
            // Arrange
            var expectedResult = new StatusCodeResult((int)HttpStatusCode.BadRequest);
            var function       = new LmiWebhookHttpTrigger(fakeLogger, draftEnvironmentValues, fakeLmiWebhookReceiverService);
            var request        = BuildRequestWithValidBody(string.Empty);

            // Act
            var result = await function.Run(request, fakeDurableOrchestrationClient).ConfigureAwait(false);

            // Assert
            var statusResult = Assert.IsType <BadRequestResult>(result);

            Assert.Equal(expectedResult.StatusCode, statusResult.StatusCode);
        }
        public async Task LmiWebhookHttpTriggerPostCatchesException()
        {
            // Arrange
            var expectedResult = new StatusCodeResult((int)HttpStatusCode.InternalServerError);
            var function       = new LmiWebhookHttpTrigger(fakeLogger, draftEnvironmentValues, fakeLmiWebhookReceiverService);
            var request        = BuildRequestWithValidBody("a request body");

            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).Throws(new Exception());

            // Act
            var result = await function.Run(request, fakeDurableOrchestrationClient).ConfigureAwait(false);

            // Assert
            var statusResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal(expectedResult.StatusCode, statusResult.StatusCode);
        }
        public async Task LmiWebhookHttpTriggerPostWithNoBodyReturnsBadRequest()
        {
            // Arrange
            var expectedResult = new StatusCodeResult((int)HttpStatusCode.BadRequest);
            var function       = new LmiWebhookHttpTrigger(fakeLogger, draftEnvironmentValues, fakeLmiWebhookReceiverService);
            var request        = BuildRequestWithValidBody(string.Empty);

            // Act
            var result = await function.Run(request).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportAll()).MustNotHaveHappened();
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportSoc(A <Guid> .Ignored)).MustNotHaveHappened();
            var statusResult = Assert.IsType <BadRequestResult>(result);

            Assert.Equal(expectedResult.StatusCode, statusResult.StatusCode);
        }
Exemple #6
0
        public async Task LmiWebhookHttpTriggerPostCatchesException()
        {
            // Arrange
            var expectedResult = new StatusCodeResult((int)HttpStatusCode.InternalServerError);
            var function       = new LmiWebhookHttpTrigger(fakeLogger, fakeLmiWebhookReceiverService);
            var request        = BuildRequestWithValidBody("a request body");

            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).Throws(new Exception());

            // Act
            var result = await function.Run(request).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportAll()).MustNotHaveHappened();
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportSoc(A <Guid> .Ignored)).MustNotHaveHappened();
            var statusResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal(expectedResult.StatusCode, statusResult.StatusCode);
        }
        public async Task LmiWebhookHttpTriggerPostForSubscriptionValidationReturnsBadRequestForPublishedEnvironment(WebhookCommand webhookCommand)
        {
            // Arrange
            var expectedResult      = HttpStatusCode.BadRequest;
            var function            = new LmiWebhookHttpTrigger(fakeLogger, publishedEnvironmentValues, fakeLmiWebhookReceiverService);
            var request             = BuildRequestWithValidBody("a request body");
            var webhookRequestModel = new WebhookRequestModel
            {
                WebhookCommand = webhookCommand,
            };

            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).Returns(webhookRequestModel);

            // Act
            var result = await function.Run(request).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportAll()).MustNotHaveHappened();
            A.CallTo(() => fakeLmiWebhookReceiverService.ReportSoc(A <Guid> .Ignored)).MustNotHaveHappened();
            var statusResult = Assert.IsType <BadRequestResult>(result);

            Assert.Equal((int)expectedResult, statusResult.StatusCode);
        }
        public async Task LmiWebhookHttpTriggerPostForSubscriptionValidationReturnsOk()
        {
            // Arrange
            var expectedResult      = new StatusCodeResult((int)HttpStatusCode.OK);
            var function            = new LmiWebhookHttpTrigger(fakeLogger, fakeLmiWebhookReceiverService);
            var request             = BuildRequestWithValidBody("a request body");
            var webhookRequestModel = new WebhookRequestModel
            {
                WebhookCommand = WebhookCommand.SubscriptionValidation,
            };

            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).Returns(webhookRequestModel);

            // Act
            var result = await function.Run(request, fakeDurableOrchestrationClient).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLmiWebhookReceiverService.ExtractEvent(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDurableOrchestrationClient.StartNewAsync(A <string> .Ignored, A <SocRequestModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeDurableOrchestrationClient.CreateCheckStatusResponse(A <HttpRequest> .Ignored, A <string> .Ignored, A <bool> .Ignored)).MustNotHaveHappened();
            var statusResult = Assert.IsType <OkObjectResult>(result);

            Assert.Equal(expectedResult.StatusCode, statusResult.StatusCode);
        }