Ejemplo n.º 1
0
        public async Task NoEventsTest()
        {
            // Arrange / act
            var deviceConnectivityManager = new DeviceConnectivityManager(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3));

            var client = new Mock <IClient>();

            client.SetupSequence(c => c.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>()))
            .Returns(Task.CompletedTask)
            .Throws <TimeoutException>()
            .Throws <TimeoutException>()
            .Returns(Task.CompletedTask);
            IClient connectivityAwareClient = new ConnectivityAwareClient(client.Object, deviceConnectivityManager);
            var     cloudProxy = new CloudProxy(connectivityAwareClient, Mock.Of <IMessageConverterProvider>(), "d1/m1", null, Mock.Of <ICloudListener>(), TimeSpan.FromHours(1));

            deviceConnectivityManager.SetTestCloudProxy(cloudProxy);

            bool connected = false;

            deviceConnectivityManager.DeviceConnected    += (_, __) => connected = true;
            deviceConnectivityManager.DeviceDisconnected += (_, __) => connected = false;

            // Assert
            await Task.Delay(TimeSpan.FromSeconds(4));

            Assert.True(connected);

            await Task.Delay(TimeSpan.FromSeconds(4));

            Assert.False(connected);

            await Task.Delay(TimeSpan.FromSeconds(4));

            Assert.True(connected);
        }
Ejemplo n.º 2
0
        public async Task ConnectivityTestFailedTest()
        {
            // Arrange / act
            var deviceConnectivityManager = new DeviceConnectivityManager(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3));

            var client = new Mock <IClient>();

            client.SetupSequence(c => c.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>()))
            .Returns(Task.CompletedTask)
            .Throws <TimeoutException>()
            .Returns(Task.CompletedTask)
            .Throws <TimeoutException>()
            .Returns(Task.CompletedTask);
            IClient connectivityAwareClient = new ConnectivityAwareClient(client.Object, deviceConnectivityManager);
            var     cloudProxy = new CloudProxy(connectivityAwareClient, Mock.Of <IMessageConverterProvider>(), "d1/m1", null);

            deviceConnectivityManager.SetTestCloudProxy(cloudProxy);

            int connected    = 0;
            int disconnected = 0;

            deviceConnectivityManager.DeviceConnected    += (_, __) => Interlocked.Increment(ref connected);
            deviceConnectivityManager.DeviceDisconnected += (_, __) => Interlocked.Increment(ref disconnected);

            // Assert
            await Task.Delay(TimeSpan.FromSeconds(15));

            Assert.Equal(1, connected);
            Assert.Equal(0, disconnected);
        }
Ejemplo n.º 3
0
        public async Task TestCloseOnInactiveDisabled()
        {
            // Arrange
            var  client         = new Mock <IClient>();
            bool isClientActive = true;

            client.Setup(c => c.CloseAsync())
            .Callback(() => isClientActive = false)
            .Returns(Task.CompletedTask);
            client.SetupGet(c => c.IsActive).Returns(() => isClientActive);
            client.Setup(c => c.SendEventAsync(It.IsAny <Message>())).Returns(Task.CompletedTask);

            var messageConverter = new Mock <IMessageConverter <Message> >();

            messageConverter.Setup(m => m.FromMessage(It.IsAny <IMessage>()))
            .Returns(new Message());

            var messageConverterProvider = new Mock <IMessageConverterProvider>();

            messageConverterProvider.Setup(m => m.Get <Message>())
            .Returns(messageConverter.Object);

            var         cloudListener = new Mock <ICloudListener>();
            TimeSpan    idleTimeout   = TimeSpan.FromSeconds(5);
            ICloudProxy cloudProxy    = new CloudProxy(client.Object, messageConverterProvider.Object, "device1", null, cloudListener.Object, idleTimeout, false);

            // Act
            await Task.Delay(TimeSpan.FromSeconds(6));

            // Assert
            Assert.True(cloudProxy.IsActive);
            Assert.True(isClientActive);
            client.Verify(c => c.CloseAsync(), Times.Never);
        }
