コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
            }
        }