示例#1
0
        private TheThing CreateThingForTest(TheEngineDeviceTypeInfo deviceType, out TestInfo testInfo)
        {
            if (!configs.TryGetValue($"{deviceType.EngineName}/{deviceType.DeviceType}", out testInfo))
            {
                WriteLine($"{deviceType}: No config found. Using default.");
                // No test config found: just create the instance without any configuration
                testInfo = new TestInfo
                {
                    MinimumBrowseTags = 0,
                    MaximumBrowseTags = 100,
                    Config            = new TheThing.TheThingConfiguration
                    {
                        ThingIdentity = new TheThingIdentity
                        {
                            EngineName = deviceType.EngineName,
                            DeviceType = deviceType.DeviceType,
                        },
                        ConfigurationValues = new List <TheThing.TheConfigurationProperty>
                        {
                        }
                    }
                };
            }

            var config = testInfo.Config;

            if (string.IsNullOrEmpty(config.ThingIdentity?.EngineName))
            {
                config.ThingIdentity = new TheThingIdentity
                {
                    EngineName = deviceType.EngineName,
                    DeviceType = deviceType.DeviceType,
                };
                var addressValue = config.ConfigurationValues.FirstOrDefault(c => c.Name == "Address");
                if (addressValue != null)
                {
                    config.ThingIdentity.ID = TheCommonUtils.CStr(addressValue);
                }
            }

            var owner     = TheThingRegistry.GetBaseEngineAsThing(eEngineName.ContentService);
            var testThing = TheThing.CreateThingFromConfigurationAsync(owner, config).Result;

            Assert.IsNotNull(testThing, $"Error creating thing for {config.ThingIdentity.EngineName} / {config.ThingIdentity.DeviceType}");
            return(testThing);
        }