Ejemplo n.º 4
0
        public async Task TestHandleFailOverExceptions()
        {
            // Arrange
            var symbol            = new Amqp.Encoding.AmqpSymbol("com.microsoft:iot-hub-not-found-error");
            var failOverException = new IotHubException(new Amqp.AmqpException(symbol, $"(condition='{symbol}')"));

            var      messageConverter         = Mock.Of <IMessageConverter <Message> >(m => m.FromMessage(It.IsAny <IMessage>()) == new Message());
            var      messageConverterProvider = Mock.Of <IMessageConverterProvider>(m => m.Get <Message>() == messageConverter);
            string   clientId      = "d1";
            var      cloudListener = Mock.Of <ICloudListener>();
            TimeSpan idleTimeout   = TimeSpan.FromSeconds(60);
            Action <string, CloudConnectionStatus> connectionStatusChangedHandler = (s, status) => { };
            var client = new Mock <IClient>(MockBehavior.Strict);

            client.Setup(c => c.SendEventAsync(It.IsAny <Message>())).ThrowsAsync(failOverException);
            client.Setup(c => c.CloseAsync()).Returns(Task.CompletedTask);
            var      cloudProxy = new CloudProxy(client.Object, messageConverterProvider, clientId, connectionStatusChangedHandler, cloudListener, idleTimeout, false);
            IMessage message    = new EdgeMessage.Builder(new byte[0]).Build();

            // Act
            await Assert.ThrowsAsync <IotHubException>(() => cloudProxy.SendMessageAsync(message));

            // Assert.
            client.VerifyAll();
        }
Ejemplo n.º 5
0
        public void CloudReceiverCanProcessAMessage()
        {
            //Arrange
            var sampleMessage = Mock.Of <IMessage>();

            var messageConverter = new  Mock <IMessageConverter <Client.Message> >();

            messageConverter.Setup(p => p.ToMessage(It.IsAny <Client.Message>())).Returns(sampleMessage);

            var messageConverterProvider = new Mock <IMessageConverterProvider>();

            messageConverterProvider.Setup(p => p.Get <Client.Message>()).Returns(messageConverter.Object);

            var identity     = Mock.Of <IIdentity>(i => i.Id == "device1");
            var deviceClient = new Mock <IClient>();

            deviceClient.Setup(p => p.ReceiveAsync(It.IsAny <TimeSpan>())).ReturnsAsync(new Client.Message(new byte[0]));

            var cloudProxy    = new CloudProxy(deviceClient.Object, messageConverterProvider.Object, identity.Id, (id, s) => { });
            var cloudListener = new Mock <ICloudListener>();

            var cloudReceiver = new CloudProxy.CloudReceiver(cloudProxy, cloudListener.Object);

            cloudListener.Setup(p => p.ProcessMessageAsync(It.IsAny <IMessage>()))
            .Returns(Task.CompletedTask)
            .Callback(() => cloudReceiver.CloseAsync());

            //Act
            cloudReceiver.StartListening();

            //Assert
            cloudListener.Verify(m => m.ProcessMessageAsync(sampleMessage));
        }
        public async Task ConnectivityTestFailedTest()
        {
            // Arrange / act
            var deviceIdentity            = Mock.Of <IIdentity>(i => i.Id == "d2");
            var edgeHubIdentity           = Mock.Of <IIdentity>(i => i.Id == "d1/m1");
            var deviceConnectivityManager = new DeviceConnectivityManager(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3), edgeHubIdentity);

            var client = new Mock <IClient>();

            client.SetupSequence(c => c.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>()))
            .Returns(Task.CompletedTask)
            .Throws <TimeoutException>()
            .Returns(Task.CompletedTask)
            .Throws <TimeoutException>()
            .Returns(Task.CompletedTask);
            IClient     connectivityAwareClient = new ConnectivityAwareClient(client.Object, deviceConnectivityManager, deviceIdentity);
            ICloudProxy cloudProxy        = new CloudProxy(connectivityAwareClient, Mock.Of <IMessageConverterProvider>(), "d1/m1", null, Mock.Of <ICloudListener>(), TimeSpan.FromHours(1), true);
            var         connectionManager = Mock.Of <IConnectionManager>(c => c.GetCloudConnection("d1/m1") == Task.FromResult(Option.Some(cloudProxy)));

            deviceConnectivityManager.SetConnectionManager(connectionManager);

            int connected    = 0;
            int disconnected = 0;

            deviceConnectivityManager.DeviceConnected    += (_, __) => Interlocked.Increment(ref connected);
            deviceConnectivityManager.DeviceDisconnected += (_, __) => Interlocked.Increment(ref disconnected);

            // Assert
            await Task.Delay(TimeSpan.FromSeconds(15));

            Assert.Equal(1, connected);
            Assert.Equal(0, disconnected);
        }
