public async Task DetailsGetAction_GetModelFromService() { // Arrange // Act var result = await validController.Details(entity.Id); // Assert mock.Verify(a => a.GetAsync(entity.Id, false)); }
public void test_Db_Edit_UpdatesInDb() { //Arrrange ItemsController controller = new ItemsController(db); Item testItem = new Item { ItemId = 16, Name = "Lil Pump", Description = "rap gummi", Cost = 234 }; Item updatedItem = new Item { ItemId = 9, Name = "Lil Flip", Description = "rap dummi", Cost = 123 }; //Act controller.Create(testItem); testItem.Name = "Lil Flip"; controller.Edit(testItem); var returnItem = (controller.Details(1) as ViewResult).ViewData.Model as Item; //Assert Assert.AreEqual(returnItem.Name, "Lil Flip"); }
public async void ItemsController_GetSelectedItemDataAsync() { context = GetInMemoryContext(); controller = new ItemsController(context); Item newItem = new Item() { Id = 1, Title = "First", About = "About", CurrentPrice = 222.22m, Image = "image/href" }; await context.AddAsync(newItem); await context.SaveChangesAsync(); OkObjectResult itemRes = await controller.Details(newItem.Id) as OkObjectResult; Assert.NotNull(itemRes); Item item = itemRes.Value as Item; Assert.Equal(newItem.Title, item.Title); Assert.Equal(newItem.Image, item.Image); Assert.Equal(newItem.About, item.About); Assert.Equal(newItem.CurrentPrice, item.CurrentPrice); Assert.Equal(newItem.PriceHistory.Count, item.PriceHistory.Count); }
public async void ItemsController_ThrowNotFoundExceptionItemsEmptyAsync() { context = GetInMemoryContext(); controller = new ItemsController(context); NotFoundResult itemRes = await controller.Details(1) as NotFoundResult; Assert.NotNull(itemRes); }
public void Get_ViewResult_Details_Test() { //Arrange ItemsController controller = new ItemsController(); //Act var result = controller.Details(0); //Assert Assert.IsType <ViewResult>(result); }
public void Mock_GetDetails_ReturnsView() { //Arrange Item item = new Item(); DbSetup(); ItemsController controller = new ItemsController(mock.Object); //Act var resultView = controller.Details(item.ItemId) as ViewResult; var model = resultView.ViewData.Model as Item; //Assert Assert.IsInstanceOfType(resultView, typeof(ViewResult)); }
public void Mock_HttpGetDetails_ReturnsView() { //arrange Item item = new Item { ItemId = 1, Name = "Blender" }; DbSetUp(); ItemsController controller = new ItemsController(mock.Object); //act var resultView = controller.Details(item.ItemId) as ViewResult; var model = resultView.ViewData.Model as Item; //assert Assert.IsInstanceOfType(resultView, typeof(ViewResult)); Assert.IsInstanceOfType(model, typeof(Item)); }
public void testDb_EditWOrks_UpdatesInDb() { //arrange ItemsController controller = new ItemsController(db); Item testItem = new Item { ItemId = 1, Name = "Blender" }; Item updatedItem = new Item { ItemId = 1, Name = "Blender" }; //act testItem.Name = "Blender"; var returnedItem = (controller.Details(1) as ViewResult).ViewData.Model as Item; //assert Assert.AreEqual(returnedItem.Name, "Blender"); }
public void Mock_GetDetails_ReturnsView() { // Arrange Item testItem = new Item { ItemId = 1, Description = "Wash the dog" }; DbSetup(); ItemsController controller = new ItemsController(mock.Object); // Act var resultView = controller.Details(testItem.ItemId) as ViewResult; var model = resultView.ViewData.Model as Item; // Assert Assert.IsInstanceOfType(resultView, typeof(ViewResult)); Assert.IsInstanceOfType(model, typeof(Item)); }
public async void ItemsController_ThrowNotFoundExceptionItemNullIdAsync() { context = GetInMemoryContext(); controller = new ItemsController(context); Item newItem = new Item() { Id = 1, Title = "First", About = "About", CurrentPrice = 222.22m, Image = "image/href" }; await context.AddAsync(newItem); await context.SaveChangesAsync(); NotFoundResult itemRes = await controller.Details(null) as NotFoundResult; Assert.NotNull(itemRes); }