コード例 #1
0
        public void ExceptionLogToDataBase()
        {
            try
            {
                DJobLogger _DJobLogger        = new DJobLogger(false, true, false, true, true, true);
                var        mockILogToDataBase = new Mock <ILogToDataBase>();
                mockILogToDataBase.Setup(x => x.LogMessageToDataBase(It.IsAny <string>(), It.IsAny <int>())).Throws(new Exception("An Exception occurs when try to save message to DataBase"));
                _DJobLogger.LogMsgToDataBase = mockILogToDataBase.Object;

                _DJobLogger.LogMessage("test", Enumerations.LogType.message);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.Message, "Excepcion al intentar registrar el mensaje");;
                return;
            }
        }
コード例 #2
0
        public void SuccessSaveLogToFile()
        {
            try
            {
                DJobLogger _DJobLogger    = new DJobLogger(true, false, false, true, true, true);
                var        mockILogToFile = new Mock <ILogToFile>();
                mockILogToFile.Setup(x => x.LogMessageToFile(It.IsAny <string>()));
                _DJobLogger.LogMsgToFile = mockILogToFile.Object;

                _DJobLogger.LogMessage("test", Enumerations.LogType.message);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
                return;
            }
        }
コード例 #3
0
        public void ExceptionLogToFile()
        {
            DJobLogger _DJobLogger    = new DJobLogger(true, false, false, true, true, true);
            var        mockILogToFile = new Mock <ILogToFile>();

            mockILogToFile.Setup(x => x.LogMessageToFile(It.IsAny <string>())).Throws(new Exception("Exception when trying to write to log file"));
            _DJobLogger.LogMsgToFile = mockILogToFile.Object;

            try
            {
                _DJobLogger.LogMessage("test", Enumerations.LogType.message);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.Message, "Excepcion al intentar registrar el mensaje");
                return;
            }

            Assert.Fail("No exception was thrown");
        }