Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
test(back-end): Add a rename test cases in ProductInvoices controller
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
CarlosPavajeau committed Jan 17, 2021
1 parent 80a4b82 commit fbbbf8c
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions Kaizen.Test/Controllers/ProductInvoicesControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public void SetUp()

_productInvoicesController = new ProductInvoicesController(_productInvoicesRepository.Object,
_unitWork.Object, ServiceProvider.GetService<IMapper>());

SetUpProductInvoicesRepository();
SetUpUnitWork();
}

[Test]
public async Task GetProductInvoices()
private void SetUpProductInvoicesRepository()
{
_productInvoicesRepository.Setup(r => r.GetAll()).Returns(new TestAsyncEnumerable<ProductInvoice>(
new List<ProductInvoice>
Expand All @@ -54,6 +56,28 @@ public async Task GetProductInvoices()
}
}).AsQueryable());

_productInvoicesRepository.Setup(r => r.FindByIdAsync(1)).ReturnsAsync(new ProductInvoice
{
Id = 1,
ClientId = "1007870922",
GenerationDate = DateTime.Now,
ProductInvoiceDetails = new List<ProductInvoiceDetail>()
});
_productInvoicesRepository.Setup(r => r.FindByIdAsync(3)).ReturnsAsync((ProductInvoice)null);

_productInvoicesRepository.Setup(r => r.Update(It.IsAny<ProductInvoice>()));
_productInvoicesRepository.Setup(r => r.Insert(It.IsAny<ProductInvoice>())).Verifiable();

}

private void SetUpUnitWork()
{
_unitWork.Setup(r => r.SaveAsync()).Returns(Task.CompletedTask);
}

[Test]
public async Task Get_All_ProductInvoices()
{
OkObjectResult result = (await _productInvoicesController.GetProductInvoices()).Result as OkObjectResult;

Assert.NotNull(result);
Expand All @@ -62,36 +86,27 @@ public async Task GetProductInvoices()
}

[Test]
public async Task GetProductInvoice()
public async Task Get_Existing_ProductInvoice()
{
_productInvoicesRepository.Setup(r => r.FindByIdAsync(1)).ReturnsAsync(new ProductInvoice
{
Id = 1,
ClientId = "1007870922",
GenerationDate = DateTime.Now,
ProductInvoiceDetails = new List<ProductInvoiceDetail>()
});

ActionResult<ProductInvoiceViewModel> result = await _productInvoicesController.GetProductInvoice(1);

Assert.NotNull(result);
Assert.NotNull(result.Value);
}

[Test]
public async Task PutProductInvoice()
public async Task Get_Non_Existent_ProductInvoice()
{
_productInvoicesRepository.Setup(r => r.FindByIdAsync(1)).ReturnsAsync(new ProductInvoice
{
Id = 1,
ClientId = "1007870922",
GenerationDate = DateTime.Now,
ProductInvoiceDetails = new List<ProductInvoiceDetail>()
});
_productInvoicesRepository.Setup(r => r.Update(It.IsAny<ProductInvoice>()));
_unitWork.Setup(r => r.SaveAsync()).Returns(Task.CompletedTask);
ActionResult<ProductInvoiceViewModel> result = await _productInvoicesController.GetProductInvoice(3);

Assert.IsNotNull(result);
Assert.IsNull(result.Value);
Assert.IsInstanceOf<NotFoundObjectResult>(result.Result);
}

[Test]
public async Task Update_Existing_ProductInvoice()
{
ActionResult<ProductInvoiceViewModel> result = await _productInvoicesController.PutProductInvoice(1, new ProductInvoiceEditModel
{
State = InvoiceState.Regenerated
Expand All @@ -102,12 +117,22 @@ public async Task PutProductInvoice()
}

[Test]
public async Task PostProductInvoice()
public async Task Update_Non_Existent_ProductInvoice()
{
_productInvoicesRepository.Setup(r => r.Insert(It.IsAny<ProductInvoice>())).Verifiable();
_unitWork.Setup(r => r.SaveAsync()).Returns(Task.CompletedTask);
ActionResult<ProductInvoiceViewModel> result = await _productInvoicesController.PutProductInvoice(3, new ProductInvoiceEditModel
{
State = InvoiceState.Regenerated
});

Assert.IsNotNull(result);
Assert.IsNull(result.Value);
Assert.IsInstanceOf<BadRequestObjectResult>(result.Result);
}

var result = await _productInvoicesController.PostProductInvoice(new ProductInvoiceInputModel
[Test]
public async Task Save_New_ProductInvoice()
{
ActionResult<ProductInvoiceViewModel> result = await _productInvoicesController.PostProductInvoice(new ProductInvoiceInputModel
{
ClientId = "1007870922",
State = InvoiceState.Generated
Expand Down

0 comments on commit fbbbf8c

Please sign in to comment.