예제 #1
0
        public void ValidateCreditCard_BadRequestWithEmpty_expirydate_ShouldReturn400()
        {
            //Arrange
            var expectedModelResponse = new ValidateCreditCardResponse
            {
                CreditCardNumber = "371449635398431",
                StatusCode       = 400,
                IsExist          = "Does not exist",
                IsValid          = "Invalid",
                StatusMessage    = "Invalid Null Request: expirydate"
            };

            controller.Request.RequestUri = new Uri(@"http://localhost:60855/api/Validation");

            //Act
            var actualResult = controller.ValidateCreditCard("371449635398431", "");
            var objContent   = actualResult.Content as ObjectContent;

            Assert.NotNull(objContent);
            var actualResponse = objContent.Value as ValidateCreditCardResponse;

            Assert.NotNull(actualResponse);

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, actualResult.StatusCode);
            Assert.AreEqual(expectedModelResponse.StatusCode, actualResponse.StatusCode);
            Assert.AreEqual(expectedModelResponse.CreditCardNumber, actualResponse.CreditCardNumber);
            Assert.AreEqual(expectedModelResponse.IsExist, actualResponse.IsExist);
            Assert.AreEqual(expectedModelResponse.IsValid, actualResponse.IsValid);
            Assert.AreEqual(expectedModelResponse.StatusMessage, actualResponse.StatusMessage);
        }
예제 #2
0
        public void ValidateCreditCard_MASTERCARD_CardNumStartwith5_NotPrimeYear_ShouldReturnStatus200_Valid()
        {
            //Arrange
            var expectedModelResponse = new ValidateCreditCardResponse
            {
                CreditCardNumber = "5105105105105100",
                StatusCode       = 200,
                IsValid          = "Invalid",
                CardType         = "MASTERCARD"
            };

            controller.Request.RequestUri = new Uri(@"http://localhost:60855/api/Validation");

            //Act
            var actualResult = controller.ValidateCreditCard("5105105105105100", "112018");
            var objContent   = actualResult.Content as ObjectContent;

            Assert.NotNull(objContent);
            var actualResponse = objContent.Value as ValidateCreditCardResponse;

            Assert.NotNull(actualResponse);

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, actualResult.StatusCode);
            Assert.AreEqual(expectedModelResponse.StatusCode, actualResponse.StatusCode);
            Assert.AreEqual(expectedModelResponse.CreditCardNumber, actualResponse.CreditCardNumber);
            Assert.AreEqual(expectedModelResponse.IsValid, actualResponse.IsValid);
            Assert.AreEqual(expectedModelResponse.CardType, actualResponse.CardType);
        }
예제 #3
0
        public void ValidateCreditCard_JCB_CardNumStartwith3590_ShouldReturnStatus400_Invalid()
        {
            //Arrange
            var expectedModelResponse = new ValidateCreditCardResponse
            {
                CreditCardNumber = "3590111333300000",
                StatusCode       = 400,
                IsValid          = "Invalid",
            };

            controller.Request.RequestUri = new Uri(@"http://localhost:60855/api/Validation");

            //Act
            var actualResult = controller.ValidateCreditCard("3590111333300000", "112018");
            var objContent   = actualResult.Content as ObjectContent;

            Assert.NotNull(objContent);
            var actualResponse = objContent.Value as ValidateCreditCardResponse;

            Assert.NotNull(actualResponse);

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, actualResult.StatusCode);
            Assert.AreEqual(expectedModelResponse.StatusCode, actualResponse.StatusCode);
            Assert.AreEqual(expectedModelResponse.CreditCardNumber, actualResponse.CreditCardNumber);
            Assert.AreEqual(expectedModelResponse.IsValid, actualResponse.IsValid);
        }
