public void GetThreads() { // arrange FakeThreadRepo threadRepo = new FakeThreadRepo(); const string bio = "hello there friends"; const string name = "testThread2"; const string creatorName = "bob"; const string category = "games and music"; int id = ObjectIDBuilder.GetThreadID(); Thread thread1 = new Thread() { ThreadID = id, Name = name, CreatorName = creatorName, Bio = bio, Category = category }; threadRepo.AddThreadtoRepo(thread1); // add thread // act Thread foundThread = threadRepo.GetThreadById(id); // found thread with id Thread foundThread2 = threadRepo.GetThreadByName(name); // found thread with name // assert (test if the thread was found with id) Assert.Equal(thread1.Name, foundThread.Name); Assert.Equal(thread1.Category, foundThread.Category); Assert.Equal(thread1.CreatorName, foundThread.CreatorName); // assert (test if the thread was found with name) Assert.Equal(thread1.Name, foundThread2.Name); Assert.Equal(thread1.Category, foundThread2.Category); Assert.Equal(thread1.CreatorName, foundThread2.CreatorName); }
public void RemoveThreads() { // arrange FakeThreadRepo threadRepo = new FakeThreadRepo(); const string bio = "hello there friends"; const string name = "testThread"; const string creatorName = "bob"; const string category = "games and music"; int id = ObjectIDBuilder.GetThreadID(); Thread thread1 = new Thread() { ThreadID = id, Name = name, CreatorName = creatorName, Bio = bio, Category = category }; threadRepo.AddThreadtoRepo(thread1); // add thread // act Thread removedThread = threadRepo.RemoveThreadfromRepo(id); // remove thread // assert Assert.Equal(thread1.Name, removedThread.Name); Assert.Equal(thread1.Category, removedThread.Category); Assert.Equal(thread1.CreatorName, removedThread.CreatorName); }
public void AddRemoveUser() { // arrange FakeUserRepo userRepo = new FakeUserRepo(); int id = ObjectIDBuilder.GetUserID(); const string username = "******"; const string password = "******"; const string gender = "male"; DateTime dateJoinedD = DateTime.Now; Thread ownedThread = null; User newUser = new User() { UserID = id, Username = username, Password = password, Gender = gender, DateJoined = dateJoinedD, OwnedThread = ownedThread }; // act userRepo.AddUsertoRepo(newUser); User removedUser = userRepo.RemoveUserfromRepo(id); // assert Assert.Equal(newUser.Username, removedUser.Username); Assert.Equal(newUser.DateJoined, removedUser.DateJoined); Assert.Equal(newUser.UserID, removedUser.UserID); }
public RedirectToActionResult BuildThread(string threadName, string threadCategory, string bio, string userId) { // validate input (not empty AND trim trailing white space) // search thread repo and determine if the threadname is in use // Build a thread object using the input parameters // Get reference to user by id // Set the user's owned thread property // Add thread to threadRepo // make a temp data entry containing the userId // redirect to ReloadBlogDashboard action method var trimmedThreadname = ""; var trimmedBio = ""; if (threadName != null && threadCategory != null && bio != null) { trimmedThreadname = threadName.Trim(); trimmedBio = bio.Trim(); } else { // create a tempdata entry that contains the message to be returned in the getting started view // return getting started view because the inputted data is empty TempData["ThreadCreationMessage"] = "No fields can be left blank"; TempData["userId"] = userId; return(RedirectToAction("GettingStarted")); } if (!(threadRepo.GetThreadnameEligibility(trimmedThreadname) == true)) { TempData["ThreadCreationMessage"] = "Unforunately, that thread name is already taken :("; TempData["userId"] = userId; return(RedirectToAction("GettingStarted")); } int USERID = int.Parse(userId); User user = userRepo.GetUserById(USERID); Thread newThread = new Thread() { ThreadID = ObjectIDBuilder.GetThreadID(), Name = threadName, Bio = bio, Category = threadCategory, CreatorName = user.Username }; user.OwnedThread = newThread; threadRepo.AddThreadtoRepo(newThread); TempData["userId"] = userId; return(RedirectToAction("ReloadBlogDashboard")); }
public RedirectToActionResult SignUpRedirect(string username, string password, string passwordConfirmation) { // validate username and password (not empty AND trim trailing white space) // search repo to see if username is already taken // check to make sure password and confirmed password fields match // build user object // add user to repo // redirect to myblogpanel // else show signup with an invalid username and password error var trimmedUsername = ""; var trimmedPassword = ""; var trimmedConfirmPassword = ""; if (username != null && password != null && passwordConfirmation != null) { trimmedUsername = username.Trim(); trimmedPassword = password.Trim(); trimmedConfirmPassword = passwordConfirmation.Trim(); } else { // create a tempdata entry that contains the message to be returned in the sign up view // return signup view because the password/username combo is empty TempData["SignUpMessage"] = "Password and/or username fields cannot be empty"; return(RedirectToAction("SignUp")); } if (userRepo.GetUsernameEligibility(trimmedUsername) == false) { TempData["SignUpMessage"] = "That username is taken :("; return(RedirectToAction("SignUp")); } if (trimmedPassword != trimmedConfirmPassword) { TempData["SignUpMessage"] = "Password and/or username fields cannot be empty"; return(RedirectToAction("SignUp")); } User newUser = new User() { UserID = ObjectIDBuilder.GetUserID(), Username = trimmedUsername, Password = trimmedConfirmPassword, DateJoined = DateTime.Now }; userRepo.AddUsertoRepo(newUser); TempData["validUsername"] = trimmedUsername; return(RedirectToAction("MyBlogDashboard")); }
public RedirectToActionResult AddPost(string postTitle, string postContent, string threadId, string userId) { // Build post object // Get thread by id // add post to thread // make a temp data entry containing the userId // redirect to ReloadBlogDashboard action method Post newPost = new Post() { PostID = ObjectIDBuilder.GetPostID(), Title = postTitle, Content = postContent, TimeStamp = DateTime.Now }; int THREADID = int.Parse(threadId); threadRepo.GetThreadById(THREADID).AddPostToThread(newPost); TempData["userId"] = userId; return(RedirectToAction("ReloadBlogDashboard")); }
public void AddThreads() { // arrange FakeThreadRepo threadRepo = new FakeThreadRepo(); const string bio = "hello there friends"; const string name = "testThread1"; const string creatorName = "bob"; const string category = "games and music"; int id = ObjectIDBuilder.GetThreadID(); Thread thread1 = new Thread() { ThreadID = id, Name = name, CreatorName = creatorName, Bio = bio, Category = category }; // act threadRepo.AddThreadtoRepo(thread1); // add thread List <Thread> threads = threadRepo.GetThreads(); // get thread Thread foundThread = null; // found thread foreach (Thread t in threads) { if (t == thread1) { foundThread = t; } } // Assert Assert.Equal(thread1.Name, foundThread.Name); Assert.Equal(thread1.Category, foundThread.Category); Assert.Equal(thread1.CreatorName, foundThread.CreatorName); }
public void SearchUsersAndThreads() { // arrange FakeThreadRepo threadRepo = new FakeThreadRepo(); FakeUserRepo userRepo = new FakeUserRepo(); int id = ObjectIDBuilder.GetUserID(); const string username = "******"; const string password = "******"; const string gender = "female"; DateTime dateJoinedD = DateTime.Now; Thread ownedThread = null; User newUser = new User() // user1 { UserID = id, Username = username, Password = password, Gender = gender, DateJoined = dateJoinedD, OwnedThread = ownedThread }; const string bio = "hello there friends"; const string name = "testThread3"; string creatorName = newUser.Username; const string category = "games and music"; int threadId = ObjectIDBuilder.GetThreadID(); Thread thread1 = new Thread() { ThreadID = id, Name = name, CreatorName = creatorName, Bio = bio, Category = category }; newUser.OwnedThread = thread1; int id2 = ObjectIDBuilder.GetUserID(); const string username2 = "robert"; const string password2 = "asdf"; const string gender2 = "male"; DateTime dateJoinedD2 = DateTime.Now; Thread ownedThread2 = null; User newUser2 = new User() // user2 { UserID = id2, Username = username2, Password = password2, Gender = gender2, DateJoined = dateJoinedD2, OwnedThread = ownedThread2 }; const string bio2 = "hello there friends"; const string name2 = "testThread4"; string creatorName2 = newUser2.Username; const string category2 = "games and music"; int threadId2 = ObjectIDBuilder.GetThreadID(); Thread thread2 = new Thread() { ThreadID = id2, Name = name2, CreatorName = creatorName2, Bio = bio2, Category = category2 }; newUser2.OwnedThread = thread2; threadRepo.AddThreadtoRepo(thread1); threadRepo.AddThreadtoRepo(thread2); userRepo.AddUsertoRepo(newUser); userRepo.AddUsertoRepo(newUser2); // act List <Thread> searchResult = userRepo.SearchForUsersAndThreads(name2); // search for thread by the name of the second thread object Thread parsedThread = null; foreach (Thread t in searchResult) { // get the search result out of the list structure and into a Thread variable if (t.Name == name2) { parsedThread = t; } } // assert Assert.Equal(thread2, parsedThread); Assert.Equal(name2, parsedThread.Name); }