コード例 #1
0
ファイル: DiagnosticsTests.cs プロジェクト: tharshada/Omex
        public void StopActivityIfExist_HandlesNullValue()
        {
            (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener();

            listener.StopActivityIfExist(null);
            Assert.IsFalse(mockObserver.Events.Any(), "Should not produce any events");
        }
コード例 #2
0
ファイル: DiagnosticsTests.cs プロジェクト: tharshada/Omex
        public void ReportException_PropagatedAsEventPayload()
        {
            (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener();
            Exception exception = new IndexOutOfRangeException();

            listener.ReportException(exception);

            mockObserver.AssertException(exception);
        }
コード例 #3
0
ファイル: MockObserver.cs プロジェクト: tharshada/Omex
        public static (DiagnosticListener, MockObserver) CreateListener([CallerMemberName] string name = "")
        {
            MockObserver mockObserver = new MockObserver(name);

            mockObserver.m_unsubscribe = DiagnosticListener.AllListeners.Subscribe(mockObserver);
            DiagnosticListener listener = new DiagnosticListener(name);

            return(listener, mockObserver);
        }
コード例 #4
0
ファイル: DiagnosticsTests.cs プロジェクト: tharshada/Omex
        public void CreateAndStartActivity_ReportsStartEvent()
        {
            (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener();

            string   activityName = nameof(CreateAndStartActivity_ReportsStartEvent);
            Activity?activity     = listener.CreateAndStartActivity(activityName);
            string   eventName    = mockObserver.Events.Single().Key;

            Assert.AreEqual(activityName + ".Start", eventName);
        }
コード例 #5
0
ファイル: DiagnosticsTests.cs プロジェクト: tharshada/Omex
        public void StopActivityIfExist_ReportsStopEvent()
        {
            (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener();

            string   activityName = nameof(StopActivityIfExist_ReportsStopEvent);
            Activity activity     = new Activity(activityName).Start();

            listener.StopActivityIfExist(activity);
            string eventName = mockObserver.Events.Single().Key;

            Assert.AreEqual(activityName + ".Stop", eventName);
            Assert.AreNotEqual(TimeSpan.Zero, activity.Duration, "Activity should be stoped");
        }
コード例 #6
0
        public void Constructor_SendOneWay_ReportsException()
        {
            ArithmeticException            exception    = new ArithmeticException();
            IServiceRemotingRequestMessage messsageMock = CreateMessage();
            Mock <IServiceRemotingClient>  clientMock   = new Mock <IServiceRemotingClient>();

            clientMock.Setup(c => c.SendOneWay(messsageMock)).Throws(exception);
            (DiagnosticListener listener, MockObserver observer) = MockObserver.CreateListener();
            ServiceRemotingClientWrapper wrapper = new ServiceRemotingClientWrapper(clientMock.Object, listener);

            Assert.ThrowsException <ArithmeticException>(() => wrapper.SendOneWay(messsageMock));
            observer.AssertException(exception);
        }
コード例 #7
0
        public async Task Constructor_RequestResponseAsync_ReportsException()
        {
            ArithmeticException            exception    = new ArithmeticException();
            IServiceRemotingRequestMessage messsageMock = CreateMessage();
            Mock <IServiceRemotingClient>  clientMock   = new Mock <IServiceRemotingClient>();

            clientMock.Setup(c => c.RequestResponseAsync(messsageMock)).Throws(exception);
            (DiagnosticListener listener, MockObserver observer) = MockObserver.CreateListener();
            ServiceRemotingClientWrapper wrapper = new ServiceRemotingClientWrapper(clientMock.Object, listener);

            await Assert.ThrowsExceptionAsync <ArithmeticException>(() => wrapper.RequestResponseAsync(messsageMock));

            observer.AssertException(exception);
        }