public void AdminController_RemoveItem_Success() { Users user = new Users { Id = 1, UserName = "******" }; var cancel = new CancellationToken(); var adminRemoveModel = new AdminModel { ModelName = "modelName", }; var productService = new StoreProductService(_context); var userService = new UserService(_context); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var manager = new UserManager <Users>(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new AdminController(productService, manager, userService, null); var addItem = Controller.AddItem(adminModel); var getItemsBefore = productService.GetAll(); Assert.Single(getItemsBefore); var removeItem = Controller.RemoveItem(adminRemoveModel); var getItemsAfter = productService.GetAll(); Assert.Empty(getItemsAfter); Assert.Equal("Item Was Sucessfully Removed", removeItem.Value); }
public async void AddItemOk() { Item newitem = new Item() { Name = "Iphone 7", Category = "Телефоны", Price = 45000, Code = "111-222-333-444" }; var unitofworkMock = GetUnitOfWorkMock(); unitofworkMock.Setup(unit => unit.Items.CreateAsync(It.IsAny <Item>())); AdminController adminController = new AdminController( GetUserManagerMock <Customer>().Object, unitofworkMock.Object); AddItemModel model = new AddItemModel() { Category = newitem.Category, Price = newitem.Price, Code = newitem.Code, Name = newitem.Name }; //Act await adminController.AddItem(model); //Assert unitofworkMock.Verify(u => u.Items.CreateAsync(It.IsAny <Item>())); }
public void AddItem_ShouldRedirectToAdminPanel() { //Arange var adminController = new AdminController(this.itemServiceMock.Object, this.mappingServiceMock.Object, this.imageProviderMock.Object); var addItemViewModel = new AddItemViewModel(); //Act var redirectResult = adminController.AddItem(addItemViewModel) as RedirectResult; //Assert Assert.IsNotNull(redirectResult); Assert.AreEqual(ServerConstants.AdminPanelRedirectUrl, redirectResult.Url); }
public void AddItem_ShouldSetViewItemProperties_IfModelIsValid() { // Arrange var adminController = new AdminController(this.itemServiceMock.Object, this.mappingServiceMock.Object, this.imageProviderMock.Object); var viewModel = new AddItemViewModel(); // Act adminController.AddItem(viewModel); // Assert Assert.AreEqual(viewModel.IsDeleted, false); Assert.AreEqual(viewModel.Discount, 0); }
public void AdminController_UpdateItem_Success() { Users user = new Users { Id = 1, UserName = "******" }; var cancel = new CancellationToken(); var adminUpdateModel = new AdminModel { Availibility = 1, Price = 12, Discount = 0, Color = "Orange", ModelName = "modelName", SpecSpec = "Specification", SpecDesc = "Description" }; var productService = new StoreProductService(_context); var userService = new UserService(_context); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var manager = new UserManager <Users>(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new AdminController(productService, manager, userService, null); var addItem = Controller.AddItem(adminModel); var getItemsBefore = productService.GetAll(); Assert.Equal("itemColor", getItemsBefore.First().Color); var updateItem = Controller.UpdateItems(adminUpdateModel); var getItemsPost = productService.GetAll(); Assert.Single(getItemsPost); Assert.Equal("Orange", getItemsPost.First().Color); Assert.Equal(1, getItemsPost.First().Availability); Assert.Equal("Item Updated", updateItem.Value); }
public void AddItem_ShouldCallImageProviderToParseItemImage_IfModelIsValid() { // Arrange string imageStringBase64 = "asdfasdf"; byte[] array = new byte[5]; this.itemServiceMock.Setup(i => i.CheckUniqueItemCode(It.IsAny <string>())).Returns(true); this.imageProviderMock.Setup(i => i.ConvertByteArrayToImageString(It.IsAny <byte[]>())).Returns(imageStringBase64); this.imageProviderMock.Setup(i => i.ConvertFileToByteArray(It.IsAny <HttpPostedFileBase>())).Returns(array); var adminController = new AdminController(this.itemServiceMock.Object, this.mappingServiceMock.Object, this.imageProviderMock.Object); var viewModel = new AddItemViewModel(); // Act adminController.AddItem(viewModel); // Assert this.imageProviderMock.Verify(i => i.ConvertFileToByteArray(It.IsAny <HttpPostedFileBase>()), Times.Once); this.imageProviderMock.Verify(i => i.ConvertByteArrayToImageString(It.IsAny <byte[]>()), Times.Once); }
public async Task AddItem_Post_Test() { Mock <IFormFile> mockIFormFile = new Mock <IFormFile>(); mockIFormFile.Setup(x => x.FileName) .Returns(Guid.NewGuid().ToString()); mockIFormFile.Setup(x => x.CopyToAsync(It.IsAny <Stream>(), It.IsAny <CancellationToken>())); ItemModel model = new ItemModel() { categoryId = 1, price = 10, title = "title", description = "qweqe", image = mockIFormFile.Object }; var result = await controller.AddItem(model); var viewResult = Xunit.Assert.IsType <RedirectToActionResult>(result); Assert.AreEqual("GetItemsPage", viewResult.ActionName); _saveFileService.Verify(x => x.SaveFile(It.IsAny <IFormFile>(), It.IsAny <string>())); _itemService.Verify(x => x.AddItem(It.IsAny <Item>())); }
public void AdminController_AddItem_Success() { Users user = new Users { Id = 1, UserName = "******" }; var cancel = new CancellationToken(); var productService = new StoreProductService(_context); var userService = new UserService(_context); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var manager = new UserManager <Users>(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new AdminController(productService, manager, userService, null); var addItem = Controller.AddItem(adminModel); var getItems = productService.GetAll(); Assert.Single(getItems); Assert.Equal("itemColor", getItems.First().Color); Assert.Equal("Item added!", addItem.Value); }