Ejemplo n.º 7
0
        public void CloudReceiverIgnoresOtherExceptionsWhenReceivingMessages()
        {
            //Arrange
            var messageConverter = new Mock <IMessageConverter <Client.Message> >();

            messageConverter.Setup(p => p.ToMessage(It.IsAny <Client.Message>())).Returns <IMessage>(null);

            var messageConverterProvider = new Mock <IMessageConverterProvider>();

            messageConverterProvider.Setup(p => p.Get <Client.Message>()).Returns(messageConverter.Object);

            var identity     = Mock.Of <IIdentity>(i => i.Id == "device1");
            var deviceClient = new Mock <IClient>();

            deviceClient.Setup(p => p.ReceiveAsync(It.IsAny <TimeSpan>())).ReturnsAsync(new Client.Message(new byte[0]));

            var cloudProxy    = new CloudProxy(deviceClient.Object, messageConverterProvider.Object, identity.Id, (id, s) => { });
            var cloudListener = new Mock <ICloudListener>();

            var cloudReceiver = new CloudProxy.CloudReceiver(cloudProxy, cloudListener.Object);

            cloudListener.Setup(p => p.ProcessMessageAsync(It.IsAny <IMessage>()))
            .Callback(() => cloudReceiver.CloseAsync())
            .Throws(new Exception());

            //Act
            cloudReceiver.StartListening(); //Exception expected to be handled and not thrown.

            //Assert
            cloudListener.Verify(m => m.ProcessMessageAsync(null));
        }
Ejemplo n.º 8
0
        public void ConstructorWithNullCloudListenerThrow()
        {
            //Arrange
            var messageConverter = new Mock <IMessageConverterProvider>();
            var deviceClient     = Mock.Of <IClient>();
            var cloudProxy       = new CloudProxy(deviceClient, messageConverter.Object, "device1", (id, s) => { });

            //Act
            //Assert
            Assert.Throws <ArgumentNullException>(() => new CloudProxy.CloudReceiver(cloudProxy, null));
        }
Ejemplo n.º 9
0
        public async Task TestCloseOnInactive()
        {
            // Arrange
            var  client         = new Mock <IClient>();
            bool isClientActive = true;

            client.Setup(c => c.CloseAsync())
            .Callback(() => isClientActive = false)
            .Returns(Task.CompletedTask);
            client.SetupGet(c => c.IsActive).Returns(() => isClientActive);
            client.Setup(c => c.SendEventAsync(It.IsAny <Message>())).Returns(Task.CompletedTask);

            var messageConverter = new Mock <IMessageConverter <Message> >();

            messageConverter.Setup(m => m.FromMessage(It.IsAny <IMessage>()))
            .Returns(new Message());

            var messageConverterProvider = new Mock <IMessageConverterProvider>();

            messageConverterProvider.Setup(m => m.Get <Message>())
            .Returns(messageConverter.Object);

            var         cloudListener = new Mock <ICloudListener>();
            TimeSpan    idleTimeout   = TimeSpan.FromSeconds(5);
            var         message       = new EdgeMessage(new byte[0], new Dictionary <string, string>(), new Dictionary <string, string>());
            ICloudProxy cloudProxy    = new CloudProxy(client.Object, messageConverterProvider.Object, "device1", null, cloudListener.Object, idleTimeout, true);

            // Act
            for (int i = 0; i < 5; i++)
            {
                await cloudProxy.SendMessageAsync(message);

                await Task.Delay(TimeSpan.FromSeconds(3));
            }

            // Assert
            Assert.True(cloudProxy.IsActive);
            Assert.True(isClientActive);

            // Act
            await Task.Delay(TimeSpan.FromSeconds(5));

            // Assert
            Assert.False(cloudProxy.IsActive);
            Assert.False(isClientActive);
            client.Verify(c => c.CloseAsync(), Times.Once);

            // Act
            await Task.Delay(TimeSpan.FromSeconds(6));

            // Assert
            client.Verify(c => c.CloseAsync(), Times.Once);
        }
Ejemplo n.º 10
0
        public void ConstructorHappyPath()
        {
            //Arrange
            var messageConverter = new Mock <IMessageConverterProvider>();
            var identity         = Mock.Of <IIdentity>(i => i.Id == "device1");
            var deviceClient     = Mock.Of <IClient>();
            var cloudProxy       = new CloudProxy(deviceClient, messageConverter.Object, identity.Id, (id, s) => { });
            var cloudListener    = new Mock <ICloudListener>();

            //Act
            var cloudReceive = new CloudProxy.CloudReceiver(cloudProxy, cloudListener.Object);

            //Assert
            Assert.NotNull(cloudReceive);
        }
Ejemplo n.º 11
0
        public async Task TestDisableTimerOnC2DSubscription()
        {
            // Arrange
            var  client         = new Mock <IClient>();
            bool isClientActive = true;

            client.Setup(c => c.CloseAsync())
            .Callback(() => isClientActive = false)
            .Returns(Task.CompletedTask);
            client.SetupGet(c => c.IsActive).Returns(() => isClientActive);
            client.Setup(c => c.ReceiveAsync(It.IsAny <TimeSpan>()))
            // .Callback<TimeSpan>(t => Task.Yield())
            .Returns(Task.FromResult <Message>(new Message()));

            var messageConverter = new Mock <IMessageConverter <Message> >();

            messageConverter.Setup(m => m.FromMessage(It.IsAny <IMessage>()))
            .Returns(new Message());

            var messageConverterProvider = new Mock <IMessageConverterProvider>();

            messageConverterProvider.Setup(m => m.Get <Message>())
            .Returns(messageConverter.Object);

            var cloudListener = new Mock <ICloudListener>();

            cloudListener.Setup(c => c.ProcessMessageAsync(It.IsAny <IMessage>())).ThrowsAsync(new InvalidOperationException());
            TimeSpan    idleTimeout = TimeSpan.FromSeconds(3);
            ICloudProxy cloudProxy  = new CloudProxy(client.Object, messageConverterProvider.Object, "device1", null, cloudListener.Object, idleTimeout, true);

            // Act
            await cloudProxy.StartListening();

            // Assert
            Assert.True(cloudProxy.IsActive);
            Assert.True(isClientActive);

            // Act
            await Task.Delay(TimeSpan.FromSeconds(5));

            // Assert
            Assert.True(cloudProxy.IsActive);
            Assert.True(isClientActive);
            client.Verify(c => c.CloseAsync(), Times.Never);
        }
Ejemplo n.º 12
0
        public async Task MethodCallHandler_WhenResponse_WithRequestIdReceived_Completes()
        {
            var cloudListener = new Mock <ICloudListener>();

            cloudListener.Setup(p => p.CallMethodAsync(It.IsAny <Core.DirectMethodRequest>())).Returns(Task.FromResult(new DirectMethodResponse(RequestId, Data, StatusCode)));
            var messageConverter = new Mock <IMessageConverterProvider>();
            var identity         = Mock.Of <IIdentity>(i => i.Id == "device1");

            var deviceClient = Mock.Of <IClient>();
            var cloudProxy   = new CloudProxy(deviceClient, messageConverter.Object, identity.Id, (id, s) => { });

            var cloudReceiver = new CloudProxy.CloudReceiver(cloudProxy, cloudListener.Object);

            MethodResponse methodResponse = await cloudReceiver.MethodCallHandler(new MethodRequest(MethodName, Data), null);

            cloudListener.Verify(p => p.CallMethodAsync(It.Is <Core.DirectMethodRequest>(x => x.Name == MethodName && x.Data == Data)), Times.Once);
            Assert.NotNull(methodResponse);
        }
Ejemplo n.º 13
0
        public void SetupDesiredPropertyUpdatesAsync()
        {
            //Arrange
            var messageConverterProvider = new Mock <IMessageConverterProvider>();

            var identity     = Mock.Of <IIdentity>(i => i.Id == "device1");
            var deviceClient = new Mock <IClient>();

            var cloudProxy    = new CloudProxy(deviceClient.Object, messageConverterProvider.Object, identity.Id, (id, s) => { });
            var cloudListener = new Mock <ICloudListener>();

            var cloudReceiver = new CloudProxy.CloudReceiver(cloudProxy, cloudListener.Object);

            //Act
            cloudReceiver.SetupDesiredPropertyUpdatesAsync();

            //Assert
            deviceClient.Verify(m => m.SetDesiredPropertyUpdateCallbackAsync(It.IsAny <DesiredPropertyUpdateCallback>(), It.IsAny <object>()));
        }
Ejemplo n.º 14
0
        public void RemoveDesiredPropertyUpdatesAsync()
        {
            //Arrange
            var messageConverterProvider = new Mock <IMessageConverterProvider>();

            var identity     = Mock.Of <IIdentity>(i => i.Id == "device1");
            var deviceClient = new Mock <IClient>();

            deviceClient.Setup(dc => dc.SetDesiredPropertyUpdateCallbackAsync(null, null)).Throws(new Exception("Update this test!")); //This is to catch onde the TODO on the code get's in.

            var cloudListener = new Mock <ICloudListener>();
            var cloudProxy    = new CloudProxy(deviceClient.Object, messageConverterProvider.Object, identity.Id, (id, s) => { }, cloudListener.Object);

            CloudProxy.CloudReceiver cloudReceiver = cloudProxy.GetCloudReceiver();

            //Act
            cloudReceiver.RemoveDesiredPropertyUpdatesAsync();

            //Assert
        }
Ejemplo n.º 15
0
        public async Task TestCloseThrows()
        {
            // Arrange
            var      messageConverterProvider = Mock.Of <IMessageConverterProvider>();
            string   clientId      = "d1";
            var      cloudListener = Mock.Of <ICloudListener>();
            TimeSpan idleTimeout   = TimeSpan.FromSeconds(60);
            Action <string, CloudConnectionStatus> connectionStatusChangedHandler = (s, status) => { };
            var client = new Mock <IClient>();

            client.Setup(c => c.CloseAsync()).ThrowsAsync(new InvalidOperationException());
            var cloudProxy = new CloudProxy(client.Object, messageConverterProvider, clientId, connectionStatusChangedHandler, cloudListener, idleTimeout, false);

            // Act
            bool result = await cloudProxy.CloseAsync();

            // Assert.
            Assert.True(result);
            client.VerifyAll();
        }
Ejemplo n.º 16
0
        public void CloudReceiverDisconnectsWhenItReceivesUnauthorizedException()
        {
            //Arrange
            var messageConverterProvider = Mock.Of <IMessageConverterProvider>();

            var deviceClient = new Mock <IClient>();

            deviceClient.Setup(p => p.ReceiveAsync(It.IsAny <TimeSpan>()))
            .Throws(new UnauthorizedException(""));

            var cloudProxy    = new CloudProxy(deviceClient.Object, messageConverterProvider, "device1", (id, s) => { });
            var cloudListener = Mock.Of <ICloudListener>();

            var cloudReceiver = new CloudProxy.CloudReceiver(cloudProxy, cloudListener);

            //Act
            cloudReceiver.StartListening(); //Exception expected to be handled and not thrown.

            //Assert
            //The verification is implicit, just making sure the exception is handled.
        }
