Ejemplo n.º 1
0
 public CreditCardControllerTests()
 {
     _logger       = new Mock <ILogger <CreditCardController> >();
     _mediatorMock = new Mock <IMediator>();
     _validInput   = CreditCardGenerator.CreateValidCardInputFaker().Generate();
     _controller   = new CreditCardController(_mediatorMock.Object, _logger.Object);
 }
        public async void ShouldGetAll_CreditCard()
        {
            Mock <ISecureXRepository> MoqRepo  = new Mock <ISecureXRepository>();
            List <CreditCard>         TestList = new List <CreditCard>();

            CreditCard cc1 = new CreditCard()
            {
                Id               = 133,
                CreditLimit      = 1000m,
                CurrentDebt      = 1000m,
                CreditCardNumber = 2234923,
                CustomerId       = 33
            };

            CreditCard cc2 = new CreditCard()
            {
                Id               = 153,
                CreditLimit      = 1500m,
                CurrentDebt      = 1200m,
                CreditCardNumber = 1134923,
                CustomerId       = 500
            };

            TestList.Add(cc1);
            TestList.Add(cc2);

            MoqRepo.Setup(x => x.GetCreditCards()).ReturnsAsync(TestList);
            var con    = new CreditCardController(MoqRepo.Object);
            var result = await con.GetAll();

            result.Should().BeEquivalentTo(TestList);
        }
Ejemplo n.º 3
0
        public void GetCreditCardWithCurrentAndNextBills_NoBillExistingBefore()
        {
            // Arrange
            MonthYear monthYear    = MonthYear.Create(2018, 4);
            int       creditCardId = testsUtils.AddSingleCreditCard().Id;

            var sut = new CreditCardController(new CreditCardRepository(dbUtils.DbContext));

            // Act
            var creditCardList = sut.GetList(monthYear);

            // Assert
            Assert.Equal(1, creditCardList.Count);

            CreditCardBill currentBill = creditCardList.First().GetCurrentBill(monthYear);

            Assert.True(currentBill.Id > 0);
            Assert.Equal(TestsUtils.CLOSING_DAY, currentBill.ClosingDay);
            Assert.Equal(creditCardId, currentBill.CreditCard.Id);
            Assert.Equal(0, currentBill.Statements.Count);

            CreditCardBill nextBill = creditCardList.First().GetNextBill(monthYear);

            Assert.True(nextBill.Id > 0);
            Assert.Equal(TestsUtils.CLOSING_DAY, nextBill.ClosingDay);
            Assert.Equal(creditCardId, nextBill.CreditCard.Id);
            Assert.Equal(0, nextBill.Statements.Count);
        }
Ejemplo n.º 4
0
        public void TestMethodGetCard_ShouldReturnCard()
        {
            var controller = new CreditCardController(_creditCardService);
            var result     = controller.Get("44444444444");

            Assert.IsNotNull(result);
        }
Ejemplo n.º 5
0
        public async void Patch_No_Errors()
        {
            CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiCreditCardResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCreditCardRequestModel>()))
            .Callback <int, ApiCreditCardRequestModel>(
                (id, model) => model.CardNumber.Should().Be("A")
                )
            .Returns(Task.FromResult <UpdateResponse <ApiCreditCardResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCreditCardResponseModel>(new ApiCreditCardResponseModel()));
            CreditCardController controller = new CreditCardController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiCreditCardModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiCreditCardRequestModel>();

            patch.Replace(x => x.CardNumber, "A");

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCreditCardRequestModel>()));
        }
Ejemplo n.º 6
0
        public async void BulkInsert_No_Errors()
        {
            CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade();

            var mockResponse = new CreateResponse <ApiCreditCardResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiCreditCardResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCreditCardRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCreditCardResponseModel> >(mockResponse));
            CreditCardController controller = new CreditCardController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var records = new List <ApiCreditCardRequestModel>();

            records.Add(new ApiCreditCardRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var result = (response as OkObjectResult).Value as List <ApiCreditCardResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCreditCardRequestModel>()));
        }
        public void CreditCardController_Get_Null()
        {
            mockedCreditCardRepository.Setup(s => s.GetCreditCard(It.IsAny <string>())).Returns(() => null);
            CreditCardController creditCardController = new CreditCardController(mockedCreditCardRepository.Object);
            var result = creditCardController.Get(string.Empty);

            Assert.IsNull(result.Result);
        }
Ejemplo n.º 8
0
        public void CreditCardController_Get__Null_Cache_Database()
        {
            mockedAuditHandler.Setup(s => s.Post(It.IsAny <Audit.Audit>())).Verifiable();
            CreditCardController creditCardController = new CreditCardController(mockedCreditCardRepository.Object, mockedCacheRepository.Object, mockedAuditHandler.Object);
            var result = creditCardController.Get(string.Empty);

            Assert.IsNull(result.Result);
        }
        public void CreditCardController_Get_CreditCard()
        {
            CreditCard creditCard = new CreditCard();

            mockedCreditCardRepository.Setup(s => s.GetCreditCard(It.IsAny <string>())).Returns(() => Task.FromResult(creditCard));
            CreditCardController creditCardController = new CreditCardController(mockedCreditCardRepository.Object);
            var result = creditCardController.Get(string.Empty);

            Assert.IsNotNull(result.Result);
        }
