public void SaveShouldSetErrorMessageToNull()
        {
            // Arrange
            IUser         fakeUser      = new FakeUser(new felhasznalo(), new BindingList <felhasznalo>(), "testError");
            IUserRepo     fakeUserRepo  = new FakeUserRepo();
            UserPresenter userPresenter = new UserPresenter(fakeUser, fakeUserRepo);

            // Act
            userPresenter.Save(new felhasznalo());

            // Assert
            Assert.IsNull(fakeUser.errorMsg);
        }
        public void GivenTheUserExistsButTheRepoCantUpdateIt_WhenWeSaveTheUser_ThenTheErrorMessageFieldShouldBeSetToUpdateError()
        {
            // Arrange
            FakeUser      fakeUser      = new FakeUser(new felhasznalo(), new BindingList <felhasznalo>(), "testError");
            FakeUserRepo  fakeUserRepo  = new FakeUserRepo(existsResult: true, shouldThrowExceptionOnUpdate: true);
            UserPresenter userPresenter = new UserPresenter(fakeUser, fakeUserRepo);

            // Act
            userPresenter.Save(new felhasznalo());

            // Assert
            Assert.AreEqual(FakeUserRepo.UPDATE_ERROR_MESSAGE, fakeUser.errorMsg);
        }
        public void GivenTheUserExistsInTheRepo_WhenWeSaveTheUser_ThenWeShouldUpdateTheUser()
        {
            // Arrange
            FakeUser      fakeUser      = new FakeUser(new felhasznalo(), new BindingList <felhasznalo>(), "testError");
            FakeUserRepo  fakeUserRepo  = new FakeUserRepo(existsResult: true);
            UserPresenter userPresenter = new UserPresenter(fakeUser, fakeUserRepo);

            // Act
            userPresenter.Save(new felhasznalo());

            // Assert
            Assert.IsTrue(fakeUserRepo.wasUpdateCalled);
        }
Beispiel #4
0
        public void SignUpTest()
        {
            // arrange
            FakeUserRepo     userRepo       = new FakeUserRepo();
            FakeThreadRepo   threadRepo     = new FakeThreadRepo();
            MyBlogController blogController = new MyBlogController(userRepo, threadRepo);

            const string username          = "******";
            const string password          = "******";
            const string confirmedPassword = password;

            // act
            // blogController.SignUpRedirect(username, password, confirmedPassword);
            // NULL ERROR WHEN A METHOD HAS TEMPDATA : NEEDS A MOCK SESSION OBJECT?!?

            // assert
            int    repoCount        = userRepo.GetUsers().Count;
            string usernameFromRepo = userRepo.GetUsers()[repoCount - 1].Name;

            Assert.Equal(username, usernameFromRepo); // gets most recently added user
        }
Beispiel #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);
        }