public void PostSuppliersTest() { var supplier = DataHelper.GetDummySupplier(); moqSuppliersService.Setup(x => x.InsertSupplier(It.IsAny <Supplier>())); var response = controller.PostSupplier(supplier).Result; moqSuppliersService.Verify(mock => mock.InsertSupplier(It.IsAny <Supplier>()), Times.Once()); Assert.That(response, Is.InstanceOf <ActionResult <Supplier> >()); }
public async void GetSupplier() { // Dodavanje dobavljaca prije dohvacanja using (var context = new StoreSampleContext(_dbContextOptions)) { var suppliersAPI = new SuppliersController(context); for (int i = 0; i < 10; ++i) { Supplier tmpSupplier = new Supplier(); tmpSupplier.CompanyName = $"Kompanija { i + 1 }"; tmpSupplier.City = "Zagreb"; tmpSupplier.Country = "Hrvatska"; tmpSupplier.Phone = $"01 234 567{ i }"; suppliersAPI.PostSupplier(tmpSupplier).Wait(); } } using (var context = new StoreSampleContext(_dbContextOptions)) { var suppliersAPI = new SuppliersController(context); var result = await suppliersAPI.GetSupplier(5); var okResult = result as OkObjectResult; // Ako je rezultat Ok i status kod je 200, tada je poziv uspjesan Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); // Ako je dohvacen dobavljac sa ispravnim brojem telefona, poziv je uspjesan Supplier supplier = okResult.Value as Supplier; Assert.NotNull(supplier); Assert.Equal("01 234 5674", supplier.Phone); } }
public async Task Can_add_Supplier_when_it_not_existing() { using (var context = new ProcurementDbContext(ContextOptions)) { SuppliersController suppliersController = new SuppliersController(context); Supplier supplier = new Supplier { SupplierCode = "SP4", SupplierName = "MAS Holdings", Address1 = "Colombo 3", CompanyNo = "011548795", MobileNo = "077485698", Email = "*****@*****.**" }; var result = await suppliersController.PostSupplier(supplier); var viewResult = Assert.IsType <ActionResult <Supplier> >(result); var actionResult = Assert.IsType <CreatedAtActionResult>(viewResult.Result); var model = Assert.IsType <Supplier>(actionResult.Value); Assert.Equal("SP4", model.SupplierCode); } }
public async void PostSupplier() { using (var context = new StoreSampleContext(_dbContextOptions)) { var suppliersAPI = new SuppliersController(context); for (int i = 0; i < 10; ++i) { Supplier tmpSupplier = new Supplier(); tmpSupplier.CompanyName = $"Kompanija { i + 1 }"; tmpSupplier.City = "Zagreb"; tmpSupplier.Country = "Hrvatska"; tmpSupplier.Phone = $"01 234 567{ i }"; var result = await suppliersAPI.PostSupplier(tmpSupplier); var badRequest = result as BadRequestObjectResult; Assert.Null(badRequest); // Ako API ne vraca BadRequest, to znaci da je poziv uspjesan } } }
private async void Task5_Delete_Supplier_OkResult() { //Arrange _context = new SDCContext(dbContextOptions); _controller = new SuppliersController(_context); var supplier = new Supplier() { Company = "Kitchener", }; //Act var resultCreate = await _controller.PostSupplier(supplier); var okResult = resultCreate.Should().BeOfType <CreatedAtActionResult>().Subject; var resClient = okResult.Value.Should().BeAssignableTo <Supplier>().Subject; int delId = resClient.SupplierId; var result = await _controller.DeleteSupplier(delId); //Assert Assert.IsType <OkObjectResult>(result); }
public async void Task3_Post_NewSupplier_JobTitle() { //Arrange _context = new SDCContext(dbContextOptions); _controller = new SuppliersController(_context); var supplier = new Supplier() { Company = "Pickle", }; //Act var result = await _controller.PostSupplier(supplier); //Assert var okResult = result.Should().BeOfType <CreatedAtActionResult>().Subject; var resClient = okResult.Value.Should().BeAssignableTo <Supplier>().Subject; resClient.Company.Should().Be("Pickle"); //delete JayNew int newId = _context.Supplier.FirstOrDefault(p => p.Company == "Pickle").SupplierId; var resultDelete = await _controller.DeleteSupplier(newId); }
public async Task Cannot_add_Supplier_when_it_exist() { using (var context = new ProcurementDbContext(ContextOptions)) { SuppliersController suppliersController = new SuppliersController(context); Supplier supplier = new Supplier { SupplierCode = "SP1", SupplierName = "MAS Holdings", Address1 = "Colombo 3", CompanyNo = "011548795", MobileNo = "077485698", Email = "*****@*****.**" }; try { await suppliersController.PostSupplier(supplier); } catch (Exception exception) { Assert.NotNull(exception); return; } Assert.True(false); } }