public void SecondCleanupFixesBrokenFirstCleanup() { StreamWriter writer = null; string parent; try { using (var tempFiles = new TemporaryFiles(MockBuilder.StatelessServiceContext(), NullLogger <TemporaryFiles> .Instance)) { tempFiles.Initialize(); string testPath = tempFiles.GetFilePath("asdfpoiu"); writer = File.CreateText(testPath); } } finally { writer?.Dispose(); } using (var tempFiles = new TemporaryFiles(MockBuilder.StatelessServiceContext(), NullLogger <TemporaryFiles> .Instance)) { tempFiles.Initialize(); string testPath = tempFiles.GetFilePath("asdfpoiu"); parent = Path.GetDirectoryName(testPath); } Directory.Exists(parent).Should().BeFalse(); }
public void LogsCorrectUrl() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], Mock.Of <IFakeService>(), new LoggingServiceInterceptor(ctx, client)); impl.TestServiceMethod(); client.Flush(); RequestTelemetry requestTelemetry = telemetryChannel.Telemetry.OfType <RequestTelemetry>().FirstOrDefault(); requestTelemetry.Should().NotBeNull(); (requestTelemetry.Success ?? true).Should().BeTrue(); requestTelemetry.Url.AbsoluteUri.Should().StartWith(ctx.ServiceName.AbsoluteUri); requestTelemetry.Url.AbsoluteUri.Should().Contain(nameof(IFakeService)); telemetryChannel.Telemetry.OfType <ExceptionTelemetry>().Should().BeEmpty(); }
public void SetsDependencyData() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], Mock.Of <IFakeService>(), new LoggingServiceProxyInterceptor(client, ctx, "other://uri.test")); impl.TestServiceMethod(); client.Flush(); List <DependencyTelemetry> dependencyTelemetries = telemetryChannel.Telemetry.OfType <DependencyTelemetry>().ToList(); dependencyTelemetries.Should().ContainSingle(); DependencyTelemetry dependencyTelemetry = dependencyTelemetries[0]; (dependencyTelemetry.Success ?? true).Should().BeTrue(); dependencyTelemetry.Type.Should().Be("ServiceFabricRemoting"); dependencyTelemetry.Target.Should().Be("other://uri.test"); dependencyTelemetry.Data.Should().StartWith("other://uri.test"); dependencyTelemetry.Data.Should().Contain(nameof(IFakeService)); dependencyTelemetry.Data.Should().Contain(nameof(IFakeService.TestServiceMethod)); telemetryChannel.Telemetry.OfType <ExceptionTelemetry>().Should().BeEmpty(); }
public void SetsDependencyData() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], Mock.Of <IFakeService>(), new LoggingServiceProxyInterceptor(client, ctx, "other://uri.test")); impl.TestServiceMethod(); client.Flush(); List <DependencyTelemetry> dependencyTelemetries = telemetryChannel.Telemetry.OfType <DependencyTelemetry>().ToList(); Assert.Single(dependencyTelemetries); DependencyTelemetry dependencyTelemetry = dependencyTelemetries[0]; Assert.True(dependencyTelemetry.Success ?? true); Assert.Equal("ServiceFabricRemoting", dependencyTelemetry.Type); Assert.Equal("other://uri.test", dependencyTelemetry.Target); Assert.StartsWith("other://uri.test", dependencyTelemetry.Data); Assert.Contains(nameof(IFakeService), dependencyTelemetry.Data, StringComparison.OrdinalIgnoreCase); Assert.Contains(nameof(IFakeService.TestServiceMethod), dependencyTelemetry.Data, StringComparison.OrdinalIgnoreCase); Assert.Empty(telemetryChannel.Telemetry.OfType <ExceptionTelemetry>()); }
public void LogsCorrectUrl() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], Mock.Of <IFakeService>(), new LoggingServiceInterceptor(ctx, client)); impl.TestServiceMethod(); client.Flush(); RequestTelemetry requestTelemetry = telemetryChannel.Telemetry.OfType <RequestTelemetry>().FirstOrDefault(); Assert.NotNull(requestTelemetry); Assert.True(requestTelemetry.Success ?? true); Assert.StartsWith(ctx.ServiceName.AbsoluteUri, requestTelemetry.Url.AbsoluteUri, StringComparison.OrdinalIgnoreCase); Assert.Contains(nameof(IFakeService), requestTelemetry.Url.AbsoluteUri, StringComparison.OrdinalIgnoreCase); Assert.Empty(telemetryChannel.Telemetry.OfType <ExceptionTelemetry>()); }
public void PreInitializeIsNoop() { using (var tempFiles = new TemporaryFiles(MockBuilder.StatelessServiceContext(), NullLogger <TemporaryFiles> .Instance)) { string testPath = tempFiles.GetFilePath("asdfpoiu"); string parent = Path.GetDirectoryName(testPath); Directory.Exists(parent).Should().BeFalse(); } }
public void InitializeCreatedRoot() { using (var tempFiles = new TemporaryFiles(MockBuilder.StatelessServiceContext(), NullLogger <TemporaryFiles> .Instance)) { tempFiles.Initialize(); string testPath = tempFiles.GetFilePath("asdfpoiu"); string parent = Path.GetDirectoryName(testPath); Assert.True(Directory.Exists(parent)); } }
private static void CleanTempFolderForTest() { using (var tempFiles = new TemporaryFiles(MockBuilder.StatelessServiceContext(), NullLogger <TemporaryFiles> .Instance)) { tempFiles.Initialize(); string testPath = tempFiles.GetFilePath("asdfpoiu"); string parent = Path.GetDirectoryName(testPath); if (Directory.Exists(parent)) { Directory.Delete(parent); } } }
public void DisposeCleansUp() { string parent; using (var tempFiles = new TemporaryFiles(MockBuilder.StatelessServiceContext(), NullLogger <TemporaryFiles> .Instance)) { tempFiles.Initialize(); string testPath = tempFiles.GetFilePath("asdfpoiu"); File.WriteAllText(testPath, "Test content"); parent = Path.GetDirectoryName(testPath); } Directory.Exists(parent).Should().BeFalse(); }
public void ComplexAggregateExceptionIsReported() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); var service = new Mock <IFakeService>(); service.Setup(s => s.TestServiceMethod()) .Throws(new AggregateException(new InvalidOperationException("Test exception text"), new InvalidOperationException("Another test exception text"))); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], service.Object, new LoggingServiceProxyInterceptor(client, ctx, "other://uri.test")); var invocationException = Assert.Throws <AggregateException>(() => impl.TestServiceMethod()); client.Flush(); List <DependencyTelemetry> dependencyTelemetries = telemetryChannel.Telemetry.OfType <DependencyTelemetry>().ToList(); Assert.Single(dependencyTelemetries); DependencyTelemetry dependencyTelemetry = dependencyTelemetries[0]; Assert.False(dependencyTelemetry.Success); Assert.Equal("ServiceFabricRemoting", dependencyTelemetry.Type); Assert.Equal("other://uri.test", dependencyTelemetry.Target); Assert.StartsWith("other://uri.test", dependencyTelemetry.Data); Assert.Contains(nameof(IFakeService), dependencyTelemetry.Data, StringComparison.OrdinalIgnoreCase); Assert.Contains(nameof(IFakeService.TestServiceMethod), dependencyTelemetry.Data, StringComparison.OrdinalIgnoreCase); List <ExceptionTelemetry> exceptionTelemetries = telemetryChannel.Telemetry.OfType <ExceptionTelemetry>().ToList(); Assert.Single(exceptionTelemetries); ExceptionTelemetry exceptionTelemetry = exceptionTelemetries[0]; Assert.Same(invocationException, exceptionTelemetry.Exception); }
public void ComplexAggregateExceptionIsReported() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); var service = new Mock <IFakeService>(); service.Setup(s => s.TestServiceMethod()) .Throws(new AggregateException(new InvalidOperationException("Test exception text"), new InvalidOperationException("Another test exception text"))); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], service.Object, new LoggingServiceProxyInterceptor(client, ctx, "other://uri.test")); var invocationException = (((Func <object>)(() => impl.TestServiceMethod()))).Should().Throw <AggregateException>().Which; client.Flush(); List <DependencyTelemetry> dependencyTelemetries = telemetryChannel.Telemetry.OfType <DependencyTelemetry>().ToList(); dependencyTelemetries.Should().ContainSingle(); DependencyTelemetry dependencyTelemetry = dependencyTelemetries[0]; dependencyTelemetry.Success.Should().BeFalse(); dependencyTelemetry.Type.Should().Be("ServiceFabricRemoting"); dependencyTelemetry.Target.Should().Be("other://uri.test"); dependencyTelemetry.Data.Should().StartWith("other://uri.test"); dependencyTelemetry.Data.Should().Contain(nameof(IFakeService)); dependencyTelemetry.Data.Should().Contain(nameof(IFakeService.TestServiceMethod)); List <ExceptionTelemetry> exceptionTelemetries = telemetryChannel.Telemetry.OfType <ExceptionTelemetry>().ToList(); exceptionTelemetries.Should().ContainSingle(); ExceptionTelemetry exceptionTelemetry = exceptionTelemetries[0]; exceptionTelemetry.Exception.Should().BeSameAs(invocationException); }
public void CleanupResilientToOpenHandles() { StreamWriter writer = null; try { string parent; using (var tempFiles = new TemporaryFiles(MockBuilder.StatelessServiceContext(), NullLogger <TemporaryFiles> .Instance)) { tempFiles.Initialize(); string testPath = tempFiles.GetFilePath("asdfpoiu"); writer = File.CreateText(testPath); parent = Path.GetDirectoryName(testPath); } Directory.Exists(parent).Should().BeTrue(); } finally { writer?.Dispose(); } }
public void ExceptionLogsFailedRequest() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); Mock <IFakeService> fakeService = new Mock <IFakeService>(); fakeService.Setup(s => s.TestServiceMethod()).Throws(new InvalidOperationException("Test Exception Text")); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], fakeService.Object, new LoggingServiceInterceptor(ctx, client)); var ex = (((Func <object>)(() => impl.TestServiceMethod()))).Should().Throw <InvalidOperationException>().Which; ex.Message.Should().Be("Test Exception Text"); client.Flush(); List <RequestTelemetry> requestTelemetries = telemetryChannel.Telemetry.OfType <RequestTelemetry>().ToList(); requestTelemetries.Should().ContainSingle(); RequestTelemetry requestTelemetry = requestTelemetries[0]; requestTelemetry.Success.Should().BeFalse(); ExceptionTelemetry exceptionTelemetry = telemetryChannel.Telemetry.OfType <ExceptionTelemetry>().FirstOrDefault(); exceptionTelemetry.Should().NotBeNull(); exceptionTelemetry.Exception.Should().BeSameAs(ex); }
public void ExceptionLogsFailedRequest() { var telemetryChannel = new FakeChannel(); var config = new TelemetryConfiguration("00000000-0000-0000-0000-000000000001", telemetryChannel); var client = new TelemetryClient(config); StatelessServiceContext ctx = MockBuilder.StatelessServiceContext(); Mock <IFakeService> fakeService = new Mock <IFakeService>(); fakeService.Setup(s => s.TestServiceMethod()).Throws(new InvalidOperationException("Test Exception Text")); var gen = new ProxyGenerator(); var impl = (IFakeService)gen.CreateInterfaceProxyWithTargetInterface( typeof(IFakeService), new Type[0], fakeService.Object, new LoggingServiceInterceptor(ctx, client)); var ex = Assert.ThrowsAny <InvalidOperationException>(() => impl.TestServiceMethod()); Assert.Equal("Test Exception Text", ex.Message); client.Flush(); List <RequestTelemetry> requestTelemetries = telemetryChannel.Telemetry.OfType <RequestTelemetry>().ToList(); Assert.Single(requestTelemetries); RequestTelemetry requestTelemetry = requestTelemetries[0]; Assert.False(requestTelemetry.Success); ExceptionTelemetry exceptionTelemetry = telemetryChannel.Telemetry.OfType <ExceptionTelemetry>().FirstOrDefault(); Assert.NotNull(exceptionTelemetry); Assert.Same(ex, exceptionTelemetry.Exception); }