Exemplo n.º 1
0
        public async Task Test_DeleteCard_ReturnsOk()
        {
            // Arrange
            var walletId = 1;

            CardRepoMock.Setup(r => r.DeleteAsync(walletId)).ReturnsAsync(0);

            // Act
            var response = await Client.DeleteAsync($"/api/cards/Delete/{walletId}");

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            CardRepoMock.Verify(r => r.DeleteAsync(walletId), Times.Once);
        }
Exemplo n.º 2
0
        public async Task Test_AddCard_ReturnsOk()
        {
            // Arrange
            var newCard = new CardDTO {
                WalletId = 1, Description = "for shopping"
            };

            CardRepoMock.Setup(r => r.CreateAsync(It.IsAny <Card>())).ReturnsAsync(new Card());
            var newCardJson = JsonConvert.SerializeObject(newCard);
            var content     = new StringContent(newCardJson, Encoding.UTF8, "application/json");

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

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            CardRepoMock.Verify(r => r.CreateAsync(It.IsAny <Card>()), Times.Once);
        }
Exemplo n.º 3
0
        public async Task Test_DetailsCard_ReturnsOk()
        {
            // Arrange
            var walletId = 1;

            CardRepoMock.Setup(r => r.GetAsync(walletId)).ReturnsAsync(new Card {
                WalletId = walletId, Description = "for shopping", Number = "3566002020360505"
            });

            // Act
            var response = await Client.GetAsync($"/api/cards/Details/{walletId}");

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            var content = await response.Content.ReadAsStringAsync();

            var card = JsonConvert.DeserializeObject <CardDTO>(content);

            Assert.AreEqual(walletId, card.WalletId);
        }