Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }