public async Task AddProductToCustomerrWishlistAsync_ShouldReturnExistingProduct_WhenProductIsAlreadyInWishlist() { //Arrange string productId = "1bf0f365-fbdd-4e21-9786-da459d78dd1f"; _customerService.GetCustomerAsync(customerId).Returns(existingCustomer); var existingList = new List <WishListProduct>() { new WishListProduct() { ProductId = productId } }; _wishlistRepository.GetCustomerWishlistAsync(customerId).Returns(existingList); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var product = await sut.AddProductToCustomerrWishlistAsync(customerId, productId); //Assert Assert.NotNull(product); await _wishlistRepository.DidNotReceive().InsertWishlistProductAsync(Arg.Any <int>(), Arg.Any <WishListProduct>()); Assert.Equal(productId, product.ProductId); }
public async Task GetAll_Test() { // arrange var fakeUowProvider = A.Fake <IUnitOfWorkProvider>(); var fakeUow = A.Fake <IUnitOfWork>(); A.CallTo(() => fakeUowProvider.Get()).Returns(fakeUow); var fakeRepoProvider = A.Fake <IWishlistRepositoryProvider>(); var fakeRepo = A.Fake <IWishlistRepository>(); A.CallTo(() => fakeRepoProvider.Get(fakeUow)).Returns(fakeRepo); WishlistService service = new WishlistService(fakeUowProvider, fakeRepoProvider); List <WishlistItem> items = new List <WishlistItem> { new WishlistItem { Id = 1, Title = "test_item", Type = ItemType.Book } }; A.CallTo(() => fakeRepo.ReadAll()).Returns(items); // act var result = await service.GetAll(); // assert Assert.IsTrue(result.ToList().Count == 1); Assert.IsTrue(result.ToList()[0].Id == 1); Assert.IsTrue(result.ToList()[0].Title.Equals("test_item")); A.CallTo(() => fakeUow.Dispose()).MustHaveHappened(); }
//Helper private WishlistService CreateWishlistService() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new WishlistService(userId); return(service); }
public IActionResult Remove(string provider, string id) { WishlistService wishlistService = new WishlistService(this.serviceProvider); wishlistService.Remove(User.Identity as ClaimsIdentity, provider, id); return(Ok()); }
public void AddPartial(int id) { var addedItem = db.Toy.Single(t => t.ToysId == id); var Wishlist = WishlistService.GetWishlist(this.HttpContext); Wishlist.AddToWishlist(addedItem, id); }
public WebActionTestBase() { var options = new DbContextOptionsBuilder <DataContextTest>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; _context = new DataContextTest(options); _context.Database.EnsureCreated(); _userManager = new FakeUserManager(_context); //mock httpcontext _signInManager = new FakeSignInManager(_userManager); _courseService = new CourseService(_context); _studentService = new StudentService(_context); _enrollService = new EnrollService(_context); _facultyService = new FacultyService(_context); _wishlistService = new WishlistService(_context); _viewModelService = new ViewModelService(_courseService, _enrollService, _studentService, _facultyService, _wishlistService); _courseController = new CourseController(_userManager, null, _courseService, _studentService, _enrollService, _wishlistService, _viewModelService); _homeController = new HomeController(_userManager, null, _courseService, _studentService, _enrollService, _viewModelService); _authController = new AuthController(_signInManager); }
public async Task RemoveProductFromCustomerrWishlistAsync_ShouldCallRepository_WhenCustomerDoesExist() { //Arrange string productId = "3"; _customerService.GetCustomerAsync(customerId).Returns(existingCustomer); _wishlistRepository.DeleteWishlistProductAsync(customerId, productId).Returns(true); var wishlistProduct = new WishListProduct() { Id = 1, ProductId = productId, Image = "http://images.luizalabs.com/123.png", Price = "30.00", Title = "Product123" }; _productRest.GetProductByIdAsync(productId).Returns(wishlistProduct); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var result = await sut.RemoveProductFromCustomerrWishlistAsync(customerId, productId); //Assert Assert.True(result); _ = _wishlistRepository .Received(1) .DeleteWishlistProductAsync(customerId, productId); }
public async Task Add_Test() { // arrange var fakeUowProvider = A.Fake <IUnitOfWorkProvider>(); var fakeUow = A.Fake <IUnitOfWork>(); A.CallTo(() => fakeUowProvider.Get()).Returns(fakeUow); var fakeRepoProvider = A.Fake <IWishlistRepositoryProvider>(); var fakeRepo = A.Fake <IWishlistRepository>(); A.CallTo(() => fakeRepoProvider.Get(fakeUow)).Returns(fakeRepo); WishlistService service = new WishlistService(fakeUowProvider, fakeRepoProvider); WishlistItem item = new WishlistItem { Id = 1, Title = "test_item", Type = ItemType.Book }; // act await service.Add(item); // assert A.CallTo(() => fakeRepo.Create(item)).MustHaveHappened(); A.CallTo(() => fakeUow.Dispose()).MustHaveHappened(); }
//GET: WishList public ActionResult Index() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new WishlistService(userId); var model = service.Getwishlist(); return(View(model)); }
private void MW(string Email) { //associate shopping cart item with logged in user var wishlist = WishlistService.GetWishlist(this.HttpContext); wishlist.MigrateWishlist(Email); Session[WishlistService.WishlistSessionKey] = Email; }
public void ThrowArgumentOutOfRangeException_WhenInvokedWithIncorrectBookId() { var mapperMock = new Mock <IMapper>(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var wishlistService = new WishlistService(unitOfWorkMock.Object, mapperMock.Object); Assert.ThrowsException <ArgumentOutOfRangeException>(() => wishlistService.DeleteBookFromWishlist(-1, 1)); }
public void NotReturnNull_When_WishlistServiceCalled() { var unitOfWorkMock = new Mock <IUnitOfWork>(); var mapperMock = new Mock <IMapper>(); var wishlistService = new WishlistService(unitOfWorkMock.Object, mapperMock.Object); Assert.IsNotNull(wishlistService); }
public void RemoveFromWishlist(int id) { if (id != null) { var w = WishlistService.GetWishlist(this.HttpContext); string toyName = db.Wishlist.Single(t => t.WishlistId == id).Toy.ToysName; w.DeleteFromWishlist(id); } }
public void ThrowArgumentException_WhenInvokedWithIncorrectParams() { var mapperMock = new Mock <IMapper>(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var wishlistService = new WishlistService(unitOfWorkMock.Object, mapperMock.Object); Assert.ThrowsException <ArgumentOutOfRangeException>(() => wishlistService.GetUserWishlistBooks(-1)); }
public ActionResult AddToWishlist(int id) { var addedItem = db.Toy.Single(t => t.ToysId == id); var Wishlist = WishlistService.GetWishlist(this.HttpContext); Wishlist.AddToWishlist(addedItem, id); return(RedirectToAction("index")); }
public ActionResult Index() { var Wishlist = WishlistService.GetWishlist(this.HttpContext); var Model = new WishlistViewModel { Wishlist = Wishlist.GetToys() }; return(View(Model)); }
// Constructor: public AccountController(SignInManager <ApplicationUser> signInManager, UserManager <ApplicationUser> userManager, ISignUpService signUpService) { _signInManager = signInManager; _userManager = userManager; _signUpService = signUpService; _cartService = new CartService(); _reviewService = new ReviewService(); _bookService = new BookService(); _orderService = new OrderService(); _wishlistService = new WishlistService(); }
public APITestBase() : base() { _userManager = new FakeUserManager(_context); _signInManager = new FakeSignInManager(_userManager); _courseService = new CourseService(_context); _studentService = new StudentService(_context); _enrollService = new EnrollService(_context); _facultyService = new FacultyService(_context); _wishlistService = new WishlistService(_context); }
public async Task RemoveProductFromCustomerrWishlistAsync_ShouldReturnNull_WhenCustomerDoesNotExist() { //Arrange _customerService.GetCustomerAsync(customerId).Returns(nullReturn); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var result = await sut.RemoveProductFromCustomerrWishlistAsync(customerId, "1"); //Assert Assert.False(result); }
public async Task GetCustomerWishlistAsync_ShouldReturnNull_WhenCustomerDoesNotExist() { //Arrange _customerService.GetCustomerAsync(customerId).Returns(nullReturn); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var products = await sut.GetCustomerWishlistAsync(customerId); //Assert Assert.Null(products); }
//Constructor that initializes private variables. public AccountController(SignInManager <ApplicationUser> signInManager, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) { _signInManager = signInManager; _userManager = userManager; _roleManager = roleManager; _bookService = new BookService(); _userService = new UserService(); _cartService = new CartService(); _wishlistService = new WishlistService(); _orderService = new OrderService(); _obcService = new OrderBookConnectionService(); _ratingService = new RatingService(); }
public async Task Should_InvokeWishListRepositoryDeleteAsync_Once() { var wish = new Wishlist(); wish.AddItem(1); wish.AddItem(2); _mockWishlistRepo.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync(wish); var wishListService = new WishlistService(_mockWishlistRepo.Object, null); await wishListService.DeleteWishlistAsync(It.IsAny <int>()); _mockWishlistRepo.Verify(x => x.DeleteAsync(It.IsAny <Wishlist>()), Times.Once); }
public WishlistServiceTest() { this.wishRepo = new Mock <IDeletableEntityRepository <Wishlist> >(); this.gameRepo = new Mock <IDeletableEntityRepository <Game> >(); this.list = new List <Wishlist>(); this.service = new WishlistService(this.wishRepo.Object, this.gameRepo.Object); this.wishRepo.Setup(x => x.All()).Returns(this.list.AsQueryable()); this.wishRepo.Setup(x => x.AddAsync(It.IsAny <Wishlist>())).Callback( (Wishlist wish) => this.list.Add(wish)); this.wishRepo.Setup(x => x.Delete(It.IsAny <Wishlist>())).Callback( (Wishlist wish) => this.list.Remove(wish)); this.wishRepo.Setup(x => x.HardDelete(It.IsAny <Wishlist>())).Callback( (Wishlist wish) => this.list.Remove(wish)); var service = new WishlistService(this.wishRepo.Object, this.gameRepo.Object); }
public async void AddMovieToWishlist() { var options = CreateNewContextOptions(); using (var context = new MediaCollectionContext(options)) { var omdbClient = new OmdbClient(); var _service = new WishlistService(context, omdbClient); string imdbId = "tt1211837"; //Doctor Strange QualityType desiredQuality = QualityType.HD; Movie movie = await _service.AddMovie(imdbId, desiredQuality); Assert.Equal(movie.Title, "Doctor Strange"); Assert.Equal(movie.Year, 2016); } }
public ActionResult IndexR(int r) { try { var Wishlist = WishlistService.GetWishlist(this.HttpContext); RemoveFromWishlist(r); var Model = new WishlistViewModel { Wishlist = Wishlist.GetToys() }; return(View(Model)); } catch { return(RedirectToAction("Index")); } }
public async Task AddProductToCustomerrWishlistAsync_ShouldCallRepository_WhenCustomerDoesExist() { //Arrange string newProductId = "3"; string existingProductId = "4"; _customerService.GetCustomerAsync(customerId).Returns(existingCustomer); _wishlistRepository.InsertWishlistProductAsync(customerId, Arg.Any <WishListProduct>()).Returns(new WishListProduct()); var wishlistProduct = new WishListProduct() { ProductId = newProductId, Image = "http://images.luizalabs.com/123.png", Price = "30.00", Title = "Product123" }; _productRest.GetProductByIdAsync(newProductId).Returns(wishlistProduct); var existingList = new List <WishListProduct>() { new WishListProduct() { ProductId = existingProductId } }; _wishlistRepository.GetCustomerWishlistAsync(customerId).Returns(existingList); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var product = await sut.AddProductToCustomerrWishlistAsync(customerId, newProductId); //Assert Assert.NotNull(product); _ = _wishlistRepository.Received(1).InsertWishlistProductAsync( customerId, Arg.Is <WishListProduct>( x => x.ProductId == wishlistProduct.ProductId && x.Image == wishlistProduct.Image && x.Price == wishlistProduct.Price && x.Title == wishlistProduct.Title )); }
public async Task GetCustomerWishlistAsync_ShouldReturnList_WhenCustomerDoesExist() { //Arrange _customerService.GetCustomerAsync(customerId).Returns(existingCustomer); List <WishListProduct> list = new List <WishListProduct>(); list.Add(new WishListProduct()); _wishlistRepository.GetCustomerWishlistAsync(customerId).Returns(list); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var products = await sut.GetCustomerWishlistAsync(customerId); //Assert Assert.NotNull(products); Assert.Single(products); }
public async Task CreateWishlist_ExceptionInFileService_ReturnOperationFails() { //Arrange var fileServiceMock = new Mock <IFilesService>(); var exceptionMessage = "Directory name is not valid."; fileServiceMock .Setup(fileService => fileService.CreateDirectoryForWishlist("v....")) .Throws(new FileServiceException(exceptionMessage, new ArgumentException(exceptionMessage))); wishlistService = new WishlistService(DbContext, fileServiceMock.Object); //Act var operationResult = await wishlistService.CreateWishlist("TEST", UserId); //Assert Assert.AreEqual(OperationStatus.ERROR, operationResult.Status); }
public async Task DeleteById_Test() { // arrange var fakeUowProvider = A.Fake <IUnitOfWorkProvider>(); var fakeUow = A.Fake <IUnitOfWork>(); A.CallTo(() => fakeUowProvider.Get()).Returns(fakeUow); var fakeRepoProvider = A.Fake <IWishlistRepositoryProvider>(); var fakeRepo = A.Fake <IWishlistRepository>(); A.CallTo(() => fakeRepoProvider.Get(fakeUow)).Returns(fakeRepo); WishlistService service = new WishlistService(fakeUowProvider, fakeRepoProvider); // act await service.DeleteById(1); // assert A.CallTo(() => fakeRepo.DeleteById(1)).MustHaveHappened(); A.CallTo(() => fakeUow.Dispose()).MustHaveHappened(); }
public ActionResult IndexRA(int i, int r) { try { var addedItem = db.Toy.Single(t => t.ToysId == i); var cart = ShoppingCartService.GetCart(this.HttpContext); cart.AddToCart(addedItem); RemoveFromWishlist(r); var Wishlist = WishlistService.GetWishlist(this.HttpContext); var Model = new WishlistViewModel { Wishlist = Wishlist.GetToys() }; return(View(Model)); } catch { return(RedirectToAction("Index")); } }