public void StopActivityIfExist_HandlesNullValue() { (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener(); listener.StopActivityIfExist(null); Assert.IsFalse(mockObserver.Events.Any(), "Should not produce any events"); }
public void ReportException_PropagatedAsEventPayload() { (DiagnosticListener listener, MockObserver mockObserver) = MockObserver.CreateListener(); Exception exception = new IndexOutOfRangeException(); listener.ReportException(exception); mockObserver.AssertException(exception); }
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); }
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); }
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"); }
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); }
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); }