public async Task GetPurchaseTest_Valid() { // Arrange var repo = new FakePurchaseRepo(TestData.Purchases()); var productRepo = new FakeProductService(TestData.Products()); using (var controller = new PurchasesController(repo, productRepo, null, null)) { var purchaseId = 1; // Act var result = await controller.Details(purchaseId); // Assert Assert.IsNotNull(result); var objResult = result.Result as OkObjectResult; Assert.IsNotNull(objResult); var retResult = objResult.Value as PurchaseDetailsDto; Assert.IsNotNull(retResult); Assert.AreEqual(TestData.Purchases()[purchaseId - 1].ProductId, retResult.Id); Assert.AreEqual(TestData.Purchases()[purchaseId - 1].ProductId, retResult.ProductId); Assert.AreEqual(TestData.Purchases()[purchaseId - 1].Qty, retResult.Qty); Assert.AreEqual(TestData.Purchases()[purchaseId - 1].AddressId, retResult.AddressId); Assert.AreEqual(TestData.Purchases()[purchaseId - 1].AccountId, retResult.AccountId); Assert.AreEqual(TestData.Purchases()[purchaseId - 1].OrderStatus, retResult.OrderStatus); Assert.AreEqual(TestData.Purchases()[purchaseId - 1].TimeStamp, retResult.TimeStamp); } }
public async void Detail_ReturnNotFound(int?id) { // Arrange var mockRepo = new Mock <IAsyncRepository <Purchase> >(); var mockMediator = new Mock <IMediator>(); mockRepo.Setup(repo => repo.GetByIdAsync(id)).ReturnsAsync(GetPurchases().Find(i => i.PurchId == id)); mockMediator .Setup(m => m.Send(It.IsAny <GetPurchaseCheck>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new PurchaseCheckViewModel() { Purchase = GetPurchases().Find(i => i.PurchId == id) }) .Verifiable(); var controller = new PurchasesController(mockRepo.Object, mockMediator.Object); // Act var result = await controller.Details(id); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task GetPurchaseDetailsTest_OutOfBoundsID() { // Arrange var repo = new FakePurchaseRepo(TestData.Purchases()); var productRepo = new FakeProductService(TestData.Products()); using (var controller = new PurchasesController(repo, productRepo, null, null)) { var purchaseId = -6; //Act var result = await controller.Details(purchaseId); // Assert Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult)); } }
public async Task DeletePurchase_Success() { // Arrange var repo = new FakePurchaseRepo(TestData.Purchases()); var productRepo = new FakeProductService(TestData.Products()); using (var controller = new PurchasesController(repo, productRepo, null, null)) { var purchaseId = 1; // Act await controller.DeleteConfirmed(purchaseId); // Assert var purchase = await controller.Details(purchaseId); Assert.IsInstanceOfType(purchase.Result, typeof(NotFoundResult)); } }