public ActionResult BuyWishlistItem(string wishlistid) { var accountId = HttpContext.Session.Get <long>(SessionHelper.SessionKeyAccountId); if (accountId == default) { return(RedirectToAction("Login", "Account", new { id = LoginHelper.BudgetApp })); } if (string.IsNullOrWhiteSpace(wishlistid)) { return(Json(new { status = false, message = "WishlistId is required." })); } if (!long.TryParse(wishlistid, out long wishlistIdValue)) { return(Json(new { status = false, message = "WishlistId is not a number." })); } try { WishlistRepository.BuyWishlistItem(wishlistIdValue, accountId, new DateTime(DateTime.Now.Year, 12, 25), DateTime.Now); } catch (Exception) { return(Json(new { status = false, message = "Could not buy item." })); } return(Json(new { status = true, message = "Bought Item!" })); }
public DashboardModel(long accountId) { SetBaseViewModel(accountId); FirstColumn = new List <ListTable>(); SecondColumn = new List <ListTable>(); FirstColumn.Add(new ListTable(accountId, true)); var sharedAccountIds = WishlistRepository.GetSharedAccountIds(accountId); foreach (var sharedAccountId in sharedAccountIds) { if (FirstColumn.Sum(c => c.TableItems.Count) > SecondColumn.Sum(c => c.TableItems.Count)) { SecondColumn.Add(new ListTable(sharedAccountId, false)); } else { FirstColumn.Add(new ListTable(sharedAccountId, false)); } } //Change this to next holiday //Currently set to Christmas as default DaysTillNextHoliday = GetDaysTill(new DateTime(DateTime.Today.Year, 12, 25)); NextHoliday = "Christmas"; }
public ActionResult SaveWishlistItem(string name, string description, string link) { var accountId = HttpContext.Session.Get <long>(SessionHelper.SessionKeyAccountId); if (accountId == default) { return(RedirectToAction("Login", "Account", new { id = LoginHelper.BudgetApp })); } if (string.IsNullOrWhiteSpace(name)) { return(Json(new { status = false, message = "Name is required." })); } if (string.IsNullOrWhiteSpace(description)) { description = null; } if (string.IsNullOrWhiteSpace(link)) { link = null; } if (WishlistRepository.WishlistItemExists(accountId, name)) { return(Json(new { status = false, message = $"Item already exists with name {name}." })); } WishlistRepository.AddWishlistItem(accountId, name, description, link); return(Json(new { status = true, message = "Wishlist Item Added!" })); }
public YourListViewModel(long accountId) { WishList = WishlistRepository.GetWishlist(accountId); ColumnNames = new List <string> { "Name", "Description" }; SetBaseViewModel(accountId); }
static void Main(string[] args) { WishlistRepository obj = new WishlistRepository(); List <WishListModel> result = obj.SelectAll(); foreach (WishListModel item in result) { Console.WriteLine(JsonConvert.SerializeObject(item)); } }
public async Task GetAsyncTest_Passes() { //arrange _sut = new WishlistRepository(_access.Object, _mapper.Object); //act //var result = await _sut.GetAsync(It.IsAny<int>()); var result = await _sut.GetAsync(1); //assert Assert.IsNull(result); _access.Verify(m => m.SelectWithIdAsync(It.IsAny <int>()), Times.Once); }
public async Task WishlistRepository_GetWishlist_ReturnList() { // arrange const string username = "******"; const int userId = 1; using var contextFactory = new TestLooseLeafContextFactory(); List <DataAccess.Wishlist> wishlists = new List <DataAccess.Wishlist>() { new DataAccess.Wishlist() { UserId = userId, BookId = 1 }, new DataAccess.Wishlist() { UserId = userId, BookId = 2 }, new DataAccess.Wishlist() { UserId = userId, BookId = 3 } }; using (LooseLeafContext addContext = contextFactory.CreateContext()) { await contextFactory.CreateUser(addContext, username); await contextFactory.CreateBook(addContext, "Book 1", "Author 1"); await contextFactory.CreateBook(addContext, "Book 2", "Author 2"); await contextFactory.CreateBook(addContext, "Book 3", "Author 3"); await addContext.SaveChangesAsync(); await addContext.Wishlists.AddRangeAsync(wishlists); await addContext.SaveChangesAsync(); } using LooseLeafContext context = contextFactory.CreateContext(); IWishlistRepository wishlistRepository = new WishlistRepository(context); // act var books = await wishlistRepository.GetUserWishlist(userId); // assert Assert.Equal(wishlists.Count, books.Count()); }
public async Task DeleteWithIdAsyncTest_ValidId_HappyPath() { //arrange _access.WithDeleteWithIdResult(true); _sut = new WishlistRepository(_access.Object, _mapper.Object); //act var result = await _sut.DeleteAsync(WishlistBookTestUtils.GenerateValidWishlistBook().Id); //assert Assert.IsTrue(result); _access.Verify(m => m.DeleteWithIdAsync(It.IsAny <int>()), Times.Once); }
public async Task DeleteAsyncTest_NullWishlistBook_ThrowsNullReferenceException() { //arrange _access.WithDeleteWithIdResult(true); _sut = new WishlistRepository(_access.Object, _mapper.Object); //act var result = await _sut.DeleteAsync(null); //assert Assert.IsFalse(result); _access.Verify(m => m.DeleteOneAsync(It.IsAny <WishlistMap>()), Times.Never); }
public SharedListsViewModel(long accountId) { SharedWishLists = new List <SharedWishList>(); ColumnNames = new List <string> { "Name", "Description" }; var sharedAccountIds = WishlistRepository.GetSharedAccountIds(accountId); foreach (var sharedAccountId in sharedAccountIds) { SharedWishLists.Add(new SharedWishList(sharedAccountId)); } SetBaseViewModel(accountId); }
public async Task InsertOneAsyncTest_NullWishlistBookMap_ThrowsNullReferenceException() { //arrange _mapper.WithMap(null); _access.WithInsertResult(true); _sut = new WishlistRepository(_access.Object, _mapper.Object); //act var result = await _sut.InsertAsync(WishlistBookTestUtils.GenerateInvalidWishlistBook()); //assert Assert.IsFalse(result); _access.Verify(m => m.InsertOneAsync(It.IsAny <WishlistMap>()), Times.Never); }
public async Task InsertOneAsyncTest_ValidWishlistBook_Passes() { //arrange _mapper.WithMap(WishlistMapTestUtils.GenerateValidWishlistBookMap()); _access.WithInsertResult(true); _sut = new WishlistRepository(_access.Object, _mapper.Object); //act var result = await _sut.InsertAsync(WishlistBookTestUtils.GenerateValidWishlistBook()); //assert Assert.IsTrue(result); _access.Verify(m => m.InsertOneAsync(It.IsAny <WishlistMap>()), Times.Once); }
public static void Main() { WindowFormsFactory _formsFactory = new WindowFormsFactory(); ReadRepository _readRepo = new ReadRepository(); TBRRepository _tbrRepo = new TBRRepository(); OwnedRepository _ownedRepo = new OwnedRepository(); LibraryRepository _libraryRepo = new LibraryRepository(); WishlistRepository _wishlistRepo = new WishlistRepository(); MainFormController mainController = new MainFormController(_formsFactory, _readRepo, _tbrRepo, _ownedRepo, _libraryRepo, _wishlistRepo); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new BookNook.PresentationLayer.frmMainWindow(mainController)); }
public ListTable(long accountId, bool yourAccount) { if (yourAccount) { TableName = "Your Account"; TableActionLink = "YourList"; TableControllerLink = "List"; TableItems = WishlistRepository.GetWishlist(accountId).Select(i => i.Name).ToList(); } else { TableName = $"{AccountRepository.GetAccount(accountId).Name}'s List"; TableActionLink = "SharedLists"; TableControllerLink = "List"; TableItems = WishlistRepository.GetWishlist(accountId).Where(i => !i.IsBought).Select(i => i.Name).ToList(); } }
public async Task WishlistRepository_AddBookToUserWishlist() { // arrange //Constants to compare user and book with test results. const string username = "******"; const string bookName = "Test Book"; const string authorName = "The Author"; long isbn; const int userId = 1; const int bookId = 1; using var contextFactory = new TestLooseLeafContextFactory(); // Add in foreign key / required database data. Wishlist requires a user and a book type to exist in the database. using (LooseLeafContext arrangeContext = contextFactory.CreateContext()) { await contextFactory.CreateUser(arrangeContext, username); isbn = await contextFactory.CreateBook(arrangeContext, bookName, authorName); await arrangeContext.SaveChangesAsync(); } // act using (LooseLeafContext actContext = contextFactory.CreateContext()) { // Create Repository IWishlistRepository wishlistRepository = new WishlistRepository(actContext); // Test repository method await wishlistRepository.AddBookToUserWishlist(userId, bookId); await actContext.SaveChangesAsync(); } // assert // Create a new context to ensure that data was saved to database. using LooseLeafContext assertContext = contextFactory.CreateContext(); var wishlist = await assertContext.Wishlists.Include(w => w.User).Include(w => w.Book).SingleAsync(); // assert that the book and user are the same as one added to the wishlist. Assert.Equal(username, wishlist.User.Username); Assert.Equal(bookName, wishlist.Book.Title); Assert.Equal(authorName, wishlist.Book.Author); }
public async Task DeleteAsyncTest_NegativeIdWishlistBook_ThrowsException() { //arrange var book = WishlistBookTestUtils.GenerateValidWishlistBook(); book.Id = -4; _access.WithDeleteWithIdResult(true); _sut = new WishlistRepository(_access.Object, _mapper.Object); //act var result = await _sut.DeleteAsync(book); //assert Assert.IsFalse(result); _access.Verify(m => m.DeleteWithIdAsync(It.IsAny <int>()), Times.Never); }
public async Task WishlistRepository_RemoveBookFromUserWishlist() { // arrange const string username = "******"; const string bookName = "Test Book"; const string authorName = "The Author"; long isbn; int originalWishlistCount; const int userId = 1; const int bookId = 1; using var contextFactory = new TestLooseLeafContextFactory(); using (LooseLeafContext arrangeContext = contextFactory.CreateContext()) { await contextFactory.CreateUser(arrangeContext, username); isbn = await contextFactory.CreateBook(arrangeContext, bookName, authorName); await arrangeContext.Wishlists.AddAsync(new DataAccess.Wishlist() { UserId = 1, BookId = 1 }); await arrangeContext.SaveChangesAsync(); } // act using (LooseLeafContext actContext = contextFactory.CreateContext()) { IWishlistRepository wishlistRepository = new WishlistRepository(actContext); originalWishlistCount = actContext.Wishlists.Count(); await wishlistRepository.RemoveBookFromUserWishlist(userId, bookId); await actContext.SaveChangesAsync(); } // assert using LooseLeafContext assertContext = contextFactory.CreateContext(); Assert.Equal(0, assertContext.Wishlists.Count()); Assert.Equal(1, originalWishlistCount); }
public void TearDown() { _sut = null; _mapper = null; _access = null; }
public SharedWishList(long sharedAccountId) { Name = AccountRepository.GetAccount(sharedAccountId).Name; WishList = WishlistRepository.GetSpentWishlist(sharedAccountId); }
public WishListController() { _repository = new WishlistRepository(); }
public WishlistController(IRepository <WishList> repository, WishlistRepository wishlistRepository) { _repo = repository; repo = wishlistRepository; }