Ejemplo n.º 17
0
        public async Task TestHandleNonRecoverableExceptions(Type exceptionType)
        {
            // Arrange
            var      messageConverter         = Mock.Of <IMessageConverter <Message> >(m => m.FromMessage(It.IsAny <IMessage>()) == new Message());
            var      messageConverterProvider = Mock.Of <IMessageConverterProvider>(m => m.Get <Message>() == messageConverter);
            string   clientId      = "d1";
            var      cloudListener = Mock.Of <ICloudListener>();
            TimeSpan idleTimeout   = TimeSpan.FromSeconds(60);
            Action <string, CloudConnectionStatus> connectionStatusChangedHandler = (s, status) => { };
            var client = new Mock <IClient>(MockBehavior.Strict);

            client.Setup(c => c.SendEventAsync(It.IsAny <Message>())).ThrowsAsync((Exception)Activator.CreateInstance(exceptionType, "dummy message"));
            client.Setup(c => c.CloseAsync()).Returns(Task.CompletedTask);
            var      cloudProxy = new CloudProxy(client.Object, messageConverterProvider, clientId, connectionStatusChangedHandler, cloudListener, idleTimeout, false);
            IMessage message    = new EdgeMessage.Builder(new byte[0]).Build();

            // Act
            await Assert.ThrowsAsync(exceptionType, () => cloudProxy.SendMessageAsync(message));

            // Assert.
            client.VerifyAll();
        }
        public async Task WithDownstreamEventsTest()
        {
            // Arrange / act
            var deviceIdentity            = Mock.Of <IIdentity>(i => i.Id == "d2");
            var edgeHubIdentity           = Mock.Of <IIdentity>(i => i.Id == "d1/m1");
            var deviceConnectivityManager = new DeviceConnectivityManager(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3), edgeHubIdentity);

            int connectedCallbackCount    = 0;
            int disconnectedCallbackCount = 0;

            void ConnectionStatusChangedHandler(ConnectionStatus status, ConnectionStatusChangeReason reason)
            {
                if (status == ConnectionStatus.Connected && reason == ConnectionStatusChangeReason.Connection_Ok)
                {
                    Interlocked.Increment(ref connectedCallbackCount);
                }
                else if (status == ConnectionStatus.Disconnected && reason == ConnectionStatusChangeReason.No_Network)
                {
                    Interlocked.Increment(ref disconnectedCallbackCount);
                }
            }

            var device1UnderlyingClient = new Mock <IClient>();

            device1UnderlyingClient.Setup(c => c.SendEventAsync(It.IsAny <Message>()))
            .Returns(Task.CompletedTask);
            var device1Client = new ConnectivityAwareClient(device1UnderlyingClient.Object, deviceConnectivityManager, deviceIdentity);

            device1Client.SetConnectionStatusChangedHandler(ConnectionStatusChangedHandler);

            var device2UnderlyingClient = new Mock <IClient>();

            device2UnderlyingClient.Setup(c => c.SendEventAsync(It.IsAny <Message>()))
            .Throws <TimeoutException>();
            var device2Client = new ConnectivityAwareClient(device2UnderlyingClient.Object, deviceConnectivityManager, deviceIdentity);

            device2Client.SetConnectionStatusChangedHandler(ConnectionStatusChangedHandler);

            var edgeHubUnderlyingClient = new Mock <IClient>();

            edgeHubUnderlyingClient.Setup(c => c.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>()))
            .Throws <TimeoutException>();
            IClient edgeHubClient = new ConnectivityAwareClient(edgeHubUnderlyingClient.Object, deviceConnectivityManager, deviceIdentity);

            edgeHubClient.SetConnectionStatusChangedHandler(ConnectionStatusChangedHandler);
            ICloudProxy cloudProxy        = new CloudProxy(edgeHubClient, Mock.Of <IMessageConverterProvider>(), "d1/m1", null, Mock.Of <ICloudListener>(), TimeSpan.FromHours(1), true);
            var         connectionManager = Mock.Of <IConnectionManager>(c => c.GetCloudConnection("d1/m1") == Task.FromResult(Option.Some(cloudProxy)));

            deviceConnectivityManager.SetConnectionManager(connectionManager);

            bool connected = false;

            deviceConnectivityManager.DeviceConnected    += (_, __) => connected = true;
            deviceConnectivityManager.DeviceDisconnected += (_, __) => connected = false;

            // Act
            var  cts = new CancellationTokenSource();
            Task t   = Task.Run(
                async() =>
            {
                while (!cts.IsCancellationRequested)
                {
                    await device1Client.SendEventAsync(new Message());
                    if (!cts.IsCancellationRequested)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(1));
                    }
                }
            });

            await Task.Delay(TimeSpan.FromSeconds(5));

            // Assert
            Assert.True(connected);
            edgeHubUnderlyingClient.Verify(c => c.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>()), Times.Never);
            Assert.Equal(3, connectedCallbackCount);
            Assert.Equal(0, disconnectedCallbackCount);

            cts.Cancel();
            await t;

            var  cts2 = new CancellationTokenSource();
            Task t2   = Task.Run(
                async() =>
            {
                while (!cts2.IsCancellationRequested)
                {
                    try
                    {
                        await device2Client.SendEventAsync(new Message());
                    }
                    catch (TimeoutException)
                    {
                    }
                    if (!cts2.IsCancellationRequested)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(1));
                    }
                }
            });

            await Task.Delay(TimeSpan.FromSeconds(5));

            // Assert
            Assert.False(connected);
            edgeHubUnderlyingClient.Verify(c => c.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>()), Times.Once);
            Assert.Equal(3, connectedCallbackCount);
            Assert.Equal(3, disconnectedCallbackCount);

            cts2.Cancel();
            await t2;

            await device1Client.SendEventAsync(new Message());

            // Assert
            Assert.True(connected);
            edgeHubUnderlyingClient.Verify(c => c.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>()), Times.Once);
            Assert.Equal(6, connectedCallbackCount);
            Assert.Equal(3, disconnectedCallbackCount);
        }
Ejemplo n.º 19
0
        public List <KendoTreeItem> GetCloudFileTree(string token, int type)
        {
            CloudProxy cp = new CloudProxy(token);

            return(cp.GetFileTree(type));
        }
        public BusinessModelDefinition GetCloundBusinessModelDefinition(string modelId, string token)
        {
            CloudProxy cp = new CloudProxy(token);

            return(cp.GetBusinessModelDefinition(modelId));
        }