public async Task CreatePostAction_AddModelToService() { // Arrange // Act var result = await validController.Create(entity, new List <IFormFile>()); // Assert mock.Verify(a => a.AddAsync(entity)); }
public void Create_ReturnsCorrectActionType_RedirectToActionResult() { ItemsController ic = new ItemsController(); IActionResult view = ic.Create("Get a haircut"); Assert.IsInstanceOfType(view, typeof(RedirectToActionResult)); }
public void Create_ReturnsCorrectActionType_RedirectToActionResult() { ItemsController controller = new ItemsController(); IActionResult view = controller.Create("Walk the dog"); Assert.IsInstanceOfType(view, typeof(RedirectToActionResult)); }
public async Task Create_ReturnsNewlyCreatedTodoItem() { // Arrange var options = new DbContextOptionsBuilder <TodoDbContext>() .UseInMemoryDatabase(databaseName: "Create_ReturnsNewlyCreatedTodoItem") .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.Create(new Item { Description = "This is a new task" }); // Assert Assert.IsType <CreatedAtRouteResult>(result); Assert.Equal(11, context.Items.Count()); }
public void Post_MethodAddsItem_Test() { // Arrange ItemsController controller = new ItemsController(); CategoriesController catControl = new CategoriesController(); Item testItem = new Item(); Category testCategory = new Category(); testCategory.Name = "test"; testItem.Description = "test item"; // Act catControl.Create(testCategory); testItem.CategoryId = testCategory.CategoryId; //testItem.Category = testCategory; //testCategory.Items = new List<Item>(); //testCategory.Items.Add(testItem); //testCategory.CategoryId = 0; controller.Create(testItem); ViewResult indexView = new ItemsController().Index() as ViewResult; var collection = indexView.ViewData.Model as IEnumerable <Item>; // Assert Assert.Contains <Item>(testItem, collection); }
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 void ItemsController_AddsItemToIndexModelData_Collection() { // Arrange ItemsController controller = new ItemsController(); Item testItem = new Item(); testItem.Description = "test item"; Mock <IItemRepository> mock = new Mock <IItemRepository>(); mock.Setup(m => m.Items).Returns(new Item[] { new Item { ItemId = 1, Description = "Wash the dog" }, new Item { ItemId = 2, Description = "Do the dishes" }, new Item { ItemId = 3, Description = "Sweep the floor" } }.AsQueryable()); // Act controller.Create(testItem); ViewResult indexView = new ItemsController().Index() as ViewResult; var collection = indexView.ViewData.Model as List <Item>; // Assert CollectionAssert.Contains(collection, testItem); }
public void Create_RedirectsToCorrectAction_Index() { ItemsController ic = new ItemsController(); RedirectToActionResult actionResult = ic.Create("sleep in") as RedirectToActionResult; string result = actionResult.ActionName; Assert.AreEqual(result, "Index"); }
public async Task Create_ReturnsBadRequest_GivenNullItem() { var controller = new ItemsController(_context); var result = await controller.Create(null); Assert.IsType <BadRequestResult>(result); }
public async Task Create_ReturnsNewlyCreatedTodoItem() { var controller = new ItemsController(_context); var result = await controller.Create(new Item { Description = "This is a new task" }); Assert.IsType <CreatedAtRouteResult>(result); }
public void Create_RedirectsToCorrectAction_Index() { ItemsController controller = new ItemsController(); RedirectToActionResult actionResult = controller.Create("walk the dog") as RedirectToActionResult; string result = actionResult.ActionName; Assert.AreEqual(result, "Index"); }
public async Task Create_ReturnsBadRequest_WhenModelStateIsInvalid() { var controller = new ItemsController(_context); controller.ModelState.AddModelError("Name", "Required"); var result = await controller.Create(new Item()); Assert.IsType <BadRequestObjectResult>(result); }
public async Task CreatePostAction_ModelError_ReturnsSameModel() { // Arrange // Act var result = await notValidController.Create(entity, null) as ViewResult; // Assert Assert.Equal(entity, result.Model); }
public void Get_Create_Item_ReturnsActionResult() { //Arrange var mock = new Mock <IItemsRepository>(); var controller = new ItemsController(mock.Object); //Act ActionResult result = controller.Create(It.IsAny <ItemType>()); //Assert var viewResult = Assert.IsType <ViewResult>(result); }
public void Get_ViewResult_Create_Test() { //Arrange ItemsController controller = new ItemsController(); //Act var result = controller.Create(); //Assert Assert.IsType <ViewResult>(result); }
public async void UnitTest_addItem() { mockDB(); var controller = new ItemsController(_dbContext); int counter = _dbContext.item.Count(); string loggedUser = "******"; var result = await controller.Create(new Item { name = "newItem", description = "description of new item", value = 50 }, loggedUser); Assert.Equal(counter + 1, _dbContext.item.Count()); }
public void DB_CreateNewEntry_Test() { ItemsController controller = new ItemsController(db); Item testItem = new Item(); testItem.Description = "One two one two this is just a test"; controller.Create(testItem); var collection = (controller.Index() as ViewResult).ViewData.Model as IEnumerable <Item>; Assert.Contains <Item>(testItem, collection); }
public void Create_RedirectsToCorrectActionResult_New() { //Arrange ItemsController controller = new ItemsController(); RedirectToActionResult actionResult = controller.Create("string", 1, 2, false) as RedirectToActionResult; //Act string result = actionResult.ActionName; //Assert Assert.AreEqual(result, "Index"); }
public void Create_RedirectsToCorrectAction_Index() { //Arrange ItemsController controller = new ItemsController(); var actionResult = controller.Create("Walk the dog") as RedirectToActionResult; //Act string result = actionResult.ActionName; //Assert Assert.AreEqual(result, "Index"); }
public void CreateOrder() { var options = new DbContextOptionsBuilder <OrderContext>() .UseInMemoryDatabase(databaseName: "create_order") .Options; Customer customer; Item item; Order order; using (var context = new OrderContext(options)) { var controller = new CustomersController(context); customer = controller.Create(new CreateCustomer { Name = "customer" }); customer.Name.ShouldEqual("customer"); } using (var context = new OrderContext(options)) { var controller = new ItemsController(context); item = controller.Create(new CreateItem { Name = "item" }); item.Name.ShouldEqual("item"); } using (var context = new OrderContext(options)) { var controller = new OrdersController(context); order = controller.Create(new CreateOrder { CustomerId = customer.Id }); order.Customer.Name.ShouldEqual(customer.Name); } using (var context = new OrderContext(options)) { var controller = new OrdersController(context); order = controller.GetById(order.Id); order.Customer.Name.ShouldEqual(customer.Name); } // using (var context = new OrderContext(options)) // { // var controller = new OrdersController(context); // order = controller.Update(new CreateOrder { CustomerId = customer.Id }); // order.Customer.Name.ShouldEqual(customer.Name); // } }
public void Show_HasCorrectModelType_PackObjectList() { //Arrange ItemsController controller = new ItemsController(); controller.Create("string", 1, 2, false); ViewResult newShow = new ItemsController().Show(1) as ViewResult; //Act var result = newShow.ViewData.Model; //Assert Assert.IsInstanceOfType(result, typeof(List <PackObject>)); }
public void Create_ReturnsViewResultWithItemModelForCorrectInvoiceId() { // Arrange var mockRepo = new Mock <IInvoicesRepository>(); var controller = new ItemsController(mockRepo.Object); // Act var result = controller.Create(1); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <Item>(viewResult.ViewData.Model); Assert.Equal(1, model.InvoiceId); }
public void DB_CreateNewEntry_Test() { // Arrange ItemsController controller = new ItemsController(db); Item testItem = new Item(); testItem.Description = "TestDb Item"; // Act controller.Create(testItem); var collection = (controller.Index() as ViewResult).ViewData.Model as IEnumerable <Item>; // Assert Assert.Contains <Item>(testItem, collection); }
public void Show_ReturnsCorrectAction_True() { //Arrange ItemsController controller = new ItemsController(); controller.Create("string", 1, 2, false); //Act ActionResult showView = controller.Show(1); //Assert Assert.IsInstanceOfType(showView, typeof(ViewResult)); }
public void DB_CreateNewEntry_Test() { //Arrange ItemsController controller = new ItemsController(db); Item testItem = new Item(); testItem.Description = "TestDb Item"; testItem.CategoryId = 1; //Act controller.Create(testItem); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Item>; //Assert CollectionAssert.Contains(collection, testItem); }
public void Post_MethodAddsItem_Test() { // Arrange ItemsController controller = new ItemsController(); Item testItem = new Item(); testItem.Description = "test item"; // Act controller.Create(testItem); ViewResult indexView = new ItemsController().Index() as ViewResult; var collection = indexView.ViewData.Model as IEnumerable <Item>; // Assert Assert.Contains <Item>(testItem, collection); }
public void ItemsController_AddsItemToIndexModelData_Collection() { // Arrange ItemsController controller = new ItemsController(); Item testItem = new Item(); testItem.Description = "test item"; // Act controller.Create(testItem); ViewResult indexView = new ItemsController().Index() as ViewResult; var collection = indexView.ViewData.Model as List <Item>; // Assert CollectionAssert.Contains(collection, testItem); }
public async Task ItemsController_CreateNoItem() { // Arrange ItemModel item = null; var mockRepo = new Mock <IItemsBLL>(); var httpServiceMock = new Mock <IHttpServices>(); mockRepo.Setup(x => x.CreateItem(It.IsAny <ItemModel>())) .ReturnsAsync(false); var controller = new ItemsController(mockRepo.Object, httpServiceMock.Object); // Act var result = await controller.Create(item); // Assert Assert.Equal(item, result.Value); }
public async Task Post_Create_Item_User_Not_Admin_Returns_Item_Not_Approved_And_ReturnsRedirectToActionResult() { //var username = "******"; //var identity = new GenericIdentity(username,""); //Arrange var httpContextMock = new Mock <HttpContextBase>(); var mockPrincipal = new Mock <IPrincipal>(); mockPrincipal.Setup(x => x.Identity.IsAuthenticated).Returns(true); mockPrincipal.Setup(x => x.IsInRole(It.IsAny <string>())).Returns(false); httpContextMock.Setup(m => m.User).Returns(mockPrincipal.Object); Item item = new Item { ID = 1, UserID = "john123", }; //Mock a file download var request = new Mock <HttpPostedFileBase>(); var postedfilesKeyCollection = new Mock <HttpFileCollectionBase>(); httpContextMock.SetupGet(x => x.Request.Files[It.IsAny <string>()]).Returns(request.Object); var repository = new Mock <IItemsRepository>(); repository.Setup(repo => repo.AddItem(item)) .Returns(Task.CompletedTask) .Verifiable(); var controller = new ItemsController(repository.Object) { ControllerContext = new ControllerContext { HttpContext = httpContextMock.Object } }; //Act var result = await controller.Create(item); //Assert var viewResult = Assert.IsType <RedirectToRouteResult>(result); Assert.False(item.Approved); repository.Verify(); }
public void testDb_CreateWorks_CreateInDB() { //arrange ItemsController controller = new ItemsController(db); Item testItem = new Item { ItemId = 1, Name = "Blender" }; //act controller.Create(testItem); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Item>; //assert CollectionAssert.Contains(collection, testItem); db.RemoveAll(); }