예제 #4
0
        public void ValidateCreditCard_ValidReques_ShouldReturnValidCardandStatus200()
        {
            //Arrange
            var expectedModelResponse = new ValidateCreditCardResponse
            {
                CreditCardNumber = "371449635398431",
                StatusCode       = 200,
                IsExist          = "exist",
                IsValid          = "Invalid",
            };

            controller.Request.RequestUri = new Uri(@"http://localhost:60855/api/Validation");

            //Act
            var actualResult = controller.ValidateCreditCard("371449635398431", "112018");
            var objContent   = actualResult.Content as ObjectContent;

            Assert.NotNull(objContent);
            var actualResponse = objContent.Value as ValidateCreditCardResponse;

            Assert.NotNull(actualResponse);

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, actualResult.StatusCode);
            Assert.AreEqual(expectedModelResponse.StatusCode, actualResponse.StatusCode);
            Assert.AreEqual(expectedModelResponse.CreditCardNumber, actualResponse.CreditCardNumber);
            Assert.AreEqual(expectedModelResponse.IsExist, actualResponse.IsExist);
            Assert.AreEqual(expectedModelResponse.IsValid, actualResponse.IsValid);
        }
예제 #5
0
        public void ValidateCreditCard_UNKNOWN_BadRequestCardNumStartWith6_ShouldReturnStatus400_TypeUnknow_Invalid()
        {
            //Arrange
            var expectedModelResponse = new ValidateCreditCardResponse
            {
                CreditCardNumber = "671449635398422",
                StatusCode       = 400,
                IsValid          = "Invalid",
                CardType         = "UNKNOWN"
            };

            controller.Request.RequestUri = new Uri(@"http://localhost:60855/api/Validation");

            //Act
            var actualResult = controller.ValidateCreditCard("671449635398422", "112018");
            var objContent   = actualResult.Content as ObjectContent;

            Assert.NotNull(objContent);
            var actualResponse = objContent.Value as ValidateCreditCardResponse;

            Assert.NotNull(actualResponse);

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, actualResult.StatusCode);
            Assert.AreEqual(expectedModelResponse.StatusCode, actualResponse.StatusCode);
            Assert.AreEqual(expectedModelResponse.CreditCardNumber, actualResponse.CreditCardNumber);
            Assert.AreEqual(expectedModelResponse.IsValid, actualResponse.IsValid);
            Assert.AreEqual(expectedModelResponse.CardType, actualResponse.CardType);
        }
예제 #6
0
        public void ValidateCreditCard_BadRequestWithLongCharactor_expirydate_ShouldReturn400()
        {
            //Arrange
            var expectedModelResponse = new ValidateCreditCardResponse
            {
                StatusCode    = 400,
                StatusMessage = "Invalid - expirydate out of length."
            };

            controller.Request.RequestUri = new Uri(@"http://localhost:60855/api/Validation");

            //Act
            var actualResult = controller.ValidateCreditCard("3530111333300000", "1211211");
            var objContent   = actualResult.Content as ObjectContent;

            Assert.NotNull(objContent);
            var actualResponse = objContent.Value as ValidateCreditCardResponse;

            Assert.NotNull(actualResponse);

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, actualResult.StatusCode);
            Assert.AreEqual(expectedModelResponse.StatusCode, actualResponse.StatusCode);
            Assert.AreEqual(expectedModelResponse.StatusMessage, actualResponse.StatusMessage);
        }
예제 #7
0
        public HttpResponseMessage ValidateCreditCard(string creditcardnumber, string expirydate)
        {
            MethodBase currentMethod = MethodBase.GetCurrentMethod();

            CreditCardLogManager.Entering(string.Format("Card Number : {0}, Expiry Date : {1}", creditcardnumber, expirydate), currentClass, currentMethod);

            var errorMsg = RequestValidation.BadRequestValidationCardNumber(creditcardnumber, expirydate);

            if (!string.IsNullOrEmpty(errorMsg))
            {
                return(BuildResponse(creditcardnumber, HttpStatusCode.BadRequest, (int)HttpStatusCode.BadRequest, errorMsg));
            }

            try
            {
                var response = new ValidateCreditCardResponse();

                using (var context = new CreditcardDBEntities())
                {
                    var result = context.ValidateCreditCard(creditcardnumber, expirydate).ToList();
                    if (result.Count > 0)
                    {
                        foreach (var item in result)
                        {
                            response.CreditCardNumber = item.CARDNUMBER;
                            response.StatusCode       = (int)HttpStatusCode.OK;
                            response.StatusMessage    = HttpStatusCode.OK.ToString();
                            response.IsExist          = item.ISEXIST;
                            response.IsValid          = item.ISVALID;
                            response.CardType         = item.CARDTYPE;
                        }
                        ;
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (Exception ex)
            {
                return(BuildResponse(creditcardnumber, HttpStatusCode.InternalServerError, (int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }