예제 #1
0
        public async void PostTest()
        {
            var authContract = new AuthContract {
                Login = "******", Password = "******"
            };
            var authHashContract = new AuthHashContract {
                HashValue = "hashhashhashhash"
            };

            var mockFactory = new Mock <IHttpClientFactory>();
            var handlerMock = new Mock <HttpMessageHandler>();
            var response    = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(authHashContract), Encoding.UTF8, "application/json"),
            };

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(response);


            var httpClient = new HttpClient(handlerMock.Object);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(httpClient);


            AppSettings app = new AppSettings()
            {
                ApiUrls = new ApiUrls()
                {
                    MD5Function = "http://test"
                }
            };
            var mockOptions = new Mock <IOptions <AppSettings> >();

            mockOptions.Setup(ap => ap.Value).Returns(app);

            var hashController = new HashController(mockFactory.Object, mockOptions.Object);

            var result = await hashController.PostAsync(authContract);

            var actual   = JsonConvert.SerializeObject(((OkObjectResult)result).Value);
            var expected = JsonConvert.SerializeObject(authHashContract);


            Assert.Equal(expected, actual);
        }
예제 #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req)
        {
            string authContractJson = await new StreamReader(req.Body).ReadToEndAsync();

            var hash = GetMD5Hash(authContractJson);

            AuthHashContract authHashContract = new AuthHashContract {
                HashValue = hash
            };

            return(new OkObjectResult(authHashContract));
        }