Beispiel #1
0
        public async Task Test_MakeIncomeOk()
        {
            // Arrange
            int walletId    = 1;
            var transaction = new Transaction {
                TargetWalletId = walletId, Amount = 433, Description = "transact"
            };

            TransactionRepoMock.Setup(r => r.MakeIncomeAsync(transaction)).ReturnsAsync(transaction);
            var newTransactionJson = JsonConvert.SerializeObject(transaction);
            var content            = new StringContent(newTransactionJson, Encoding.UTF8, "application/json");

            // Act
            var response = await Client.PostAsync("/api/transactions/makeincome", content);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            TransactionRepoMock.Verify(r => r.MakeIncomeAsync(It.IsAny <Transaction>()), Times.Once);
        }
Beispiel #2
0
        public async Task Test_UpdateTransaction_ReturnsOk()
        {
            // Arrange
            var transactionId = 1;
            var transaction   = new TransactionDTO {
                Id = transactionId, Description = "desc"
            };

            TransactionRepoMock.Setup(r => r.UpdateAsync(transactionId, It.IsAny <Transaction>())).ReturnsAsync(new Transaction());
            var newTransactionJson = JsonConvert.SerializeObject(transaction);
            var content            = new StringContent(newTransactionJson, Encoding.UTF8, "application/json");

            // Act
            var response = await Client.PutAsync($"/api/transactions/Update/{transactionId}", content);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            TransactionRepoMock.Verify(r => r.UpdateAsync(transactionId, It.IsAny <Transaction>()), Times.Once);
        }
Beispiel #3
0
        public async Task Test_DetailsTransaction()
        {
            // Arrange
            int walletId      = 1;
            int transactionId = 1;
            var transaction   = new Transaction {
                SourceWalletId = walletId, Amount = 433, Description = "transact"
            };

            TransactionRepoMock.Setup(r => r.GetAsync(walletId, transactionId)).ReturnsAsync(transaction);

            // Act
            var response = await Client.GetAsync($"/api/transactions/details/1?walletId=1&transactionId=1");

            // Assert
            response.EnsureSuccessStatusCode();
            var transactionJson = await response.Content.ReadAsStringAsync();

            var trans = JsonConvert.DeserializeObject <TransactionDTO>(transactionJson);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            //Assert.AreEqual(trans, transaction);
            Assert.AreEqual(walletId, transaction.SourceWalletId);
        }