Ejemplo n.º 10
0
        public void VerifyCreditCard_ReturnJCBCard_ResultTrue(string cardNumber, string expiryDate)
        {
            var controller = new CreditCardController();
            var result     = controller.Validation(new CreditCardInfo {
                CardNumber = cardNumber, ExpiryDate = expiryDate
            });

            Assert.IsTrue(result.Result);
            Assert.AreEqual("JCB", result.CardType);
        }
Ejemplo n.º 11
0
        public void VerifyCreditCard_ReturnUnknown_InvalidCardNumber(string cardNumber, string expiryDate)
        {
            var controller = new CreditCardController();
            var result     = controller.Validation(new CreditCardInfo {
                CardNumber = cardNumber, ExpiryDate = expiryDate
            });

            Assert.IsFalse(result.Result);
            Assert.AreEqual("Unknown", result.CardType);
        }
Ejemplo n.º 12
0
 public void TestInitialize()
 {
     unityContainer          = new UnityContainer();
     premiumPaymentGateway   = MockRepository.GenerateStub <IPremiumPaymentGateway>();
     cheapPaymentGateway     = MockRepository.GenerateStub <ICheapPaymentGateway>();
     expensivePaymentGateway = MockRepository.GenerateStub <IExpensivePaymentGateway>();
     controller               = new CreditCardController(unityContainer, cheapPaymentGateway, expensivePaymentGateway, premiumPaymentGateway);
     controller.Request       = new HttpRequestMessage();
     controller.Configuration = new HttpConfiguration();
 }
Ejemplo n.º 13
0
        public void CheckInvalidCVV()
        {
            var ccControler = new CreditCardController();
            var result      = ccControler.Add(new CreditCardInfo()
            {
                CardNumber = 4256321658974868, CVV = 256789
            });


            Assert.AreEqual(typeof(BadRequestObjectResult), result.GetType());
        }
Ejemplo n.º 14
0
        public void CheckValidCreditCard()
        {
            var ccControler = new CreditCardController();
            var result      = ccControler.Add(new CreditCardInfo()
            {
                CardNumber = 4256321658974868, CVV = 25678
            });


            Assert.AreEqual(typeof(JsonResult), result.GetType());
        }
Ejemplo n.º 15
0
        private void InitializeController()
        {
            var bankAccountRepository = new BankAccountRepository(_options);
            var creditCardRepository  = new CreditCardRepository(_options);
            var providerRepository    = new ProviderRepository(_options);
            var providerFactory       = new ProviderFactory();
            var accountService        = new AccountService(providerFactory, bankAccountRepository, creditCardRepository);

            _controller = new CreditCardController(providerFactory, providerRepository,
                                                   accountService, creditCardRepository);
        }
Ejemplo n.º 16
0
        public void TestMethodAddCard_ShouldAddCard()
        {
            CreditCardViewModel value = new CreditCardViewModel()
            {
                CardNumber = 55555555555, ExpiryDate = DateTime.UtcNow
            };

            var controller = new CreditCardController(_creditCardService);
            var result     = ((System.Web.Http.Results.OkNegotiatedContentResult <int>)controller.Post(value));

            Assert.IsTrue(result.Content.Equals(1));
        }
Ejemplo n.º 17
0
        public void CreditCardController_Get_Cache()
        {
            var creditCard = new CreditCard();

            mockedCreditCardRepository.Setup(s => s.GetCreditCard(It.IsAny <string>())).Returns(() => null);
            mockedCacheRepository.Setup(s => s.GetAsync(It.IsAny <string>())).Returns(() => Task.FromResult(creditCard as object));
            mockedAuditHandler.Setup(s => s.Post(It.IsAny <Audit.Audit>())).Verifiable();
            CreditCardController creditCardController = new CreditCardController(mockedCreditCardRepository.Object, mockedCacheRepository.Object, mockedAuditHandler.Object);
            var result = creditCardController.Get(string.Empty);

            Assert.IsNotNull(result.Result);
        }
Ejemplo n.º 18
0
        public void TestInValid_Visa()
        {
            var ccDTO = new CreditCardDTO {
                Number = "4348601342777256", Expiry = "052021"
            };
            var controller = new CreditCardController(ccDTO);

            var result = controller.FetchValidationResult(ccDTO);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.CardType.ToLower(), "visa");
            Assert.AreEqual(result.Result.ToLower(), "invalid");
        }
Ejemplo n.º 19
0
        public void TestInValid_Mastercard()
        {
            var ccDTO = new CreditCardDTO {
                Number = "5554705785720271", Expiry = "022280"
            };
            var controller = new CreditCardController(ccDTO);

            var result = controller.FetchValidationResult(ccDTO);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.CardType.ToLower(), "mastercard");
            Assert.AreEqual(result.Result.ToLower(), "invalid");
        }
