public void GetAllSuppliersReturnsEverythingInRepository() { var allSuppliers = new[] { new Supplier() { Name = "ANTEL", Commission = 1, SupplierId = 1 }, new Supplier() { Name = "OSE", Commission = 2, SupplierId = 2 } }; var mockSupplierService = new Mock <ISupplierService>(); mockSupplierService.Setup(x => x.GetAllSuppliers()).Returns(allSuppliers); var controller = new SuppliersController(mockSupplierService.Object); IHttpActionResult actionResult = controller.GetSuppliers(); OkNegotiatedContentResult <IEnumerable <Supplier> > contentResult = Assert.IsType <OkNegotiatedContentResult <IEnumerable <Supplier> > >(actionResult); Assert.NotNull(contentResult); Assert.NotNull(contentResult.Content); Assert.Same(allSuppliers, contentResult.Content); }
public async Task NonExistentSuppliers_GetSuppliers_ReturnNotFound() { _supplierService.Setup(s => s.GetAll()).Returns(Task.FromResult <ICollection <Supplier> >(null)); var response = await _suppliersController.GetSuppliers(); Assert.IsType <ActionResult <SupplierModel[]> >(response); Assert.IsType <NotFoundResult>(response.Result); }
public async Task Can_get_all_Suppliers_in_database() { using (var context = new ProcurementDbContext(ContextOptions)) { SuppliersController suppliersController = new SuppliersController(context); var result = await suppliersController.GetSuppliers(); var viewResult = Assert.IsType <ActionResult <IEnumerable <Supplier> > >(result); var suppliers = Assert.IsType <List <Supplier> >(viewResult.Value); Assert.Equal(3, suppliers.Count); } }