Пример #1
0
        public void ConvertService_NaegativeNumber_ExceptionShouldReturn()
        {
            var numberDetail = new NumberDetailRequest
            {
                Name   = "Behnam karimi",
                Number = -3324.39m
            };

            var result = _converterController.Convert(numberDetail) as HttpResponseMessage;

            var exception = Assert.Throws <HttpRequestException>(() => result.EnsureSuccessStatusCode());
        }
Пример #2
0
        public HttpResponseMessage Convert(NumberDetailRequest request)
        {
            try
            {
                // maps the reqeust data contract to entity to be passed to business layer
                NumberDetail numberDetail = Mapper.Map <NumberDetailRequest, NumberDetail>(request);

                ConverterComponent converter = new ConverterComponent();

                NumberDetail result = converter.ProccesNumber(numberDetail);

                // creates a response with 200 status code and passes the result.
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #3
0
        public void ConvertServiceTest()
        {
            var numberDetail = new NumberDetailRequest
            {
                Name   = "Behnam karimi",
                Number = 3324.39m
            };

            var result = _converterController.Convert(numberDetail) as HttpResponseMessage;

            result.EnsureSuccessStatusCode();

            var resultContent = result.Content.ReadAsAsync <NumberDetail>().GetAwaiter().GetResult();

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            Assert.IsNotNull(resultContent);
            Assert.AreEqual(numberDetail.Name, resultContent.Name);
            Assert.AreEqual(numberDetail.Number, resultContent.Number);
            Assert.AreEqual("three thousand and three hundred and twenty-four dollars and thirty-nine cents", resultContent.ConvertedNumber);
            Assert.AreEqual(DateTime.UtcNow.Date, resultContent.DateCreated.Date);
            Assert.AreNotEqual(Guid.Empty, resultContent.Id);
        }