コード例 #1
0
        public void IsLoginOK_ValidUserAndPassword_LogsMessage()
        {
            var logger = FakeLogerFactory();
            var lm     = new FakeLoginManager(logger);

            lm.AddUser("a", "b");

            lm.IsLoginOK("a", "b");

            Assert.AreEqual("login ok: user: a", logger.LastMessage());
        }
コード例 #2
0
        public void IsLoginOK_CallStaticLogger_LogsCorrectMessage()
        {
            var logger = FakeLogerFactory();
            var lm     = new FakeLoginManager(logger);

            lm.AddUser("a", "b");

            lm.IsLoginOK("a", "b");

            Assert.AreEqual("user a logged in ok", lm.Message);
        }
コード例 #3
0
        public void IsLoginOK_CallStaticLogger_LogsCorrectMessage()
        {
            var machineName = "machineName";
            var lm          = new FakeLoginManager(machineName);

            lm.AddUser("a", "b");

            lm.IsLoginOK("a", "b");

            Assert.AreEqual("12.12.12 12:33:55 My Exception machineName", lm.Message);
        }
コード例 #4
0
        public void IsLoginOK_UsingMoq_ValidUserAndPassword_LogsMessage()
        {
            var loggerMock = new Mock <ILogger>();

            var lm = new FakeLoginManager(loggerMock.Object);

            lm.AddUser("a", "b");

            lm.IsLoginOK("a", "b");

            loggerMock.Verify(_ => _.Write("login ok: user: a"), Times.Once);
        }
コード例 #5
0
        public void IsLoginOK_WhenLoggerThrowsException_LogsCorrectMessage()
        {
            var mockWs = new Mock <IWebService>();
            var logger = FakeLogerFactory(mockWs.Object, willThrowException: true);
            var lm     = new FakeLoginManager(logger);

            lm.AddUser("a", "b");

            lm.IsLoginOK("a", "b");

            mockWs.Verify(_ => _.Write(It.IsAny <string>()), Times.Once);
        }
コード例 #6
0
        public void IsLoginOK_ValidUserAndPassword_FailsToCompareHashtable(
            string addUserName, string addPassword,
            string checkUserName, string checkPassword)
        {
            var logger = FakeLogerFactory();
            var lm     = new FakeLoginManager(logger);

            lm.AddUser(addUserName, addPassword);

            lm.IsLoginOK(checkUserName, checkPassword);

            Assert.AreEqual(string.Format("login ok: user: {0}", checkUserName), logger.LastMessage());
        }
コード例 #7
0
        public void IsLoginOK_UsingMock_InvalidUserOrPassword_LogsMessage(
            string addUserName, string addPassword,
            string checkUserName, string checkPassword)
        {
            var logger = new Mock <ILogger>();
            var lm     = new FakeLoginManager(logger.Object);

            lm.AddUser(addUserName, addPassword);

            lm.IsLoginOK(checkUserName, checkPassword);

            logger.Verify(_ => _.Write(string.Format("bad login: {0},{1}", checkUserName, checkPassword)), Times.Once);
        }
コード例 #8
0
        public void IsLoginOK_InvalidUserOrPassword_LogsMessage(
            string addUserName, string addPassword,
            string checkUserName, string checkPassword)
        {
            var logger = FakeLogerFactory();
            var lm     = new FakeLoginManager(logger);

            lm.AddUser(addUserName, addPassword);

            lm.IsLoginOK(checkUserName, checkPassword);

            Assert.AreEqual(string.Format("bad login: {0},{1}", checkUserName, checkPassword), logger.LastMessage());
        }
コード例 #9
0
        public void IsLoginOK_ValidUserAndPassword_FailsToCompareHashtable()
        {
            var logger = FakeLogerFactory();
            var lm     = new FakeLoginManager(logger);

            var addUserName   = new string(new [] { 'a' });
            var addPassword   = new string(new[] { 'b' });
            var checkUserName = new string(new[] { 'a' });
            var checkPassword = new string(new[] { 'b' });

            lm.AddUser(addUserName, addPassword);

            lm.IsLoginOK(checkUserName, checkPassword);

            Assert.AreEqual("login ok: user: a", logger.LastMessage());
        }