Пример #1
0
        [TestMethod]//2
        public void LogToOperationsTest_WithExceptionMsg2()
        {
            /*public void LogToOperations(Exception exception, string additionalMessage, int eventId)*/
            string    strExceptionMsg = "Custom Exception Message by Automation code. Message No " + DateTime.Now.Ticks.ToString();
            Exception ex = new Exception(strExceptionMsg);

            string strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");

            EventLogEntryType Severity  = EventLogEntryType.Error;
            TraceSeverity     TSeverity = LogUtils.MapEventLogEntryTypesToTraceLogSeverity(Severity);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.LogToOperations(ex, strMessage, EID_Default);

            bool isValidEL = LogUtils.ValidateEventLog(strEventSourceName, EID_Default, strMessage, strExceptionMsg, Severity); //validation for event log entry

            bool isValidSPL = LogUtils.ValidateSPLogs(strExceptionMsg, null, TSeverity, EID_Default);                           ////Validation for Splog Entries

            spLogger = null;
            ex       = null;

            Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
            Assert.IsTrue(isValidEL, "No entry is made in Event Logs");
        }
Пример #2
0
        public void WhenLoggingFailsAClearExceptionIsThrown()
        {
            //Arrange
            var    target  = new SharePointLogger();
            string message = testMessageString;

            ((ActivatingServiceLocator)SharePointServiceLocator.GetCurrent())
            .RegisterTypeMapping <IEventLogLogger, FailingEventLogger>();

            //Act
            try
            {
                target.LogToOperations(message, 99, EventSeverity.Error, TestsConstants.AreasCategories);
                Assert.Fail();
            }
            //Assert
            catch (LoggingException ex)
            {
                Assert.IsTrue(ex.Message.Contains(message));
                Assert.IsTrue(ex.Message.Contains("EventLog"));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Пример #3
0
        public void LogMessageShouldContainContextualInformation()
        {
            // arrange
            var context = BHttpContext.SetCurrent();

            MSPContext.CurrentGet = () => null;

            context.Timestamp = new DateTime(2000, 1, 1);
            var user     = context.SetUser();
            var identity = user.SetIdentity();

            identity.Name = "TestUser";
            var request = context.SetRequest();

            request.Url             = new Uri("http://localhost/mypage.aspx");
            request.UserHostAddress = "1.1.1.1.1";
            request.UserAgent       = "MyAgent";
            var       eventLogger = SharePointServiceLocator.GetCurrent().GetInstance <IEventLogLogger>() as MockEventAndTraceLogger;
            Exception ex          = new Exception("message");

            // act
            var target = new SharePointLogger();

            target.LogToOperations(ex);

            var message = eventLogger.Messages[0].Message;

            Assert.IsTrue(message.Contains(@"Request URL: 'http://localhost/mypage.aspx'"));
            Assert.IsTrue(message.Contains("Request TimeStamp: '" + context.Timestamp.ToString("o", CultureInfo.CurrentCulture) + "'"));
            Assert.IsTrue(message.Contains("UserName: '******'"));
            Assert.IsTrue(message.Contains("Originating IP address: '1.1.1.1.1'"));
            Assert.IsTrue(message.Contains("User Agent: 'MyAgent'"));
        }
Пример #4
0
        public void TraceLoggerPropertyTest()
        {
            SharePointLogger logger = new SharePointLogger();

            try
            {
                ITraceLogger iTLogger = logger.TraceLogger;
                TraceLogger  tlogger  = new TraceLogger();
                if (!iTLogger.GetType().IsInterface)
                {
                    if (iTLogger.GetType().ToString() == tlogger.GetType().ToString())
                    {
                        Assert.IsTrue(true);
                    }
                    else
                    {
                        Assert.Fail("There is a type mismatch");
                    }
                }
                else
                {
                    Assert.Fail("Interface was returned");
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Пример #5
0
        public void TraceToDeveloperTest_WithException()
        {
            /*public void TraceToDeveloper(Exception exception, string additionalMessage, int eventId,
             *                                TraceSeverity severity, string category)  */

            string    strExceptionMsg = "Custom Exception Message by Automation code. Message No " + new Random(100).Next(100, 500);
            Exception ex = new Exception(strExceptionMsg);

            string strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");
            int    EID        = new Random().Next(1, 20);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            //spLogger.TraceToDeveloper(strMessage, EID, TraceSeverity.Medium, null);
            spLogger.TraceToDeveloper(ex, strMessage, EID, TraceSeverity.Medium, null);

            bool isValidSPL = LogUtils.ValidateSPLogs(strExceptionMsg);//Validation for Splog Entries

            if (isValidSPL)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("No exception entry is made in Share point Logs");
            }
        }
Пример #6
0
        /// <summary>
        /// This is a sample specific finder method for Entity1.
        /// If you want to delete or rename the method think about changing the xml in the BDC model file as well.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Entity1</returns>
        public static EntityEmployeeData ReadItem(string PersonalNumber)
        {
            EmployeeBasic      basicInfo    = null;
            EmployeeDetail     detailedInfo = null;
            EntityEmployeeData ret          = new EntityEmployeeData();

            SharePointLogger logger  = new SharePointLogger();
            TestConfigTh     config  = new TestConfigTh();
            TestLicense      license = new TestLicense();


            using (EmployeeRepositorySAPDotNet rep = new EmployeeRepositorySAPDotNet(config, logger, license))
            {
                List <EmployeeBasic> empList = rep.getEmployeeBasicList();
                foreach (EmployeeBasic emp in empList)
                {
                    if (emp.PersonalNumber.ToLower().Trim().Equals(PersonalNumber.ToLower().Trim()))
                    {
                        basicInfo = emp;
                    }
                }
                if (basicInfo != null)
                {
                    detailedInfo = rep.getEmployeeDetailedInfo(PersonalNumber);
                }
            }

            if (basicInfo != null)
            {
                ret = new EntityEmployeeData(basicInfo, detailedInfo);
            }

            return(ret);
        }
Пример #7
0
        public void TraceLogsOnlyToTraceLog()
        {
            SharePointLogger target = new SharePointLogger();

            target.TraceToDeveloper("Message", 99, TraceSeverity.High, "Category1");

            Assert.IsNull((target.EventLogLogger as MockEventLogger).Message);

            AssertLogData(target.TraceLogger as MockTraceLogger, TraceSeverity.High);
        }
Пример #8
0
        public void IfTracingErrorOccursEventLogMessageShouldStillBeWritten()
        {
            SharePointLogger target = new SharePointLogger();

            ((ActivatingServiceLocator)SharePointServiceLocator.Current).RegisterTypeMapping <ITraceLogger, FailingLogger>();
            target.LogToOperations("Message", 99, EventLogEntryType.Error, "Category1");

            Assert.AreEqual("Message", (target.EventLogLogger as MockEventLogger).Messages[0]);
            Assert.IsTrue((target.EventLogLogger as MockEventLogger).Messages[1].Contains("NotImplementedException"));
        }
Пример #9
0
        public void WhenLogToOperationsFailsThrowsLoggingException()
        {
            //Arrange
            ((ActivatingServiceLocator)SharePointServiceLocator.GetCurrent()).RegisterTypeMapping <IEventLogLogger, FailingEventLogger>();
            var    target      = new SharePointLogger();
            string testMessage = testMessageString;

            //Act
            target.LogToOperations(testMessage);

            //Assert is caught by thrown exception.
        }
Пример #10
0
        public void EventLogLoggerPropertyTest2()
        {
            SharePointLogger logger   = new SharePointLogger();
            IEventLogLogger  iELogger = logger.EventLogLogger;
            EventLogLogger   elogger  = (EventLogLogger)logger.EventLogLogger;

            Assert.AreEqual(iELogger.GetType(), elogger.GetType());

            logger   = null;
            iELogger = null;
            elogger  = null;
        }
Пример #11
0
        public void TraceLoggerPropertyTest()
        {
            SharePointLogger logger   = new SharePointLogger();
            ITraceLogger     iTLogger = logger.TraceLogger;
            TraceLogger      tlogger  = new TraceLogger();

            Assert.AreEqual(iTLogger.GetType(), tlogger.GetType());

            logger   = null;
            iTLogger = null;
            tlogger  = null;
        }
Пример #12
0
        public void WriteSandboxLog_LogsMessage()
        {
            //Arrange
            SharePointEnvironment.Reset();
            var context = new SIApplicationContextProvider()
            {
                GetCurrentAppDomainFriendlyName = () => "SandboxDomain",
                IsProxyCheckerInstalled         = () => true,
                IsProxyInstalledStringString    = (a, t) => true,
            };

            SharePointEnvironment.ApplicationContextProvider = context;
            string testMessage = testMessageString;
            int    testEventId = 99;
            LoggingOperationArgs loggingArgs = null;
            BSPSite site = new BSPSite();
            MSPSite s    = new MSPSite(site)
            {
                IDGet = () => TestsConstants.TestGuid
            };

            BSPContext.SetCurrent();
            MSPContext c = new MSPContext(BSPContext.Current)
            {
                SiteGet = () => site
            };

            MSPUtility.ExecuteRegisteredProxyOperationStringStringSPProxyOperationArgs = (a, t, args) =>
            {
                loggingArgs =
                    args as
                    LoggingOperationArgs;
                return(null);
            };


            //Act
            var target = new SharePointLogger();

            target.LogToOperations(testMessage, testEventId, SandboxEventSeverity.Error, TestsConstants.AreasCategories);

            // Assert
            Assert.IsNotNull(loggingArgs);
            Assert.AreEqual(loggingArgs.Message, testMessage);
            Assert.AreEqual(loggingArgs.Category, TestsConstants.AreasCategories);
            Assert.AreEqual(loggingArgs.EventId, testEventId);
            Assert.AreEqual((SandboxEventSeverity)loggingArgs.Severity, SandboxEventSeverity.Error);
        }
Пример #13
0
        [TestMethod]//5
        public void TraceToDeveloperTest5()
        {
            //public void TraceToDeveloper(string message, string category)

            string strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.TraceToDeveloper(strMessage, strDefaultCategory);

            bool isValidSPL = LogUtils.ValidateSPLogs(strMessage, strDefaultCategory, DefaultSevirity, EID_Default);//Validation for Splog Entries

            spLogger = null;

            Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
        }
Пример #14
0
        /// <summary>
        /// This is a sample finder method for Entity1.
        /// If you want to delete or rename the method think about changing the xml in the BDC model file as well.
        /// </summary>
        /// <returns>IEnumerable of Entities</returns>
        public static IEnumerable <EntityEmployeeData> ReadList()
        {
            List <EntityEmployeeData> returnList = new List <EntityEmployeeData>();

            SharePointLogger logger  = new SharePointLogger();
            TestConfigTh     config  = new TestConfigTh();
            TestLicense      license = new TestLicense();

            using (EmployeeRepositorySAPDotNet rep = new EmployeeRepositorySAPDotNet(config, logger, license))
            {
                List <EmployeeBasic> empList = rep.getEmployeeBasicList();
                foreach (EmployeeBasic emp in empList)
                {
                    returnList.Add(new EntityEmployeeData(emp));
                }
            }
            return(returnList);
        }
Пример #15
0
        public void LogMessageShouldContainContextualInformation()
        {
            SharePointLogger target = new SharePointLogger();

            Isolate.WhenCalled(() => HttpContext.Current.User.Identity.Name).WillReturn("TestUser");
            Isolate.WhenCalled(() => HttpContext.Current.Request.Url).WillReturn(new Uri("http://localhost/mypage.aspx"));
            Isolate.WhenCalled(() => HttpContext.Current.Request.UserHostAddress).WillReturn("1.1.1.1.1");
            Isolate.WhenCalled(() => HttpContext.Current.Request.UserAgent).WillReturn("MyAgent");
            Isolate.WhenCalled(() => HttpContext.Current.Timestamp).WillReturn(new DateTime(2000, 1, 1));

            target.LogToOperations("Message");

            Assert.IsTrue(eventLogger.Message.Contains("Request URL: 'http://localhost/mypage.aspx"));
            Assert.IsTrue(eventLogger.Message.Contains("Request TimeStamp: '" + new DateTime(2000, 1, 1).ToString("o", CultureInfo.CurrentCulture) + "'"));
            Assert.IsTrue(eventLogger.Message.Contains("UserName: '******'"));
            Assert.IsTrue(eventLogger.Message.Contains("Originating IP address: '1.1.1.1.1'"));
            Assert.IsTrue(eventLogger.Message.Contains("User Agent: 'MyAgent'"));
        }
Пример #16
0
        [TestMethod]//3
        public void TraceToDeveloperTest_WithException3()
        {
            /*public void TraceToDeveloper(Exception exception) */

            string    strExceptionMsg = "Custom Exception Message by Automation code. Message No " + DateTime.Now.Ticks.ToString();
            Exception ex = new Exception(strExceptionMsg);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.TraceToDeveloper(ex);

            bool isValidSPL = LogUtils.ValidateSPLogs(strExceptionMsg, null, DefaultSevirity, EID_Default);//Validation for Splog Entries

            spLogger = null;
            ex       = null;

            Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
        }
Пример #17
0
        public void WriteSandboxTrace_NoContext_TracesMessage()
        {
            //Arrange
            SharePointEnvironment.Reset();
            string testMessage = testMessageString;
            int    testEventId = 99;
            TracingOperationArgs tracingArgs = null;
            BSPSite site = new BSPSite();
            MSPSite s    = new MSPSite(site)
            {
                IDGet = () => TestsConstants.TestGuid
            };

            MSPContext.CurrentGet = () => null;
            MSPUtility.ExecuteRegisteredProxyOperationStringStringSPProxyOperationArgs = (a, t, args) =>
            {
                tracingArgs =
                    args as
                    TracingOperationArgs;
                return(null);
            };

            var context = new SIApplicationContextProvider()
            {
                GetCurrentAppDomainFriendlyName = () => "SandboxDomain",
                IsProxyCheckerInstalled         = () => true,
                IsProxyInstalledStringString    = (a, t) => true,
            };

            SharePointEnvironment.ApplicationContextProvider = context;

            //Act
            var target = new SharePointLogger();

            target.TraceToDeveloper(testMessage, testEventId, SandboxTraceSeverity.High, TestsConstants.AreasCategories);

            // Assert
            Assert.IsNotNull(tracingArgs);
            Assert.AreEqual(tracingArgs.Message, testMessage);
            Assert.AreEqual(tracingArgs.Category, TestsConstants.AreasCategories);
            Assert.AreEqual(tracingArgs.EventId, testEventId);
            Assert.AreEqual((SandboxTraceSeverity)tracingArgs.Severity, SandboxTraceSeverity.High);
        }
Пример #18
0
        public void LogToOperationsTest_WithExceptionMsg()
        {
            /*public void LogToOperations(Exception exception, string additionalMessage, int eventId,
             *                               EventLogEntryType severity, string category)*/
            string    strExceptionMsg = "Custom Exception Message by Automation code. Message No " + new Random(100).Next(100, 500);
            Exception ex = new Exception(strExceptionMsg);

            string strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");
            int    EID        = new Random().Next(1, 20);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.LogToOperations(ex, strMessage, EID, EventLogEntryType.Error, null);

            bool isValidEL = LogUtils.ValidateEventLog(LogUtils.strEventSourceName, EID, strMessage, strExceptionMsg); //validation for event log entry

            bool isValidSPL = LogUtils.ValidateSPLogs(strExceptionMsg);                                                ////Validation for Splog Entries

            //if (isValidEL)
            //    if (isValidSPL)
            //        Assert.IsTrue(true);
            //    else
            //        Assert.Fail("No entry is made in Share point Logs");
            //else
            //    Assert.Fail("No entry is made in Event Logs");

            if (isValidSPL)
            {
                if (isValidEL)
                {
                    Assert.IsTrue(true);
                }
                else
                {
                    Assert.Fail("No exception entry is made in Event Logs");
                }
            }
            else
            {
                Assert.Fail("No exception entry is made in Share point Logs");
            }
        }
Пример #19
0
        public void TraceLogsOnlyToTraceLogSucceeds()
        {
            //Arrange
            string testMessage = testMessageString;
            int    testEventId = 99;
            var    traceLogger = SharePointServiceLocator.GetCurrent().GetInstance <ITraceLogger>() as MockEventAndTraceLogger;
            var    eventLogger = SharePointServiceLocator.GetCurrent().GetInstance <IEventLogLogger>() as MockEventAndTraceLogger;

            //Act
            var target = new SharePointLogger();

            target.TraceToDeveloper(testMessage, testEventId, TraceSeverity.High, TestsConstants.AreasCategories);

            // Assert
            Assert.IsTrue(traceLogger.Messages.Count == 1);
            Assert.IsTrue(eventLogger.Messages.Count == 0);
            Assert.AreEqual(traceLogger.Messages[0].Message, testMessage);
            Assert.AreEqual(traceLogger.Messages[0].Category, TestsConstants.AreasCategories);
            Assert.AreEqual(traceLogger.Messages[0].EventId, testEventId);
            Assert.AreEqual(traceLogger.Messages[0].TraceSeverity, TraceSeverity.High);
        }
Пример #20
0
        public void LogToOperationsOnlyLogsToEventLogSucceeds()
        {
            //Arrange
            string testMessage = testMessageString;
            int    testEventId = 99;
            var    traceLogger = SharePointServiceLocator.GetCurrent().GetInstance <ITraceLogger>() as MockEventAndTraceLogger;
            var    eventLogger = SharePointServiceLocator.GetCurrent().GetInstance <IEventLogLogger>() as MockEventAndTraceLogger;

            //Act
            var target = new SharePointLogger();

            target.LogToOperations(testMessage, testEventId, EventSeverity.Error);

            // Assert
            Assert.IsTrue(traceLogger.Messages.Count == 0);
            Assert.IsTrue(eventLogger.Messages.Count == 1);
            Assert.AreEqual(eventLogger.Messages[0].Message, testMessage);
            Assert.AreEqual(eventLogger.Messages[0].Category, null); // Diagnostics service will use default category when called at a lower level.
            Assert.AreEqual(eventLogger.Messages[0].EventId, testEventId);
            Assert.AreEqual(eventLogger.Messages[0].EventSeverity, EventSeverity.Error);
        }
Пример #21
0
        [TestMethod]//5
        public void TraceToDeveloperTest_WithException5()
        {
            /*public void TraceToDeveloper(Exception exception, string additionalMessage, int eventId) */

            string    strExceptionMsg = "Custom Exception Message by Automation code. Message No " + DateTime.Now.Ticks.ToString();
            Exception ex = new Exception(strExceptionMsg);

            string strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");
            int    EID        = DateTime.Now.Second + DateTime.Now.Millisecond;

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.TraceToDeveloper(ex, strMessage, EID);

            bool isValidSPL = LogUtils.ValidateSPLogs(strExceptionMsg, null, DefaultSevirity, EID);//Validation for Splog Entries

            spLogger = null;
            ex       = null;

            Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
        }
Пример #22
0
        [TestMethod]//2
        public void TraceToDeveloperTest_WithException2()
        {
            /*public void TraceToDeveloper(Exception exception, int eventId, TraceSeverity severity, string category) */

            string    strExceptionMsg = "Custom Exception Message by Automation code. Message No " + new Random(100).Next(100, 500);
            Exception ex = new Exception(strExceptionMsg);

            //int EID = (int)DateTime.Now.Ticks;
            int EID = DateTime.Now.Second + DateTime.Now.Millisecond;

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.TraceToDeveloper(ex, EID, DefaultSevirity, strDefaultCategory);

            bool isValidSPL = LogUtils.ValidateSPLogs(strExceptionMsg, strDefaultCategory, DefaultSevirity, EID);//Validation for Splog Entries

            spLogger = null;
            ex       = null;

            Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
        }
Пример #23
0
        [TestMethod]//6
        public void LogToOperationsTest6()
        {
            //public void LogToOperations(string message, string category)
            string            strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");
            EventLogEntryType Severity   = EventLogEntryType.Error;
            TraceSeverity     TSeverity  = LogUtils.MapEventLogEntryTypesToTraceLogSeverity(Severity);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.LogToOperations(strMessage, strDefaultCategory);

            bool isValidEL = LogUtils.ValidateEventLog(strEventSourceName, EID_Default, strMessage, Severity); //validation for event log entry

            bool isValidSPL = LogUtils.ValidateSPLogs(strMessage, strDefaultCategory, TSeverity, EID_Default); ////Validation for Splog Entries

            strMessage = null;
            spLogger   = null;

            Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
            Assert.IsTrue(isValidEL, "No entry is made in Event Logs");
        }
Пример #24
0
        public void TraceToDeveloperTest()
        {
            //public void TraceToDeveloper(string message, int eventId, TraceSeverity severity, string category)

            string strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");
            int    EID        = new Random().Next(1, 20);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.TraceToDeveloper(strMessage, EID, TraceSeverity.Medium, null);

            bool isValidSPL = LogUtils.ValidateSPLogs(strMessage);//Validation for Splog Entries

            if (isValidSPL)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("No entry is made in Share point Logs");
            }
        }
Пример #25
0
        public void LogToOperationsTest()
        {
            //public void LogToOperations(string message, int eventId, EventLogEntryType severity, string category)

            string strMessage = "Custom Message by Automation Test Code. " + Guid.NewGuid().ToString("N");
            int    EID        = new Random().Next(1, 20);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.LogToOperations(strMessage, EID, EventLogEntryType.Error, null);

            bool isValidEL = LogUtils.ValidateEventLog(LogUtils.strEventSourceName, EID, strMessage); //validation for event log entry

            bool isValidSPL = LogUtils.ValidateSPLogs(strMessage);                                    ////Validation for Splog Entries

            //if (isValidEL)
            //    if (isValidSPL)
            //        Assert.IsTrue(true);
            //    else
            //        Assert.Fail("No entry is made in Share point Logs");
            //else
            //    Assert.Fail("No entry is made in Event Logs");

            if (isValidSPL)
            {
                if (isValidEL)
                {
                    Assert.IsTrue(true);
                }
                else
                {
                    Assert.Fail("No entry is made in Event Logs");
                }
            }
            else
            {
                Assert.Fail("No entry is made in Share point Logs");
            }
        }
Пример #26
0
        public void WhenLoggingFailsAClearExceptionIsThrown()
        {
            SharePointLogger target = new SharePointLogger();

            ((ActivatingServiceLocator)SharePointServiceLocator.Current)
            .RegisterTypeMapping <ITraceLogger, FailingLogger>()
            .RegisterTypeMapping <IEventLogLogger, FailingLogger>();

            try
            {
                target.LogToOperations("Message", 99, EventLogEntryType.Error, "Category1");
                Assert.Fail();
            }
            catch (LoggingException ex)
            {
                Assert.IsTrue(ex.Message.Contains("trace log"));
                Assert.IsTrue(ex.Message.Contains("EventLog"));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Пример #27
0
        [TestMethod]//4
        public void LogToOperationsTest_WithExceptionMsg4()
        {
            /*public void LogToOperations(Exception exception)*/
            string    strExceptionMsg = "Custom Exception Message by Automation code. Message No " + new Random(100).Next(100, 500);
            Exception ex = new Exception(strExceptionMsg);

            EventLogEntryType Severity  = EventLogEntryType.Error;
            TraceSeverity     TSeverity = LogUtils.MapEventLogEntryTypesToTraceLogSeverity(Severity);

            SharePointLogger spLogger = new SharePointLogger();//BaseLogger is abstract so we can use the SharePointLogger

            spLogger.LogToOperations(ex);

            bool isValidEL = LogUtils.ValidateEventLog(strEventSourceName, EID_Default, strExceptionMsg, Severity); //validation for event log entry

            bool isValidSPL = LogUtils.ValidateSPLogs(strExceptionMsg, null, TSeverity, EID_Default);               ////Validation for Splog Entries

            spLogger = null;
            ex       = null;

            Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
            Assert.IsTrue(isValidEL, "No entry is made in Event Logs");
        }
Пример #28
0
        public void WhenTraceToDeveloperFailsAClearExceptionIsThrown()
        {
            //Arrange
            ((ActivatingServiceLocator)SharePointServiceLocator.GetCurrent()).RegisterTypeMapping <ITraceLogger, FailingTraceLogger>();
            var    target      = new SharePointLogger();
            string testMessage = testMessageString;

            //Act
            try
            {
                target.TraceToDeveloper(testMessage);
                Assert.Fail();
            }
            //Assert
            catch (LoggingException ex)
            {
                Assert.IsTrue(ex.Message.Contains(testMessage));
                Assert.IsTrue(ex.Message.Contains("Trace Log"));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }