public void GenerateToken_ShouldGenerateAValidToken(long number, int cvv, string strExpectedToken) { // Arrange var expectedToken = Guid.Parse(strExpectedToken); // Act var token = CardHelper.GenerateToken(number, cvv); // Assert token.Should().Be(expectedToken); }
public async Task <CreateCardCommandResult> Handle(CreateCardCommandInput command, CancellationToken cancellationToken) { var customerId = command.CustomerId; var number = command.CardNumber; var cvv = command.CVV; var token = CardHelper.GenerateToken(number, cvv); var card = new Card(customerId, number, token); await _cardRepository.AddAsync(card, cancellationToken); await _cardRepository.UnitOfWork.CommitAsync(cancellationToken); return(new CreateCardCommandResult(card.CreationDate, card.Token, card.Id)); }
public async Task <ValidateCardTokenCommandResult> Handle(ValidateCardTokenCommandInput command, CancellationToken cancellationToken) { var card = await _cardRepository .Get(x => x.Id == command.CardId) .FirstOrDefaultAsync(cancellationToken); var creationDateRuleFailed = card.CreationDate.AddMinutes(30) < DateTime.UtcNow; var customerOwnerRuleFailed = card.CustomerId != command.CustomerId; var tokenRuleFailed = CardHelper.GenerateToken(card.Number, command.CVV) != command.Token; if (creationDateRuleFailed || customerOwnerRuleFailed || tokenRuleFailed) { return(new ValidateCardTokenCommandResult(false)); } Debug.WriteLine($"Card Number: {card.Number}."); return(new ValidateCardTokenCommandResult(true)); }
public async Task Create_ShouldReturnTheNewCard() { // Arrange const string url = "/v1/cards"; const int customerId = 1; const long cardNumber = 1234123412341234; const int cvv = 12345; var request = new CardRequest { CustomerId = customerId, CardNumber = cardNumber, CVV = cvv }; var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); // Act var response = await _testsFixture.Client.PostAsync(url, content); response.EnsureSuccessStatusCode(); var responseContentString = await response.Content.ReadAsStringAsync(); var cardResponse = JsonConvert.DeserializeObject <CardResponse>(responseContentString); // Assert response.StatusCode.Should().Be(HttpStatusCode.Created); response.Headers.Location.Should().Be($"/v1/cards/{cardResponse.CardId}"); cardResponse.CreationDate.Should().BeBefore(DateTime.UtcNow); cardResponse.CreationDate.Should().BeAfter(DateTime.UtcNow.AddSeconds(-1).Date); cardResponse.Token.Should().Be(CardHelper.GenerateToken(cardNumber, cvv)); cardResponse.CardId.Should().NotBeEmpty(); }