Esempio n. 1
0
        public async Task CanListenForDesiredPropertyUpdates()
        {
            var    update                    = new TaskCompletionSource <IMessage>();
            var    cloudListener             = new Mock <ICloudListener>();
            string deviceConnectionStringKey = "device2ConnStrKey";

            cloudListener.Setup(x => x.OnDesiredPropertyUpdates(It.IsAny <IMessage>()))
            .Callback((IMessage m) => update.TrySetResult(m))
            .Returns(TaskEx.Done);

            ICloudProxy cloudProxy = await this.GetCloudProxyWithConnectionStringKey(deviceConnectionStringKey);

            cloudProxy.BindCloudListener(cloudListener.Object);
            await cloudProxy.SetupDesiredPropertyUpdatesAsync();

            var desired = new TwinCollection()
            {
                ["desiredPropertyTest"] = Guid.NewGuid().ToString()
            };

            await UpdateDesiredProperty(ConnectionStringHelper.GetDeviceId(await SecretsHelper.GetSecretFromConfigKey(deviceConnectionStringKey)), desired);

            await update.Task;
            await cloudProxy.RemoveDesiredPropertyUpdatesAsync();

            IMessage expected = new EdgeMessage.Builder(Encoding.UTF8.GetBytes(desired.ToJson())).Build();

            expected.SystemProperties[SystemProperties.EnqueuedTime] = "";
            expected.SystemProperties[SystemProperties.Version]      = desired.Version.ToString();
            IMessage actual = update.Task.Result;

            Assert.Equal(expected.Body, actual.Body);
            Assert.Equal(expected.Properties, actual.Properties);
            Assert.Equal(expected.SystemProperties.Keys, actual.SystemProperties.Keys);
        }
Esempio n. 2
0
        public async Task CloudProxyNullReceiverTest()
        {
            // Arrange
            ICloudProxy cloudProxy = await this.GetCloudProxyFromConnectionStringKey(Device2ConnStrKey);

            // Act/assert
            // Without setting up the CloudListener, the following methods should not throw.
            await cloudProxy.SetupCallMethodAsync();

            await cloudProxy.RemoveCallMethodAsync();

            await cloudProxy.SetupDesiredPropertyUpdatesAsync();

            await cloudProxy.RemoveDesiredPropertyUpdatesAsync();

            await cloudProxy.StartListening();
        }