public void WhenSetToFalseChangesTelemetryBufferCapacityToOriginalValueForBufferedTransmission()
            {
                var channel = new ServerTelemetryChannel();
                int originalTelemetryBufferSize = channel.TelemetryBuffer.Capacity;

                channel.DeveloperMode = true;
                channel.DeveloperMode = false;

                Assert.Equal(originalTelemetryBufferSize, channel.TelemetryBuffer.Capacity);
            }
            public void InitializesTransmitterWithNetworkAvailabilityPolicy()
            {
                var network = new StubNetwork { OnIsAvailable = () => false };

                var channel = new ServerTelemetryChannel(network, new StubApplicationLifecycle());
                channel.Initialize(new TelemetryConfiguration());
                Thread.Sleep(50);

                Assert.Equal(0, channel.Transmitter.Sender.Capacity);
            }
            public void PassesTelemetryToTelemetryProcessor()
            {
                ITelemetry sentTelemetry = null;
                var channel = new ServerTelemetryChannel();
                channel.Initialize(TelemetryConfiguration.CreateDefault());
                channel.TelemetryProcessor = new StubTelemetryProcessor(null) { OnProcess = (t) => sentTelemetry = t };

                var telemetry = new StubTelemetry();
                channel.Send(telemetry);

                Assert.Equal(telemetry, sentTelemetry);
            }
            public void InitializeCallsTransmitterInitialize()
            {
                var transmitterInitialized = new ManualResetEvent(false);
                var transmitter = new StubTransmitter();
                transmitter.OnInitialize = () =>
                {
                    transmitterInitialized.Set();
                };
                var channel = new ServerTelemetryChannel { Transmitter = transmitter };

                var initializedConfiguration = new TelemetryConfiguration();
                channel.Initialize(initializedConfiguration);

                Assert.True(transmitterInitialized.WaitOne(1000));
            }
            public void AppliesTransmissionPoliciesToBeginSendingStoredTelemetry()
            {
                var transmissionPoliciesApplied = new ManualResetEvent(false);
                var transmitter = new StubTransmitter();
                transmitter.OnApplyPolicies = () =>
                {
                    transmissionPoliciesApplied.Set();
                };
                var channel = new ServerTelemetryChannel { Transmitter = transmitter };
                channel.Initialize(TelemetryConfiguration.CreateDefault());

                var initializedConfiguration = new TelemetryConfiguration();
                channel.Initialize(initializedConfiguration);

                Assert.True(transmissionPoliciesApplied.WaitOne(1000));
            }
            public void WaitsForAsynchronousFlushToCompleteAndAllowsItsExceptionsToBubbleUp()
            {
                var expectedException = new Exception();
                var tcs = new TaskCompletionSource<object>();
                tcs.SetException(expectedException);
                var mockTelemetryBuffer = new Mock<TelemetryChannel.Implementation.TelemetryBuffer>();
                mockTelemetryBuffer.Setup(x => x.FlushAsync()).Returns(tcs.Task);
                var channel = new ServerTelemetryChannel { TelemetryBuffer = mockTelemetryBuffer.Object };
                channel.Initialize(TelemetryConfiguration.CreateDefault());

                var actualException = Assert.Throws<Exception>(() => channel.Flush());

                Assert.Same(expectedException, actualException);
            }
            public void PassesTelemetryToTelemetryProcessor()
            {
                ITelemetry sentTelemetry = null;
                var channel = new ServerTelemetryChannel();
                channel.TelemetryProcessor = new StubTelemetryProcessor(null) { OnProcess = (t) => sentTelemetry = t };

                var telemetry = new StubTelemetry();
                channel.Send(telemetry);

                Assert.Equal(telemetry, sentTelemetry);
            }
 public void DeveloperModeCanBeModifiedByConfiguration()
 {
     var channel = new ServerTelemetryChannel();             
     channel.DeveloperMode = true;
     Assert.True(channel.DeveloperMode.Value);
 }
 public void ChangesMaxSenderCapacityOfTransmitter()
 {
     var channel = new ServerTelemetryChannel { Transmitter = new StubTransmitter() };
     channel.MaxTransmissionSenderCapacity = 42;
     Assert.Equal(42, channel.Transmitter.MaxSenderCapacity);
 }
 public void ReturnsMaxBufferCapacityOfTransmitter()
 {
     var channel = new ServerTelemetryChannel { Transmitter = new StubTransmitter() };
     channel.Transmitter.MaxBufferCapacity = 42;
     Assert.Equal(42, channel.MaxTransmissionBufferCapacity);
 }
 public void SetterChangesTelemetryBufferCapacity()
 {
     var channel = new ServerTelemetryChannel();
     channel.MaxTelemetryBufferCapacity = 42;
     Assert.Equal(42, channel.TelemetryBuffer.Capacity);
 }
            public void DataUploadIntervalInSecondsIsStoredByTelemetryBuffer()
            {
                var channel = new ServerTelemetryChannel();
               
                TimeSpan expectedUploadInterval = TimeSpan.FromSeconds(42);
                channel.MaxTelemetryBufferDelay = expectedUploadInterval;

                Assert.Equal(expectedUploadInterval, channel.MaxTelemetryBufferDelay);
            }
 public void EndpointAddressIsStoredBySerializer()
 {
     var channel = new ServerTelemetryChannel();
     
     Uri expectedEndpoint = new Uri("http://abc.com");
     channel.EndpointAddress = expectedEndpoint.AbsoluteUri;
     
     Assert.Equal(expectedEndpoint, channel.TelemetrySerializer.EndpointAddress);
 }
            public void EndpointAddressCanBeModifiedByConfiguration()
            {
                var channel = new ServerTelemetryChannel();
               
                Uri expectedEndpoint = new Uri("http://abc.com");
                channel.EndpointAddress = expectedEndpoint.AbsoluteUri;

                Assert.Equal(expectedEndpoint, new Uri(channel.EndpointAddress));
            }
 public void SetterChangesStorageCapacityOfTransmitter()
 {
     var channel = new ServerTelemetryChannel { Transmitter = new StubTransmitter() };
     channel.MaxTransmissionStorageCapacity = 42000;
     Assert.Equal(42000, channel.Transmitter.MaxStorageCapacity);
 }
 public void DeveloperModeIsNullByDefault()
 {
     var channel = new ServerTelemetryChannel();
     Assert.Null(channel.DeveloperMode);
 }
 public void SetterChangesStorageFolderOfTransmitter()
 {
     var channel = new ServerTelemetryChannel { Transmitter = new StubTransmitter() };
     channel.StorageFolder = "test";
     Assert.Equal("test", channel.Transmitter.StorageFolder);
 }
 public void WhenSetToTrueChangesTelemetryBufferCapacityToOneForImmediateTransmission()
 {
     var channel = new ServerTelemetryChannel();
     channel.DeveloperMode = true;
     Assert.Equal(1, channel.TelemetryBuffer.Capacity);
 }
            public void FlushesTelemetryBuffer()
            {
                var mockTelemetryBuffer = new Mock<TelemetryChannel.Implementation.TelemetryBuffer>();
                var channel = new ServerTelemetryChannel { TelemetryBuffer = mockTelemetryBuffer.Object };
                channel.Initialize(TelemetryConfiguration.CreateDefault());

                channel.Flush();

                mockTelemetryBuffer.Verify(x => x.FlushAsync());
            }
            public void DoesNotModifyComponentConfigurationWhenNewValueIsSameAsOldValue()
            {
                var channel = new ServerTelemetryChannel();
                int oldTelemetryBufferSize = channel.TelemetryBuffer.Capacity;

                channel.DeveloperMode = false;

                Assert.Equal(oldTelemetryBufferSize, channel.TelemetryBuffer.Capacity);
            }
            public void FlushesTelemetryBuffer()
            {
                var mockTelemetryBuffer = new Mock<TelemetryBuffer>();
                var channel = new ServerTelemetryChannel { TelemetryBuffer = mockTelemetryBuffer.Object };

                channel.Flush();

                mockTelemetryBuffer.Verify(x => x.FlushAsync());
            }