Ejemplo n.º 20
0
        public void TestInValid_Amex()
        {
            var ccDTO = new CreditCardDTO {
                Number = "31643311XX15513", Expiry = "022281"
            };
            var controller = new CreditCardController(ccDTO);

            var result = controller.FetchValidationResult(ccDTO);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.CardType.ToLower(), "amex");
            Assert.AreEqual(result.Result.ToLower(), "invalid");
        }
Ejemplo n.º 21
0
        public void TestInValid_JCB()
        {
            var ccDTO = new CreditCardDTO {
                Number = "326026WWW6585401", Expiry = "022281"
            };
            var controller = new CreditCardController(ccDTO);

            var result = controller.FetchValidationResult(ccDTO);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.CardType.ToLower(), "jcb");
            Assert.AreEqual(result.Result.ToLower(), "invalid");
        }
Ejemplo n.º 22
0
        public void GetCreditCardWithCurrentAndNextBills_RecoveryExistingBills()
        {
            // Arrange
            MonthYear       monthYear  = MonthYear.Create(2018, 4);
            DbCreditCardDto creditCard = testsUtils.AddSingleCreditCard();

            var bill = new DbCreditCardBillDto()
            {
                CreditCardId = creditCard.Id,
                ClosingDay   = TestsUtils.CLOSING_DAY + 1,
                DueDate      = monthYear.GetFirstDay(),
                CategoryId   = creditCard.CategoryId
            };

            dbUtils.Insert(bill);

            var statement = new DbCreditCardStatementDto()
            {
                BillId      = bill.Id,
                Amount      = 100m,
                BuyDate     = DateTime.Parse("2018-05-05"),
                Description = "test credit card statement"
            };

            dbUtils.Insert(statement);

            var sut = new CreditCardController(new CreditCardRepository(dbUtils.DbContext));

            // Act
            var creditCardList = sut.GetList(monthYear);

            // Assert
            Assert.Equal(1, creditCardList.Count);

            CreditCardBill currentBill = creditCardList.First().GetCurrentBill(monthYear);

            Assert.Equal(bill.Id, currentBill.Id);
            Assert.Equal(TestsUtils.CLOSING_DAY + 1, currentBill.ClosingDay);
            Assert.Equal(creditCard.Id, currentBill.CreditCard.Id);
            Assert.Equal(1, currentBill.Statements.Count);

            CreditCardBill nextBill = creditCardList.First().GetNextBill(monthYear);

            Assert.True(nextBill.Id > 0);
            Assert.Equal(TestsUtils.CLOSING_DAY, nextBill.ClosingDay);
            Assert.Equal(creditCard.Id, nextBill.CreditCard.Id);
            Assert.Equal(0, nextBill.Statements.Count);
        }
Ejemplo n.º 23
0
        public async void Get_Not_Exists()
        {
            CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCreditCardResponseModel>(null));
            CreditCardController controller = new CreditCardController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public async void ShouldGetByID_CreditCard()
        {
            Mock <ISecureXRepository> MoqRepo = new Mock <ISecureXRepository>();
            CreditCard cc1 = new CreditCard()
            {
                Id               = 133,
                CreditLimit      = 1000m,
                CurrentDebt      = 1000m,
                CreditCardNumber = 2234923,
                CustomerId       = 33
            };

            MoqRepo.Setup(x => x.GetCreditCardById(cc1.Id)).ReturnsAsync(cc1);
            var con    = new CreditCardController(MoqRepo.Object);
            var result = await con.GetById(cc1.Id);

            result.Value.Should().BeEquivalentTo(cc1);
        }
Ejemplo n.º 25
0
        public async void Delete_Errors()
        {
            CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            CreditCardController controller = new CreditCardController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Delete(default(int));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>()));
        }
Ejemplo n.º 26
0
        public async void All_Not_Exists()
        {
            CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade();

            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiCreditCardResponseModel> >(new List <ApiCreditCardResponseModel>()));
            CreditCardController controller = new CreditCardController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiCreditCardResponseModel>;

            items.Should().BeEmpty();
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Ejemplo n.º 27
0
        public async void Update_NotFound()
        {
            CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiCreditCardResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCreditCardRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiCreditCardResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCreditCardResponseModel>(null));
            CreditCardController controller = new CreditCardController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiCreditCardModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Update(default(int), new ApiCreditCardRequestModel());

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 28
0
        public async void Patch_Record_Not_Found()
        {
            CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCreditCardResponseModel>(null));
            CreditCardController controller = new CreditCardController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiCreditCardRequestModel>();

            patch.Replace(x => x.CardNumber, "A");

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
 public CreditCardControllerTest()
 {
     _creditCardService = new Mock <ICreditCardService>();
     _logger            = new Mock <ILogger <CreditCardController> >();
     _controller        = new CreditCardController(_creditCardService.Object, _logger.Object);
 }
 public CreditCardControllerTest()
 {
     _seed       = Guid.NewGuid().ToString();
     _controller = MockController.CreateController <CreditCardController>(_seed, "user");
 }