public void WHEN_Operation_is_disposed_SHOULD_track_dependency() { //Arrange var operation = Sut.StartTrace(this, "Trace", LogSeverity.Warning, new Dictionary <string, object> { { "key", "1" } }); MockTelemetryDecorator.Where_Decorate_returns(new TraceTelemetry("Decorated")); MockTelemetryClient.Mock.Verify(x => x.TrackTrace(It.IsAny <TraceTelemetry>()), Times.Never); Sut.StartOperation(this, "overall"); //Act operation.Dispose(); //Assert MockTelemetryDecorator.Mock.Verify(x => x.DecorateTelemetry( It.Is <TraceTelemetry>(y => y.Message == "Trace" && y.SeverityLevel == SeverityLevel.Warning), It.IsAny <string>(), It.IsAny <string>(), It.Is <IAnalyticsOperation>(y => y.Name == "overall"), Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => ((TimeSpan)y["Duration"]).Ticks > 0 && (string)y["key"] == "1"))); MockTelemetryClient.Mock.Verify(x => x.TrackTrace(It.Is <TraceTelemetry>(y => y.Message == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogTrace("Trace", LogSeverity.Warning, It.Is <Dictionary <string, string> >(y => y["key"] == "1"))); }
public void WHEN_Operation_is_disposed_SHOULD_track_dependency() { //Arrange var headers = new Dictionary <string, string> { { AnalyticsHeaders.Operation.Name, "MyOperation" } }; var operation = Sut.StartRequestOperation(this, "RequestName", headers); var decoratedRequestTelemetry = new RequestTelemetry(); MockTelemetryDecorator.Where_Decorate_returns(decoratedRequestTelemetry); //Act operation.Dispose(); //Assert MockTelemetryDecorator.Mock.Verify(x => x.DecorateTelemetry( It.Is <RequestTelemetry>(y => y.Name == "RequestName"), nameof(StartRequestOperationTests), "WHEN_Operation_is_disposed_SHOULD_track_dependency", It.Is <IAnalyticsOperation>(y => y.Name == "MyOperation"), Sut.CurrentSession, It.IsAny <Dictionary <string, object> >())); MockTelemetryClient.Mock.Verify(x => x.TrackRequest(decoratedRequestTelemetry)); MockConsoleLogger.Mock.Verify(x => x.LogOperation("RequestName", It.IsAny <TimeSpan>())); }
public void IF_properties_is_null_SHOULD_log_empty() { //Arrange MockTelemetryDecorator.Where_Decorate_returns(new TraceTelemetry("Decorated")); //Act Sut.Trace(this, "Trace message", LogSeverity.Verbose, null); //Assert MockTelemetryDecorator.Mock.Verify <TraceTelemetry>(x => x.DecorateTelemetry( It.Is <TraceTelemetry>(y => y.Message == "Trace message"), It.IsAny <string>(), It.IsAny <string>(), null, Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => y.Count == 0))); MockTelemetryClient.Mock.Verify(x => x.TrackTrace(It.Is <TraceTelemetry>(y => y.Message == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogTrace("Trace message", LogSeverity.Verbose, It.Is <Dictionary <string, string> >(y => y.Count == 0))); }
public void IF_properties_null_SHOULD_log_empty() { //Arrange MockTelemetryDecorator.Where_Decorate_returns(new EventTelemetry("Decorated")); //Act Sut.LogEvent(this, "Event Name", null); //Assert MockTelemetryDecorator.Mock.Verify <EventTelemetry>(x => x.DecorateTelemetry( It.Is <EventTelemetry>(y => y.Name == "Event Name"), It.IsAny <string>(), It.IsAny <string>(), null, Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => y.Count == 0))); MockTelemetryClient.Mock.Verify(x => x.TrackEvent(It.Is <EventTelemetry>(y => y.Name == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogEvent("Event Name", It.Is <Dictionary <string, string> >(y => y.Count == 0))); }
public void SHOULD_work_with_extension_string() { //Arrange MockTelemetryDecorator.Where_Decorate_returns(new TraceTelemetry("Decorated")); //Act Sut.TraceVerbose(this, "Trace message", "Property", "value"); //Assert MockTelemetryDecorator.Mock.Verify(x => x.DecorateTelemetry( It.Is <TraceTelemetry>(y => y.Message == "Trace message"), It.IsAny <string>(), It.IsAny <string>(), Sut.CurrentOperation, Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => (string)y["Property"] == "value"))); MockTelemetryClient.Mock.Verify(x => x.TrackTrace(It.Is <TraceTelemetry>(y => y.Message == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogTrace("Trace message", LogSeverity.Verbose, It.Is <Dictionary <string, string> >(y => y["Property"] == "value"))); }
public void SHOULD_work_with_extension_object() { //Arrange MockTelemetryDecorator.Where_Decorate_returns(new TraceTelemetry("Decorated")); var property = new TestObject(); //Act Sut.TraceVerbose(this, "Trace message", property.ToObjectDictionary()); //Assert MockTelemetryDecorator.Mock.Verify(x => x.DecorateTelemetry( It.Is <TraceTelemetry>(y => y.Message == "Trace message"), It.IsAny <string>(), It.IsAny <string>(), Sut.CurrentOperation, Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => (TestObject)y["TestObject"] == property))); MockTelemetryClient.Mock.Verify(x => x.TrackTrace(It.Is <TraceTelemetry>(y => y.Message == "Decorated"))); }
public void WHEN_Operation_is_replaced_SHOULD_track_dependency() { //Arrange Sut.StartPageViewOperation(this, "MyOperation"); MockTelemetryClient.Mock.Verify(x => x.TrackPageView(It.IsAny <PageViewTelemetry>()), Times.Never); MockTelemetryDecorator.Where_Decorate_returns(new PageViewTelemetry("Decorated")); //Act Sut.StartPageViewOperation(this, "New"); //Assert MockTelemetryDecorator.Mock.Verify <PageViewTelemetry>(x => x.DecorateTelemetry( It.Is <PageViewTelemetry>(y => y.Name == "MyOperation"), It.IsAny <string>(), "WHEN_Operation_is_replaced_SHOULD_track_dependency", It.Is <IAnalyticsOperation>(y => y.Name == "MyOperation"), Sut.CurrentSession, It.IsAny <Dictionary <string, object> >())); MockTelemetryClient.Mock.Verify(x => x.TrackPageView(It.Is <PageViewTelemetry>(y => y.Name == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogOperation("MyOperation", It.IsAny <TimeSpan>())); }
public void SHOULD_decorate_telemetry_and_log_to_console_and_server() { //Arrange var properties = new Dictionary <string, object> { { "Property", "value" } }; MockTelemetryDecorator.Where_Decorate_returns(new EventTelemetry("Decorated")); //Act Sut.LogEvent(this, "Event Name", properties); //Assert MockTelemetryDecorator.Mock.Verify <EventTelemetry>(x => x.DecorateTelemetry( It.Is <EventTelemetry>(y => y.Name == "Event Name"), It.IsAny <string>(), It.IsAny <string>(), Sut.CurrentOperation, Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => (string)y["Property"] == "value"))); MockTelemetryClient.Mock.Verify(x => x.TrackEvent(It.Is <EventTelemetry>(y => y.Name == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogEvent("Event Name", It.Is <Dictionary <string, string> >(y => y["Property"] == "value"))); }
public void IF_PageName_is_empty_SHOULD_use_class_name() { //Arrange var operation = Sut.StartPageViewOperation(this); MockTelemetryClient.Mock.Verify(x => x.TrackPageView(It.IsAny <PageViewTelemetry>()), Times.Never); MockTelemetryDecorator.Where_Decorate_returns(new PageViewTelemetry("Decorated")); //Act operation.Dispose(); //Assert MockTelemetryDecorator.Mock.Verify <PageViewTelemetry>(x => x.DecorateTelemetry( It.Is <PageViewTelemetry>(y => y.Name == GetType().Name), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IAnalyticsOperation>(), Sut.CurrentSession, It.IsAny <Dictionary <string, object> >())); MockTelemetryClient.Mock.Verify(x => x.TrackPageView(It.Is <PageViewTelemetry>(y => y.Name == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogOperation(GetType().Name, It.IsAny <TimeSpan>())); }
public void IF_Operation_details_not_provided_WHEN_Operation_is_disposed_SHOULD_log_new_operation() { //Arrange var operation = Sut.StartRequestOperation(this, "RequestName", new Dictionary <string, string>()); var decoratedRequestTelemetry = new RequestTelemetry(); MockTelemetryDecorator.Where_Decorate_returns(decoratedRequestTelemetry); //Act operation.Dispose(); //Assert MockTelemetryDecorator.Mock.Verify <RequestTelemetry>(x => x.DecorateTelemetry( It.Is <RequestTelemetry>(y => y.Name == "RequestName"), nameof(StartRequestOperationTests), "IF_Operation_details_not_provided_WHEN_Operation_is_disposed_SHOULD_log_new_operation", It.Is <IAnalyticsOperation>(y => y.Name == "NewRequest"), Sut.CurrentSession, It.IsAny <Dictionary <string, object> >())); MockTelemetryClient.Mock.Verify(x => x.TrackRequest(decoratedRequestTelemetry)); MockConsoleLogger.Mock.Verify(x => x.LogOperation("RequestName", It.IsAny <TimeSpan>())); }
public void SHOULD_decorate_telemetry_and_log_to_console_and_server() { //Arrange var properties = new Dictionary <string, object> { { "Property", "value" } }; var exception = new ArgumentException("oops"); MockTelemetryDecorator.Where_Decorate_returns(new ExceptionTelemetry(exception)); //Act Sut.LogException(this, exception, properties); //Assert MockTelemetryDecorator.Mock.Verify(x => x.DecorateTelemetry( It.Is <ExceptionTelemetry>(y => y.Exception == exception), It.IsAny <string>(), It.IsAny <string>(), Sut.CurrentOperation, Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => (string)y["Property"] == "value" && (string)y["ExceptionType"] == "System.ArgumentException"))); MockTelemetryClient.Mock.Verify(x => x.TrackException(It.Is <ExceptionTelemetry>(y => y.Exception == exception))); MockConsoleLogger.Mock.Verify(x => x.LogException(exception, It.Is <Dictionary <string, string> >(y => y["Property"] == "value"))); }
public void SHOULD_decorate_telemetry_and_log_to_console_and_server() { //Arrange var properties = new Dictionary <string, object> { { "Property", "value" } }; MockTelemetryDecorator.Where_Decorate_returns(new TraceTelemetry("Decorated")); //Act Sut.Trace(this, "Trace message", LogSeverity.Critical, properties); //Assert MockTelemetryDecorator.Mock.Verify(x => x.DecorateTelemetry( It.Is <TraceTelemetry>(y => y.Message == "Trace message" && y.SeverityLevel == SeverityLevel.Critical), It.IsAny <string>(), It.IsAny <string>(), Sut.CurrentOperation, Sut.CurrentSession, It.Is <Dictionary <string, object> >(y => (string)y["Property"] == "value"))); MockTelemetryClient.Mock.Verify(x => x.TrackTrace(It.Is <TraceTelemetry>(y => y.Message == "Decorated"))); MockConsoleLogger.Mock.Verify(x => x.LogTrace("Trace message", LogSeverity.Critical, It.Is <Dictionary <string, string> >(y => y["Property"] == "value"))); }