public void ProcessNumber_NegativeNumber_ReturnException()
        {
            var numberDetail = new NumberDetail
            {
                Name   = "Behnam Karimi",
                Number = -100.12m
            };

            var bc = new ConverterComponent();

            var exception = Assert.Throws <ArgumentException>(() => bc.ProccesNumber(numberDetail));

            Assert.AreEqual("The number should be positive.", exception.Message);
        }
Esempio n. 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));
            }
        }
        public void ProccesNumberTest(decimal number, string expected)
        {
            var numberDetail = new NumberDetail
            {
                Name   = "Behnam Karimi",
                Number = number
            };

            var bc     = new ConverterComponent();
            var result = bc.ProccesNumber(numberDetail);

            TestContext.Out.WriteLine(numberDetail.ToString());

            Assert.AreNotEqual(numberDetail.Id, Guid.Empty);
            Assert.AreEqual(numberDetail.DateCreated.Date, DateTime.UtcNow.Date);
            Assert.IsFalse(string.IsNullOrWhiteSpace(numberDetail.ConvertedNumber));
            Assert.IsFalse(string.IsNullOrWhiteSpace(numberDetail.Name));
            Assert.AreEqual(expected, numberDetail.ConvertedNumber);
        }