Exemple #1
0
        public async Task RegisterAdapterSettingOptionAddedTest()
        {
            //Arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());
            var adapterBuilder = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var dbAdapter      = UnitTesting.CreateFakeAdapter();

            var adapterSetting = new AdapterSetting
            {
                Name             = "Adapter Setting 1",
                ValueType        = DataType.STRING,
                Value            = "Hello World",
                UniqueIdentifier = "PropertyTest"
            };

            dbAdapter.Settings.Add(adapterSetting);
            var option1 = new AdapterSettingOption
            {
                Name = "Option 1",
            };
            var option2 = new AdapterSettingOption
            {
                Name = "Option 2",
            };

            adapterSetting.Options.Add(option1);


            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(dbAdapter);
                await context.SaveChangesAsync();
            }
            var adapter = new StubUnitTestAdapter
            {
                AdapterGuidGet = () => dbAdapter.AdapterGuid
            };

            adapterSetting.Options.Add(option2);

            //act
            var result = await adapterBuilder.Adapter(adapter).RegisterAdapterSettingAsync(adapterSetting, o => o.PropertyTest);

            AdapterSetting a;

            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.AdapterSettings
                    .Include(o => o.Options)
                    .FirstOrDefaultAsync(o => o.Id == adapterSetting.Id);
            }

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Options.Count == 2, "Expected 2 adapter setting options");
            Assert.IsTrue(a.Options[1].Name == option2.Name, "Adapter option name mismatch");
        }
Exemple #2
0
        public async Task RegisterAsyncUpdatedDeviceTypeTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb     = new DeviceTypeBuilder(dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            var dt      = new DeviceType
            {
                AdapterId        = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name             = "Unit Test Device Type"
            };

            adapter.DeviceTypes.Add(dt);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            dt.Name = "New Unit Test Device Type Name";

            //act
            var result = await dtb.RegisterAsync(adapter.AdapterGuid, dt, CancellationToken.None);

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
        }
Exemple #3
0
        public async Task RegisterAsyncRemvoedCommandOptionDeviceTypeTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb     = new DeviceTypeBuilder(dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            var dt      = new DeviceType
            {
                AdapterId        = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name             = "Unit Test Device Type"
            };
            var dtc = new DeviceTypeCommand
            {
                UniqueIdentifier = "DTC1",
                Name             = "Test Device Type Command"
            };
            var option1 = new CommandOption
            {
                Name = "Option 1"
            };
            var option2 = new CommandOption
            {
                Name = "Option 2"
            };

            dt.Commands.Add(dtc);
            adapter.DeviceTypes.Add(dt);
            dtc.Options.Add(option1);
            dtc.Options.Add(option2);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            dtc.Options.Remove(option1);

            //act
            var result = await dtb.RegisterAsync(adapter.AdapterGuid, dt, CancellationToken.None);

            using (var context = new ZvsContext(dbConnection))
            {
                var dtc1 = context.DeviceTypeCommands
                           .Include(o => o.Options)
                           .First();

                //assert
                Console.WriteLine(result.Message);
                Assert.IsFalse(result.HasError);
                Assert.IsTrue(dtc1.Options.Count == 1, "Expected 2 options");
            }
        }
Exemple #4
0
        public async Task RegisterAdapterSettingValueDonestTriggerChangedTest()
        {
            //Arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());
            var adapterBuilder = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var dbAdapter      = UnitTesting.CreateFakeAdapter();

            var adapterSetting = new AdapterSetting
            {
                Name             = "Adapter Setting 1",
                ValueType        = DataType.STRING,
                Value            = "Hello World",
                UniqueIdentifier = "PropertyTest"
            };

            dbAdapter.Settings.Add(adapterSetting);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(dbAdapter);
                await context.SaveChangesAsync();
            }
            var adapter = new StubUnitTestAdapter
            {
                AdapterGuidGet = () => dbAdapter.AdapterGuid
            };

            adapterSetting.Value = "New value!";

            //act
            var result = await adapterBuilder.Adapter(adapter).RegisterAdapterSettingAsync(adapterSetting, o => o.PropertyTest);

            Adapter a;

            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.Adapters
                    .Include(o => o.Settings)
                    .FirstOrDefaultAsync(o => o.AdapterGuid == dbAdapter.AdapterGuid);
            }

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Settings.Count == 1, "Expected 1 adapter setting");
            Assert.IsTrue(a.Settings[0].Value == "Hello World", "Adapter value changed when it shouldn't!");
        }