Exemplo n.º 1
0
        public void Equals_WorksProperly()
        {
            string name = nameof(Equals_WorksProperly);

            TimedScopeDefinition definition1 = new TimedScopeDefinition(name);

            TimedScopeDefinition definition2 = new TimedScopeDefinition(name);

            Assert.IsTrue(definition1.Equals(definition2), "1 Equals 2");

            Assert.IsTrue(definition2.Equals(definition1), "2 Equals 1");

            Assert.IsTrue(definition1.Equals((object)definition2), "1 Equals (object)2");

            Assert.IsTrue(definition2.Equals((object)definition1), "2 Equals (object)1");

            Assert.AreEqual(definition1.GetHashCode(), definition2.GetHashCode(), "1 HashCode equals 2 HashCode");

            Assert.IsTrue(definition1 == definition2, "1 == 2");

            Assert.IsTrue(definition2 == definition1, "2 == 1");

            Assert.IsFalse(definition1 != definition2, "1 != 2");

            Assert.IsFalse(definition2 != definition1, "2 != 1");
        }
Exemplo n.º 2
0
        public void EquilsWithEmpty_WorksProperly()
        {
            TimedScopeDefinition definition = new TimedScopeDefinition(nameof(EquilsWithEmpty_WorksProperly));

            Assert.IsFalse(definition.Equals(null), "definition Equals null");

            Assert.IsFalse(definition.Equals(default), "definition Equals default");
Exemplo n.º 3
0
        private void TestExecution(
            string scopeName,
            Action <Task <bool>, ITimedScopeProvider, TimedScopeDefinition> createTask,
            Action <TaskCompletionSource <bool> > finishTask,
            TimedScopeResult expectedResult)
        {
            Mock <ITimedScopeProvider> providerMock         = new Mock <ITimedScopeProvider>();
            TimedScopeDefinition       timedScopeDefinition = new TimedScopeDefinition(scopeName);
            Activity activity = new Activity(scopeName);

            TimedScope scope = new TimedScope(activity, TimedScopeResult.SystemError);

            providerMock.Setup(p => p.CreateAndStart(timedScopeDefinition, TimedScopeResult.SystemError)).Returns(scope);

            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            createTask(taskCompletionSource.Task, providerMock.Object, timedScopeDefinition);

            providerMock.Verify(p => p.CreateAndStart(timedScopeDefinition, TimedScopeResult.SystemError), Times.Once);
            scope.Activity.AssertResult(TimedScopeResult.SystemError);

            finishTask(taskCompletionSource);

            scope.Activity.AssertResult(expectedResult);
        }
Exemplo n.º 4
0
        public void CreateAndStart_TimedScopeCreated()
        {
            TimedScopeResult     result     = TimedScopeResult.ExpectedError;
            TimedScopeDefinition definition = new TimedScopeDefinition(nameof(CreateAndStart_TimedScopeCreated));
            SimpleScopeProvider  provider   = new SimpleScopeProvider();
            TimedScope           scope      = provider.CreateAndStart(definition, result);

            Assert.IsNotNull(scope);
        }
        public static TimedScope Create(this TimedScopeDefinition timedScopeDefinition, TimedScopeResult initialResult, bool startScope = true)
        {
            if (s_timedScopeProvider == null)
            {
                throw new OmexCompatibilityInitializationException();
            }

            TimedScope scope = s_timedScopeProvider.Create(timedScopeDefinition, initialResult);

            if (startScope)
            {
                scope.Start();
            }

            return(scope);
        }
Exemplo n.º 6
0
        private void CreateAndValidateActivity(string activityName)
        {
            TimedScopeResult result = TimedScopeResult.ExpectedError;

            Mock <IActivityProvider> activityProviderMock = new Mock <IActivityProvider>();
            Mock <Activity>          activityMock         = new Mock <Activity>(activityName);
            TimedScopeDefinition     definition           = new TimedScopeDefinition(activityName);

            activityProviderMock.Setup(p => p.Create(definition)).Returns(activityMock.Object);

            TimedScopeProvider provider = new TimedScopeProvider(activityProviderMock.Object);

            TimedScope scope = provider.CreateAndStart(definition, result);

            Assert.IsNotNull(scope);
        }
Exemplo n.º 7
0
        public void AddOmexCompatibilityServices_RegisterTypes()
        {
            Mock <ILogger>        mockLogger  = new Mock <ILogger>();
            Mock <ILoggerFactory> mockFactory = new Mock <ILoggerFactory>();

            mockFactory.Setup(f => f.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object);

            new HostBuilder()
            .ConfigureServices(collection =>
            {
                collection
                .AddTimedScopes()
                .AddSingleton(mockFactory.Object)
                .AddOmexCompatibilityServices();
            })
            .Build()
            .Start();

            EventId   eventId    = new EventId(1);
            Category  category   = new Category("Test");
            LogLevel  logLevel   = LogLevel.Error;
            string    logMessage = "TestLogMessage";
            Exception exception  = new Exception();

            mockLogger.Invocations.Clear();
            ULSLogging.LogTraceTag(eventId, category, logLevel, logMessage);
            Assert.AreEqual(1, mockLogger.Invocations.Count, "ULSLogging.LogTraceTag not calling ILogger");

            mockLogger.Invocations.Clear();
            ULSLogging.ReportExceptionTag(eventId, category, exception, logMessage);
            Assert.AreEqual(1, mockLogger.Invocations.Count, "ULSLogging.ReportExceptionTag not calling ILogger");

            mockLogger.Invocations.Clear();
            Code.Validate(false, logMessage, eventId);
            Assert.AreEqual(1, mockLogger.Invocations.Count, "Code.Validate not calling ILogger");

            using (TimedScope startedTimedScope = new TimedScopeDefinition("TestStartedTimedScope").Create(TimedScopeResult.SystemError))
            {
                AssertResult(ActivityResultStrings.SystemError);
            }

            using (TimedScope notStartedTimedScope = new TimedScopeDefinition("TestNotStartedTimedScope").Create(TimedScopeResult.ExpectedError, false))
            {
                notStartedTimedScope.Start();
                AssertResult(ActivityResultStrings.ExpectedError);
            }
        }
Exemplo n.º 8
0
        public void Scope_TimedScopeLogger_IsCalled()
        {
            Mock <ITimedScopeLogger>        timedScopeLoggerMock       = new Mock <ITimedScopeLogger>();
            Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>();
            Mock <ICallContextManager>      callContextManagerMock     = new Mock <ICallContextManager>();

            IMachineInformation     machineInformation     = new UnitTestMachineInformation();
            ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation);

            TimedScope      scope;
            CorrelationData data = new CorrelationData();

            using (scope = new TimedScopeDefinition("TestScope")
                           .Create(data, machineInformation, customLogger: timedScopeLoggerMock.Object, replayEventConfigurator: replyEventConfiguratorMock.Object,
                                   timedScopeStackManager: timedScopeStackManager, initialResult: TimedScopeResult.SystemError))
            {
                timedScopeLoggerMock.Verify(x => x.LogScopeStart(scope), Times.Once);
                timedScopeLoggerMock.Verify(x => x.LogScopeEnd(scope, It.IsAny <CorrelationData>()), Times.Never);
            }

            timedScopeLoggerMock.Verify(x => x.LogScopeEnd(scope, It.IsAny <CorrelationData>()), Times.Once);
        }
