public async Task ItemsController_GetAllItems() { // Arrange var items = new List <ItemModel>() { new ItemModel { Id = 1, ItemName = "name" }, new ItemModel { Id = 2, ItemName = "fame" } }; var mockRepo = new Mock <IItemsBLL>(); var httpServiceMock = new Mock <IHttpServices>(); mockRepo.Setup(x => x.GetItems()) .ReturnsAsync(items); var controller = new ItemsController(mockRepo.Object, httpServiceMock.Object); // Act var result = await controller.GetAll(); // Assert Assert.Equal(items, result.Value); }
public async Task GetAll_ReturnsItems() { // Arrange var options = new DbContextOptionsBuilder <TodoDbContext>() .UseInMemoryDatabase(databaseName: "GetAll_ReturnsItems") .Options; var context = new TodoDbContext(options); context.Items.AddRange( Enumerable.Range(1, 10).Select(t => new Item { Description = "Item " + t }) ); context.SaveChanges(); var controller = new ItemsController(context); // Act var result = await controller.GetAll(); // Assert var model = Assert.IsAssignableFrom <IEnumerable <Item> >(result); Assert.Equal(10, model.Count()); }
public void GetAll() { var controller = new ItemsController(); var result = controller.GetAll(); Assert.IsInstanceOfType(result, typeof(Microsoft.AspNetCore.Mvc.OkObjectResult)); }
public async Task Should_get_all_items() { //Act var result = await _itemsController.GetAll(); //Assert await _itemService.Received(1).GetAll(); result.Should().BeOfType <OkObjectResult>(); }
public async Task GetAll_ReturnsItems() { // Arrange var controller = new ItemsController(_context); // Act var result = await controller.GetAll(); // Assert var model = Assert.IsAssignableFrom <IEnumerable <Item> >(result); Assert.Equal(10, model.Count()); }
public async void GetAllReturnsAllItems() { // Arrange var items = GetTestItems(); var mock = new Mock <IItemsRepository>(); mock.Setup(repo => repo.GetAll()).Returns(items); var controller = new ItemsController(mock.Object); // Act var actual = await controller.GetAll(); List <Item> result = actual?.Value as List <Item>; // Assert Assert.IsType <JsonResult>(actual); Assert.Equal((await items).Count, result.Count()); }
static async Task Main(string[] args) { var octrl = new OrdersController(); var neworder = new Order { Id = 0, Description = "4000 boxes", Status = "Delivered", Total = 8000.00m, CustomerId = 1 }; var WALorder1 = await octrl.Create(neworder); var neworder2 = new Order { Id = 0, Description = "2000 labels", Status = "Delivered", Total = 2500.00m, CustomerId = 1 }; var WALorder2 = await octrl.Create(neworder2); var allorders = await octrl.GetAll(); foreach (var o in allorders) { Console.WriteLine($"{o.Description} | {o.Total}"); } var oup = await octrl.GetByPK(2); oup.Status = "In Transit"; await octrl.Change(oup); var findorder = await octrl.GetByPK(2); if (findorder == null) { Console.WriteLine($"Order could not be found"); } else { Console.WriteLine($"{findorder.Description}"); } var orderdelete = await octrl.Remove(findorder.Id); var ictrl = new ItemsController(); var newitem = new Item { Id = 0, Name = "Box", Price = 2.00m }; var box = await ictrl.Create(newitem); var newitem2 = new Item { Id = 0, Name = "Packing Tape", Price = 1.50m }; var tape = await ictrl.Create(newitem2); var items = await ictrl.GetAll(); foreach (var i in items) { Console.WriteLine($"{i.Name}"); } var itup = await ictrl.GetByPK(4); itup.Name = "Label"; itup.Price = 1.25m; await ictrl.Change(itup); var find4 = await ictrl.GetByPK(4); if (find4 == null) { Console.WriteLine("Is Null"); } else { Console.WriteLine($"{find4.Name} | {find4.Price}"); } var itemdeleted = await ictrl.Remove(3); //var cctrl = new CustomerController(); //var newcust = new Customer { // Id = 0, Code = "WAL", Name = "Walmart", Sales = 250000.00m, // Created = new DateTime(2010, 02, 01) //}; ////var walmart = await cctrl.Create(newcust); ////Console.WriteLine($"{walmart.Id}| {walmart.Code}"); //var newcust2 = new Customer { // Id = 0, Code = "AMAZ", Name = "Amazon", Sales = 400000.00m, // Created = new DateTime(2012, 04, 01) //}; ////var amazon = await cctrl.Create(newcust2); ////Console.WriteLine($"{amazon.Id} | {amazon.Code}"); //var allcust = await cctrl.GetAll(); //foreach(var c in allcust) { // Console.WriteLine($"{c.Name} | {c.Created} | {c.Sales}"); //} //var amazchange = await cctrl.GetByPk(2); //amazchange.Sales = 450000.00m; ////await cctrl.Change(amazchange); ////Console.WriteLine($"{amazchange.Sales}"); //var findamaz = await cctrl.GetByPk(2); ////if(findamaz == null) { //// Console.WriteLine($"Not Found"); ////}else { //// Console.WriteLine($"{findamaz.Code} | {findamaz.Name}"); ////} ////var custdeleted = await cctrl.Remove(findamaz.Id); }