public void GetCardType_WrongFormatCard() { var options = new DbContextOptionsBuilder <SATADbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; var dbContext = new SATADbContext(options); var expiryService = A.Fake <IExpiryService>(); var cardService = new CardService(dbContext, expiryService); var card = new Card { CardNumber = "912341234123412", ExpiryDate = "102020" }; var cardType = cardService.GetCardType(card); Assert.Equal(CardType.WrongFormatCard, cardType); }
public void Validate_Unknow_Invalid() { var options = new DbContextOptionsBuilder <SATADbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; var dbContext = new SATADbContext(options); var expiryService = A.Fake <IExpiryService>(); var cardService = new CardService(dbContext, expiryService); var card = new Card { CardNumber = "91234123412341231", ExpiryDate = "102020" }; var result = cardService.Validate(card); Assert.Equal(ResultType.INVALID, result.Result); }
public void Validate_Master_Invalid() { var options = new DbContextOptionsBuilder <SATADbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; var dbContext = new SATADbContext(options); var expiryService = A.Fake <IExpiryService>(); var cardService = new CardService(dbContext, expiryService); var card = new Card { CardNumber = "5123412341234123", ExpiryDate = "102020" }; A.CallTo(() => expiryService.IsPrimeNumber(A <string> ._)).Returns(false); var result = cardService.Validate(card); Assert.Equal(ResultType.INVALID, result.Result); }
public void Validate_Visa_Valid() { var options = new DbContextOptionsBuilder <SATADbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; var dbContext = new SATADbContext(options); var expiryService = A.Fake <IExpiryService>(); var cardService = new CardService(dbContext, expiryService); var card = new Card { CardNumber = "4123412341234123", ExpiryDate = "102020" }; A.CallTo(() => expiryService.IsLeapYear(A <string> ._)).Returns(true); var result = cardService.Validate(card); Assert.Equal(ResultType.VALID, result.Result); Assert.Equal(CardType.Visa.ToString(), result.CardType); }
public CardService(SATADbContext dbContext, IExpiryService expiryService) { this.dbContext = dbContext; this.expiryService = expiryService; }
public CardController(SATADbContext dbContext, ICardService cardService) { this.cardService = cardService; }