Esempio n. 1
0
        public async Task ShouldReturnOkWithValidRequest()
        {
            var body = new SendSessionSmsRequest
            {
                Domain       = "discover-skills-and-careers.co.uk",
                MobileNumber = "0123456789",
                SessionId    = "201904-282gk265gzmzyz",
                TemplateId   = "3B840739-F4C5-40AA-93E9-6827A6F29003"
            };

            _userSessionRepository.GetUserSession("201904-282gk265gzmzyz").Returns(Task.FromResult(new UserSession
            {
                UserSessionId = "201904-282gk265gzmzyz"
            }));

            _notifyClient.SendSms(body.Domain, body.MobileNumber, body.TemplateId, body.SessionId).Returns(Task.CompletedTask);

            var result = await RunFunction(body);

            Assert.IsType <HttpResponseMessage>(result);
            var content = await result.Content.ReadAsAsync <SendSessionSmsResponse>();

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            Assert.True(content.IsSuccess);
        }
Esempio n. 2
0
        public async Task ShouldReturn_NoContentForMissingUserSession()
        {
            var body = new SendSessionSmsRequest
            {
                Domain       = "discover-skills-and-careers.co.uk",
                MobileNumber = "0123456789",
                SessionId    = "201904-282gk265gzmzyz",
                TemplateId   = "3B840739-F4C5-40AA-93E9-6827A6F29003"
            };

            _userSessionRepository.GetUserSession("201904-282gk265gzmzyz").Returns(Task.FromResult <UserSession>(null));

            var result = await RunFunction(body);

            Assert.IsType <HttpResponseMessage>(result);
            Assert.Equal(HttpStatusCode.NoContent, result.StatusCode);
        }
Esempio n. 3
0
        private async Task <HttpResponseMessage> RunFunction(SendSessionSmsRequest body)
        {
            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Body = new MemoryStream()
            };

            if (body != null)
            {
                var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(body));
                request.Body.Write(bytes, 0, bytes.Length);
                request.Body.Seek(0, SeekOrigin.Begin);
            }

            return(await SendSessionSmsHttpTrigger.Run(
                       request,
                       _log,
                       _httpRequestHelper,
                       _httpResponseMessageHelper,
                       _userSessionRepository,
                       _notifyClient
                       ).ConfigureAwait(false));
        }
Esempio n. 4
0
        public async Task ShouldReturn_OkOnExceptionWithErrorInBody()
        {
            var body = new SendSessionSmsRequest
            {
                Domain       = "discover-skills-and-careers.co.uk",
                MobileNumber = "0123456789",
                SessionId    = "201904-282gk265gzmzyz",
                TemplateId   = "3B840739-F4C5-40AA-93E9-6827A6F29003"
            };

            _userSessionRepository.GetUserSession("201904-282gk265gzmzyz").Throws(new Exception("Error"));

            var result = await RunFunction(body);

            var response = Assert.IsType <HttpResponseMessage>(result);

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);

            var responseContent = await response.Content.ReadAsAsync <SendSessionSmsResponse>();

            Assert.Equal("Error", responseContent.Message);
            Assert.False(responseContent.IsSuccess);
        }