Beispiel #1
0
        public void StopActivityIfExist_HandlesNullValue()
        {
            (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener();

            listener.StopActivityIfExist(null);
            Assert.IsFalse(mockObserver.Events.Any(), "Should not produce any events");
        }
Beispiel #2
0
        public void ReportException_PropagatedAsEventPayload()
        {
            (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener();
            Exception exception = new IndexOutOfRangeException();

            listener.ReportException(exception);

            mockObserver.AssertException(exception);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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");
        }
Beispiel #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);
        }
Beispiel #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);
        }