public async Task Run_GoodRequest_ReturnsUniqueId()
        {
            //arrange
            var document = new Document()
            {
                Body = "Some Text"
            };
            var documentAsJson  = JsonConvert.SerializeObject(document);
            var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString(documentAsJson);

            _mockHttpClient.Setup(c => c.PostAsyncSuccessful(It.IsAny <Document>(), It.IsAny <string>(), It.IsAny <ILogger>())).Returns(Task.FromResult(true)).Verifiable();

            //act
            var actionResult = _function1.Run(mockHttpRequest.Object, out _cosmosDocument, _mockLogger);

            //assert
            _mockHttpClient.Verify();
            Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult));
            Assert.IsInstanceOfType(_cosmosDocument, typeof(IntermediaryServiceDocument));
            var returnValue = ((OkObjectResult)actionResult).Value;

            Guid guidOutput;

            Assert.IsTrue(Guid.TryParse((string)returnValue, out guidOutput));
        }
示例#2
0
        public async Task Run_CosmosDbReturnsNoDocument_Return404NotFound()
        {
            //arrange
            var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString("COMPLETED");

            //act
            var actionResult = await Function3.Run(mockHttpRequest.Object, null, _mockLogger);

            //assert
            Assert.IsTrue(_mockLogger.GetLogs().Where(m => m.Contains(UserFriendlyMessages.DocumentNotFound)).Count() == 1);
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundObjectResult));
            StringAssert.Contains(((NotFoundObjectResult)actionResult).Value.ToString(), UserFriendlyMessages.DocumentNotFound);
        }
示例#3
0
        public async Task Run_BodyDoesNotContainOneOfTheThree_Return400BadRequest(string body)
        {
            //arrange
            var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString(body);

            //act
            var actionResult = await Function3.Run(mockHttpRequest.Object, new IntermediaryServiceDocument(), _mockLogger);

            //assert
            Assert.IsTrue(_mockLogger.GetLogs().Where(m => m.Contains(UserFriendlyMessages.ErrorProcessingBody)).Count() == 1);
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
            StringAssert.Contains(((BadRequestObjectResult)actionResult).Value.ToString(), UserFriendlyMessages.ErrorProcessingBody);
        }
        public async Task Run_NoBodyInRequest_Return400()
        {
            //arrange
            var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString("");

            //act
            var actionResult = _function1.Run(mockHttpRequest.Object, out _cosmosDocument, _mockLogger);

            //assert
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
            StringAssert.Contains(((BadRequestObjectResult)actionResult).Value.ToString(), UserFriendlyMessages.ErrorProcessingBody);
            Assert.IsNull(_cosmosDocument); //Make sure cosmos document won't be saved
        }
        public async Task Run_JsonObjectDeserialized_BodyPropertyNull_Return400(string body)
        {
            //arrange
            var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString(body);

            //act
            var actionResult = _function1.Run(mockHttpRequest.Object, out _cosmosDocument, _mockLogger);

            //assert
            Assert.IsTrue(_mockLogger.GetLogs().Where(m => m.Contains(UserFriendlyMessages.ErrorProcessingBody)).Any());
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
            StringAssert.Contains(((BadRequestObjectResult)actionResult).Value.ToString(), UserFriendlyMessages.ErrorProcessingBody);
            Assert.IsNull(_cosmosDocument); //Make sure cosmos document won't be saved
        }
        public async Task Run_SendsHttpRequestToExampleDotCom_CosmosDocumentPopulated()
        {
            //arrange
            var goodJson        = "{\"body\":\"Some Text\"}";
            var mockHttpRequest = MockHttpRequestGenerator.CreateWithBodyString(goodJson);

            _mockHttpClient.Setup(c => c.PostAsyncSuccessful(It.IsAny <Document>(), It.IsAny <string>(), It.IsAny <ILogger>())).Returns(Task.FromResult(true)).Verifiable();

            //act
            var actionResult = _function1.Run(mockHttpRequest.Object, out _cosmosDocument, _mockLogger);

            //assert
            _mockHttpClient.Verify();
            Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult));
            Assert.IsInstanceOfType(_cosmosDocument, typeof(IntermediaryServiceDocument));
        }
示例#7
0
        public async Task Run_StatusCompleted_CosmosDbDocumentUpdated_Return204Success(string status)
        {
            //arrange
            var thirdPartyStatus = new ThirdPartyStatus()
            {
                Detail = "",
                Status = status
            };
            string json                 = JsonConvert.SerializeObject(thirdPartyStatus);
            var    mockHttpRequest      = MockHttpRequestGenerator.CreateWithBodyString(json);
            var    intermediaryDocument = new IntermediaryServiceDocument();

            //act
            var actionResult = await Function3.Run(mockHttpRequest.Object, intermediaryDocument, _mockLogger);

            //assert
            Assert.IsInstanceOfType(actionResult, typeof(NoContentResult));
            Assert.IsTrue(string.Equals(status, intermediaryDocument.Status.StatusCode));
        }