public BookController() { _bookService = new BookService(); _wishModel = new WishListViewModel(); _wishListService = new WishListService(); _myModel = new ExpandoObject(); }
public IActionResult TermsAndConditions(string searchString) { var user = WishListService.GetUser(this.HttpContext); var userId = user.UserId; var listModel = new WishListViewModel { ListItems = _wishListService.GetWishListItems(userId), }; var books = _bookService.GetAllBooks(); if (!String.IsNullOrEmpty(searchString)) { var booklist = _bookService.GetSearchBooks(searchString); if (booklist.Count == 0) { return(View("NoResults")); } _myModel.Book = booklist; _myModel.Account = listModel; return(View("Index", _myModel)); } return(View()); }
public IActionResult SaleNewest(string searchString) { var user = WishListService.GetUser(this.HttpContext); var userId = user.UserId; var _wishModel = _wishListService.GetWishListItems(userId); var books = _bookService.GetAllBooks(); if (!String.IsNullOrEmpty(searchString)) { var bookList = _bookService.GetSearchBooks(searchString); if (bookList.Count == 0) { return(View("NoResults")); } _myModel.Book = bookList; _myModel.Account = _wishModel; return(View("Index", _myModel)); } var orderedBooks = _bookService.GetBooksOnSaleNewest(); _myModel.Book = orderedBooks; _myModel.Account = _wishModel; return(View("Sale", _myModel)); }
public WishListController() { _wishListService = new WishListService(); _bookService = new BookService(); _db = new DataContext(); _myModel = new ExpandoObject(); }
public IActionResult Top10(string searchString) { var user = WishListService.GetUser(this.HttpContext); var userId = user.UserId; var _wishModel = _wishListService.GetWishListItems(userId); if (!String.IsNullOrEmpty(searchString)) { var bookList = _bookService.GetSearchBooks(searchString); if (bookList.Count == 0) { return(View("NoResults")); } _myModel.Book = bookList; _myModel.Account = _wishModel; return(View("Index", _myModel)); } var top10 = _bookService.GetTop10(); if (top10.Count == 0) { return(View("NotFound")); } _myModel.Book = top10; _myModel.Account = _wishModel; return(View(_myModel)); }
public void GetUserWishListTest() { // Arrange var user = new UserProfile { Id = "1" }; var list = GetTestCollection(); var expected = list.First(i => i.UserId == user.Id); var repository = new Mock <IRepository <WishListItem> >(); repository.Setup(r => r.Get(i => i.UserId == expected.Id, null, "")).Returns(list.Where(l => l.UserId == expected.Id)); var principal = new Mock <ClaimsPrincipal>(); principal.Setup(b => b.Identity.IsAuthenticated).Returns(true); principal.Setup(b => b.FindFirst(It.IsAny <string>())).Returns(new Claim(ClaimTypes.NameIdentifier, "1")); var mapper = new Mock <IMapper>(); var svc = new WishListService(repository.Object, mapper.Object); // Act svc.GetUserWishList(principal.Object); // Assert repository.Verify(r => r.Get(It.IsAny <Expression <Func <WishListItem, bool> > >(), null, ""), Times.Once()); }
public IActionResult Details(string title, string searchString) { var user = WishListService.GetUser(this.HttpContext); var userId = user.UserId; var _wishModel = _wishListService.GetWishListItems(userId); var books = _bookService.GetAllBooks(); if (!String.IsNullOrEmpty(searchString)) { var bookList = _bookService.GetSearchBooks(searchString); if (bookList.Count == 0) { return(View("NoResults")); } _myModel.Book = bookList; _myModel.Account = _wishModel; return(View("Index", _myModel)); } _myModel.Book = _bookService.GetBookByTitle(title); _myModel.Reviews = _bookService.GetBookReviews(title); _myModel.Account = _wishModel; return(View(_myModel)); }
public IActionResult Index(string searchString) { var user = WishListService.GetUser(this.HttpContext); var userId = user.UserId; var listModel = new WishListViewModel { ListItems = _wishListService.GetWishListItems(userId), }; if (String.IsNullOrEmpty(searchString)) { var newestBooks = _bookService.GetBooksBoughtOrder(); _myModel.Book = newestBooks; _myModel.Account = listModel; return(View(_myModel)); } var booklist = _bookService.GetSearchBooks(searchString); if (booklist.Count == 0) { return(View("NoResults")); } _myModel.Book = booklist; _myModel.Account = listModel; return(View(_myModel)); }
public void AddToWishListTest() { // Arrange var expected = new WishListItemDto { Id = "1", BookId = "1", Book = new Book() { Id = "1", Title = "Stephen", Description = "King" }, UserId = "1", User = new UserProfile() { Id = "1", FirstName = "Oleksii", LastName = "Rudenko" }, Note = "Best book ever" }; var repository = new Mock <IRepository <WishListItem> >(); repository.Setup(r => r.Get(expected.Id)) .Returns(new WishListItem { Id = "1", BookId = "1", Book = new Book() { Id = "1", Title = "Stephen", Description = "King" }, UserId = "1", User = new UserProfile() { Id = "1", FirstName = "Oleksii", LastName = "Rudenko" }, Note = "Best book ever" }); var mapper = new Mock <IMapper>(); mapper.Setup(m => m.Map <WishListItemDto, WishListItem>(It.IsAny <WishListItemDto>())).Returns(new WishListItem()); var svc = new WishListService(repository.Object, mapper.Object); // Act svc.AddToWishList(expected); // Assert mapper.Verify(m => m.Map <WishListItemDto, WishListItem>(It.IsAny <WishListItemDto>()), Times.Once()); repository.Verify(r => r.Create(It.IsAny <WishListItem>()), Times.Once()); repository.Verify(r => r.Save(), Times.Once()); }
public IActionResult RemoveFromWishList(int inventoryId) { if (WishListService.RemoveInventory(inventoryId, User, _db)) { return(Ok()); } return(BadRequest()); }
public IActionResult AddToWishList(int inventoryId) { if (WishListService.AddInventory(inventoryId, User, _db)) { return(Ok()); } return(BadRequest()); }
public void ShouldGetAListofwishlists() { WishListService wishListService = new WishListService(); var items = wishListService.GetAllWishLists(); Assert.AreEqual(items.Count,0); Console.WriteLine(items.Count.ToString()); }
public IActionResult DecreaseAmount(int inventoryId) { if (WishListService.DecreaseAmountInventory(inventoryId, User, _db)) { return(Ok()); } return(BadRequest()); }
public IActionResult WishList() { WishList list = WishListService.GetWishList(User, _db); if (list == null) { return(View(null)); } return(View(list)); }
public void Create_WhenWishIsEmpty_ThenThrowValidExeption() { // Arrange var wish = new WishDto(); var service = new WishListService(_unitOfWorkFake, _mapper, _validator); // Act - Assert Assert.Throws <ValidationException>(() => service.Create(wish)); }
public ShoppingCartController(IAccountService IAccountService) { _cartService = new CartService(); _bookService = new BookService(); _accountService = new AccountService(); _wishListService = new WishListService(); _IAccountService = IAccountService; _myModel = new ExpandoObject(); _db = new DataContext(); }
public IActionResult RemoveFromWishList(int bookId) { var bookAdded = _bookService.GetBookById(bookId); var user = WishListService.GetUser(this.HttpContext); _wishListService.RemoveFromWishList(bookAdded, user); string referer = Request.Headers["Referer"].ToString(); return(Redirect(referer)); }
public void Update_WhenUpdateWish_ThenInvokeUpdateByRepository() { // Arrange var service = new WishListService(_unitOfWorkFake, _mapper, _alwaysValidValidator); // Act service.Update(Guid.NewGuid(), new WishDto()); // Assert A.CallTo(() => _unitOfWorkFake.WishListRepository.Update(A <Wish> ._)).MustHaveHappened(); }
public void Delete_WhenDeleteWish_ThenInvokeDeleteByRepository() { // Arrange var wishId = Guid.NewGuid(); var service = new WishListService(_unitOfWorkFake, _mapper, _validator); service.Delete(wishId); // Act - Assert A.CallTo(() => _unitOfWorkFake.WishListRepository.Delete(wishId)).MustHaveHappened(); }
public void Find_WhenFindUnknownWish_ThenReturnEmpty() { // Arrange var wish = new WishDto(); var service = new WishListService(_unitOfWorkFake, _mapper, _validator); // Act var result = service.Find(string.Empty); // Assert Assert.IsEmpty(result); }
public void Add_UserIdAndItemId_ThrowsExcpetion() { // ARRANGE // var wishlistRep = Substitute.For <IWishListRepository>(); wishlistRep.GetById(1).Returns(CreateWishlist(1)); wishlistRep.Add(1, 1) .Returns(x => { throw new DuplicateSqlPrimaryException("message"); }); var wishlistService = new WishListService(wishlistRep); // ASSERT // Assert.Throws <DuplicateSqlPrimaryException>(() => wishlistService.Add(1, 1)); }
public async Task Should_InvokeWishListRepositoryDeleteAsync_Once() { var wishList = new WishList(); wishList.AddItem(1, It.IsAny <decimal>(), "€", It.IsAny <int>()); wishList.AddItem(2, It.IsAny <decimal>(), "€", It.IsAny <int>()); _mockWishListRepo.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync(wishList); var wishListService = new WishListService(_mockWishListRepo.Object, null); await wishListService.DeleteWishListAsync(It.IsAny <int>()); _mockWishListRepo.Verify(x => x.DeleteAsync(It.IsAny <WishList>()), Times.Once); }
public void Delete_SingleNumber_ReturnsIsDeleted(bool isDeletedFromRepo) { // ARRANGE // var wishlistRep = Substitute.For <IWishListRepository>(); wishlistRep.Delete(1).Returns(isDeletedFromRepo); var wishlistService = new WishListService(wishlistRep); // ACT // var output = wishlistService.Delete(1); // ASSERT // Assert.AreEqual(isDeletedFromRepo, output); }
public void GetById_SingleNumber_ReturnsSingleOutputDtoQueryWishlist() { // ARRANGE // var wishlistRep = Substitute.For <IWishListRepository>(); wishlistRep.GetById(1).Returns(CreateWishlist(1)); var wishlistService = new WishListService(wishlistRep); var expected = CreateOutputDtoQueryWishlist(1); // ACT // var output = wishlistService.GetById(1); // ASSERT // Assert.AreEqual(expected, output); }
public IActionResult GenerateOrderWishList([Bind("TransactionInfoId , Street , PostalCode , City , IBAN , Email")] OrderTransactionViewModel orderTransactionViewModel) { if (ModelState.IsValid) { ShoppingCart shoppingCart = ShoppingCartService.ShoppingCartWishList(User, _db); if (shoppingCart.ShoppingCartItems.Count > 0) { if (OrderService.OrderShoppingCart(shoppingCart, orderTransactionViewModel, _db, User)) { OrderService.SendConfirmEmail(shoppingCart, orderTransactionViewModel).Wait(); WishListService.RemoveWishList(User, _db); return(Redirect("/")); } } } return(BadRequest("Something went wrong while generating your order , we are very sorry for this.")); }
public IActionResult Genre(string genre, string searchString) { var user = WishListService.GetUser(this.HttpContext); var userId = user.UserId; var _wishModel = _wishListService.GetWishListItems(userId); if (!String.IsNullOrEmpty(searchString)) { var bookList = _bookService.GetSearchBooks(searchString); if (bookList.Count == 0) { return(View("NoResults")); } _myModel.Book = bookList; _myModel.Account = _wishModel; return(View("Index", _myModel)); } var books = _bookService.GetAllBooks(); if (String.IsNullOrEmpty(genre)) { _myModel.Book = books; _myModel.Account = _wishModel; return(View(_myModel)); } else { var genrelist = _bookService.GetBooksByGenre(genre); if (genrelist.Count == 0) { return(View("NotFound")); } _myModel.Book = genrelist; _myModel.Account = _wishModel; return(View(_myModel)); } }
public void InitializeClass() { _wishRepositoryMock = new Mock <IRepository <Wish> >(); _bookRepositoryMock = new Mock <IRepository <Book> >(); _userResolverServiceMock = new Mock <IUserResolverService>(); _paginationServiceMock = new Mock <IPaginationService>(); _emailSenderServiceMock = new Mock <IEmailSenderService>(); _notificationServiceMock = new Mock <INotificationsService>(); _service = new WishListService( _userResolverServiceMock.Object, _paginationServiceMock.Object, _emailSenderServiceMock.Object, _notificationServiceMock.Object, _wishRepositoryMock.Object, _bookRepositoryMock.Object); MockData(); }
public void Get_WhenIdIsPassed_ThenReturnWishWithThisId() { // Arrange var wishId = Guid.NewGuid(); A.CallTo(() => _unitOfWorkFake.WishListRepository.Get(wishId)) .Returns(new Wish { Id = wishId }); var service = new WishListService(_unitOfWorkFake, _mapper, _alwaysValidValidator); // Act var returnedWishList = service.Get(wishId); // Assert Assert.AreEqual(returnedWishList.Id, wishId); }
/// <summary> /// 获得用户分页的收藏列表 /// </summary> /// <param name="customerSysNo"></param> /// <param name="startIndex"></param> /// <returns></returns> public static string GetCustomerWishListProducts(int customerSysNo, int startIndex) { string wishListHTML = String.Empty; int pageCount = int.Parse(YoeJoyConfig.WishListPagedCount); List <WishListModule> wishList = WishListService.GetCustomerWishList(customerSysNo, startIndex, pageCount); if (wishList != null) { StringBuilder strb = new StringBuilder(); ///TODO: Add logic to impelemnt wishlist UI. wishListHTML = strb.ToString(); } return(wishListHTML); }
public void Find_WhenFindWish_ThenReturnNeeded() { // Arrange var wishDto = new WishDto(); var wish = new Wish(); var service = new WishListService(_unitOfWorkFake, _mapper, _validator); A.CallTo(() => _unitOfWorkFake.WishListRepository.Find(A <Func <Wish, bool> > ._)) .Returns(new List <Wish> { wish }); // Act var returnedWish = service.Find(wish.Id.ToString()); // Assert Assert.AreEqual(wishDto.Id, returnedWish[0].Id); }
public void GetAll_WhenRequestAllWishes_ThenReturnAllSavedWishes() { // Arrange var wishLists = new List <Wish>() { new Wish { }, new Wish { } }; A.CallTo(() => _unitOfWorkFake.WishListRepository.Get()).Returns(wishLists); var service = new WishListService(_unitOfWorkFake, _mapper, _alwaysValidValidator); // Act var returnedWishLists = service.GetAll(); // Assert Assert.AreEqual(returnedWishLists.Count, wishLists.Count); }