示例#1
0
        public void PublishPageShouldFail(string username, string password, string title, string content)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            blog.LoginUser(new User(username)
            {
                Password = password
            });

            var userIsLoggedIn = blog.UserIsLoggedIn;

            //Check to see that user is really logged in
            Assert.That(userIsLoggedIn == true, "User should be logged in");

            //Instead of page, send in null
            Assert.Throws <IncorrectPageException>(() => blog.PublishPage(null), "The publish should not have been succesful");

            blog.LogoutUser(new User(username)
            {
                Password = password
            });

            userIsLoggedIn = blog.UserIsLoggedIn;

            //Check to see that user is really logged out
            Assert.That(userIsLoggedIn == false, "User should be logged in");

            //Publish page when user is not logged in
            Assert.That(blog.PublishPage(new Page {
                Title = title, Content = content
            }) == false, "The user is not logged in, publish should fail");
        }
示例#2
0
        public void IfUserIsNullShouldThrowException()
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            //TODO Change to custom exception
            Assert.Throws <IncorrectUserException>(() => blog.LoginUser(null), "Did not throw exception");
        }
示例#3
0
文件: BlogTest.cs 项目: kimsandin/TDD
        public void IfUserIsNullShouldThrowException()
        {
            //Act
            blog = new Blog(_authenticator = new MockAuthenticator());

            //Assert Cast exception if null
            Assert.Throws <NoUserNameGivenException>(() => blog.LoginUser(null), "Did not throw an exception");
        }
示例#4
0
        public void IfNoUserIsFoundInDbShouldThrowException(string username, string password)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            Assert.Throws <NoUserFoundInDbException>(() => blog.LoginUser(new User(username)
            {
                Password = password
            }), "Did not throw exception");
        }
示例#5
0
        public void IfUsernameIsNullOrEmptyShouldThrowException(string username, string password)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            Assert.Throws <IncorrectUserException>(() => blog.LoginUser(new User(username)
            {
                Password = password
            }), "Did not throw exception");
        }
示例#6
0
        public void UserIsFoundInDbSuccess(string username, string password)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            blog.LoginUser(new User(username)
            {
                Password = password
            });
            var userIsLoggedIn = blog.UserIsLoggedIn;

            Assert.IsTrue(userIsLoggedIn, "The user should be logged in");
        }
示例#7
0
        public void LogoutShouldFail(string username, string password)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            blog.LoginUser(new User(username)
            {
                Password = password
            });
            blog.LogoutUser(new User(username)
            {
                Password = password
            });
            Assert.That(blog.UserIsLoggedIn == false);
        }
示例#8
0
        public void IfMailContentIsNullOrEmptySendEmailThrowException(string username, string password, string address, string caption, string body)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());
            blog.LoginUser(new User(username)
            {
                Password = password
            });

            var userIsLoggedIn = blog.UserIsLoggedIn;

            //Check to see that user is really logged in
            Assert.That(userIsLoggedIn == true, "User should be logged in");

            Assert.Throws <IncorrectEmailException>(() => blog.SendEmail(address, caption, body));
        }
示例#9
0
文件: BlogTest.cs 项目: kimsandin/TDD
        public void PageBeeingPublishedShouldNotSucceedIfPageObjectNotValid(string username, string password, string title, string content)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            //Loggar in anv. först  och kollar att det lyckades
            blog.LoginUser(new User(username)
            {
                Password = password
            });
            var userIsLoggedIn = blog.UserIsLoggedIn;

            Assert.IsTrue(userIsLoggedIn, "User login should be successful");

            //Skapa Page-objektet misslyckas när null skickas med
            Assert.Throws <PageIsNotCorrectObjektException>(() => blog.PublishPage(null), "The publish should not have been succesful");
        }
示例#10
0
文件: BlogTest.cs 项目: kimsandin/TDD
        public void IfMailContentIsOKShouldSendEmail(string username, string password, string address, string caption, string body)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());
            blog.LoginUser(new User(username)
            {
                Password = password
            });

            var userIsLoggedIn = blog.UserIsLoggedIn;

            //Check to see that user is really logged in
            Assert.That(userIsLoggedIn == true, "User should be logged in");

            var intreturned = blog.SendEmail(address, caption, body);

            Assert.That(intreturned == 1, "Message should be sent");
        }
示例#11
0
        public void IfUserIsLoggedInSendEmailShouldReturnOne(string address, string caption, string body, string username, string password)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            blog.LoginUser(new User(username)
            {
                Password = password
            });

            var userIsLoggedIn = blog.UserIsLoggedIn;

            //Check to see that user is really logged in
            Assert.That(userIsLoggedIn == true, "User should be logged in");

            var result = blog.SendEmail(address, caption, body);

            // SendEmail returns 1 if email is sent and 0 on failure.
            Assert.That(result == 1, "The message should have been sent, since user is logged in");
        }
示例#12
0
        public void PublishPageShouldSucceed(string username, string password, string title, string content)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            blog.LoginUser(new User(username)
            {
                Password = password
            });

            var userIsLoggedIn = blog.UserIsLoggedIn;

            //Check to see that user is really logged in
            Assert.That(userIsLoggedIn == true, "User should be logged in");

            Assert.That(blog.PublishPage(new Page()
            {
                Title = title, Content = content
            }) == true, "The publish should have been succesful");
        }
示例#13
0
文件: BlogTest.cs 项目: kimsandin/TDD
        public void PageBeeingPublishedShouldSucceed(string username, string password, string title, string content)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            //Loggar in anv. först  och kollar att det lyckades
            blog.LoginUser(new User(username)
            {
                Password = password
            });
            var userIsLoggedIn = blog.UserIsLoggedIn;

            Assert.IsTrue(userIsLoggedIn, "User login should be successful");

            //Skapa Page-objektet och kollar att det är ok och publicerat
            Assert.That(blog.PublishPage(new Page()
            {
                Title = title, Content = content
            })
                        == true, "The new page should be successfully published");
        }
示例#14
0
        public void LogoutShouldThrowException(string username, string password)
        {
            blog = new Blog(_authenticator = new MockAuthenticator());

            blog.LoginUser(new User(username)
            {
                Password = password
            });

            Assert.Throws <IncorrectUserException>(() => blog.LogoutUser(null));
            Assert.Throws <IncorrectUserException>(() => blog.LogoutUser(new User(null)
            {
                Password = password
            }));
            Assert.Throws <IncorrectAuthenticationException>(() => blog.LogoutUser(new User(username)
            {
                Password = null
            }));
            Assert.Throws <IncorrectUserException>(() => blog.LogoutUser(new User("")
            {
                Password = ""
            }));
        }