Exemplo n.º 9
0
        public void NotEquals_WorksProperly()
        {
            TimedScopeDefinition definition1 = new TimedScopeDefinition("TestName1");

            TimedScopeDefinition definition2 = new TimedScopeDefinition("TestName2");

            Assert.IsFalse(definition1.Equals(definition2), "1 Equals 2");

            Assert.IsFalse(definition2.Equals(definition1), "2 Equals 1");

            Assert.IsFalse(definition1.Equals((object)definition2), "1 Equals (object)2");

            Assert.IsFalse(definition2.Equals((object)definition1), "2 Equals (object)1");

            Assert.AreNotEqual(definition1.GetHashCode(), definition2.GetHashCode(), "1 HashCode NotEquals 2 HashCode");

            Assert.IsFalse(definition1 == definition2, "1 == 2");

            Assert.IsFalse(definition2 == definition1, "2 == 1");

            Assert.IsTrue(definition1 != definition2, "1 != 2");

            Assert.IsTrue(definition2 != definition1, "2 != 1");
        }
Exemplo n.º 10
0
 public Activity Create(TimedScopeDefinition definition) => new Activity(definition.Name);
Exemplo n.º 11
0
 /// <inheritdoc />
 public TimedScope CreateAndStart(TimedScopeDefinition name, TimedScopeResult result = TimedScopeResult.SystemError) =>
 Create(name, result).Start();
Exemplo n.º 12
0
 /// <inheritdoc />
 public TimedScope Create(TimedScopeDefinition name, TimedScopeResult result = TimedScopeResult.SystemError) =>
 new TimedScope(new System.Diagnostics.Activity(name.Name), result);
Exemplo n.º 13
0
 public Activity Create(TimedScopeDefinition definition) =>
 m_replayLogsInCaseOfError
                 ? new ReplayableActivity(definition.Name, m_maxReplayedEventsPerActivity)
                 : new Activity(definition.Name);
Exemplo n.º 14
0
        public void Constructor_PropagatesName(string activityName)
        {
            TimedScopeDefinition definition = new TimedScopeDefinition(activityName);

            Assert.AreEqual(activityName, definition.Name);
        }