public async Task GetPaymentAsync_WhenInnerRepositoryResultIsNotNull_ShouldDecryptCardNumberAndCardName() { //Arrange var paymentRecord = GetPaymentRecordObject(); var expectedCardNumberDecryption = "cardNumberDecrypted"; var expectedCardNameDecryption = "cardNameDecrypted"; _innerPaymentsRepositoryMock.Setup(x => x.GetPaymentAsync(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(paymentRecord); _encryptorMock.Setup(x => x.Decrypt(paymentRecord.CardNumber)).Returns(expectedCardNumberDecryption); _encryptorMock.Setup(x => x.Decrypt(paymentRecord.CardName)).Returns(expectedCardNameDecryption); var sut = new PaymentsEncryptorRepository(_innerPaymentsRepositoryMock.Object, _encryptorMock.Object); //Act var result = await sut.GetPaymentAsync(paymentRecord.Id, paymentRecord.CompanyId); var expectedPaymentRecord = paymentRecord; expectedPaymentRecord.CardNumber = expectedCardNumberDecryption; expectedPaymentRecord.CardName = expectedCardNameDecryption; //Assert result.Should().BeEquivalentTo(expectedPaymentRecord); }
public async Task GetPaymentAsync_WhenInnerRepositoryResultIsNull_ShouldNotDecrypt() { //Arrange _innerPaymentsRepositoryMock.Setup(x => x.GetPaymentAsync(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(default(PaymentRecord?)); var sut = new PaymentsEncryptorRepository(_innerPaymentsRepositoryMock.Object, _encryptorMock.Object); //Act var result = await sut.GetPaymentAsync(Guid.NewGuid(), Guid.NewGuid()); //Assert _encryptorMock.Verify(x => x.Decrypt(It.IsAny <string>()), Times.Never); _encryptorMock.Verify(x => x.Encrypt(It.IsAny <string>()), Times.Never); }