public void ResolveIncomingNullAllTest()
        {
            var deviceOperations   = Substitute.For <IDeviceOperations>();
            var networkeOperations = Substitute.For <INetworkOperations>();
            var serviceOperations  = Substitute.For <IServiceOperations>();
            var companyOperations  = Substitute.For <ICompanyOperations>();
            var telemetryDataSinkMetadataRegistry = Substitute.For <ITelemetryDataSinkMetadataRegistry>();

            var deviceId = Identity.Next();

            var serviceId = Identity.Next();
            var networkId = Identity.Next();
            var companyId = Identity.Next();

            deviceOperations.Get(deviceId).Returns(TestDataCreator.Device(deviceId, null, networkId, serviceId, companyId, 0));
            serviceOperations.Get(serviceId)
            .Returns(TestDataCreator.Service(serviceId, null,
                                             companyId, new TelemetryDataSinkSettings {
                Incoming = null
            }));
            companyOperations.Get(companyId)
            .Returns(TestDataCreator.Company(companyId, new TelemetryDataSinkSettings {
                Incoming = null
            }));
            networkeOperations.Get(networkId)
            .Returns(TestDataCreator.Network(networkId, "key", null, serviceId, companyId, new TelemetryDataSinkSettings {
                Incoming = new List <TelemetryDataSinkParameters>()
            }));

            var telemetryDataSinkResolver = new TelemetryDataSinkResolver(deviceOperations, networkeOperations, serviceOperations, companyOperations,
                                                                          telemetryDataSinkMetadataRegistry, new DynamicConnectionStringResolver(null));

            Assert.AreEqual(0, telemetryDataSinkResolver.ResolveIncoming(deviceId).Count());
        }
        public void ResolveIncomingCompanyTest()
        {
            var deviceOperations   = Substitute.For <IDeviceOperations>();
            var networkeOperations = Substitute.For <INetworkOperations>();
            var serviceOperations  = Substitute.For <IServiceOperations>();
            var companyOperations  = Substitute.For <ICompanyOperations>();
            var telemetryDataSinkMetadataRegistry = Substitute.For <ITelemetryDataSinkMetadataRegistry>();

            var deviceId = Identity.Next();

            var serviceId = Identity.Next();
            var networkId = Identity.Next();
            var companyId = Identity.Next();

            telemetryDataSinkMetadataRegistry.Incoming.Returns(new List <TelemetryDataSinkMetadata>
            {
                new TelemetryDataSinkMetadata("azureData", "data", typeof(IncomingStubs.CurrentDataStub),
                                              new[] { "ConnectionString", "Table" }, new Dictionary <string, string>())
            });

            deviceOperations.Get(deviceId).Returns(TestDataCreator.Device(deviceId, null, networkId, serviceId, companyId, 0));
            serviceOperations.Get(serviceId)
            .Returns(TestDataCreator.Service(serviceId, null,
                                             companyId, new TelemetryDataSinkSettings {
                Incoming = new List <TelemetryDataSinkParameters>()
            }));

            companyOperations.Get(companyId)
            .Returns(TestDataCreator.Company(companyId, new TelemetryDataSinkSettings
            {
                Incoming =
                    new List <TelemetryDataSinkParameters>
                {
                    new TelemetryDataSinkParameters()
                    {
                        SinkName   = "azureData",
                        Parameters =
                            new Dictionary <string, string>()
                        {
                            { "ConnectionString", "that" },
                            { "Table", "t" }
                        }
                    }
                }
            }));
            networkeOperations.Get(networkId)
            .Returns(TestDataCreator.Network(networkId, "key", null, serviceId, companyId, new TelemetryDataSinkSettings {
                Incoming = new List <TelemetryDataSinkParameters>()
            }));

            var telemetryDataSinkResolver = new TelemetryDataSinkResolver(deviceOperations, networkeOperations, serviceOperations, companyOperations,
                                                                          telemetryDataSinkMetadataRegistry, new DynamicConnectionStringResolver(null));

            Assert.AreEqual(1, telemetryDataSinkResolver.ResolveIncoming(deviceId).Count());
            Assert.IsInstanceOfType(telemetryDataSinkResolver.ResolveIncoming(deviceId).First(), typeof(IncomingStubs.CurrentDataStub));
        }