Example #1
0
        public async Task RegisterAsyncNewTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());
            var ssb = new SceneSettingBuilder(dbConnection);

            var sceneSetting = new SceneSetting
            {
                Name             = "Unit Test Scene Setting",
                UniqueIdentifier = "SCENE_SETTING1"
            };

            //act
            var result = await ssb.RegisterAsync(sceneSetting, CancellationToken.None);

            SceneSetting setting;

            using (var context = new ZvsContext(dbConnection))
            {
                setting =
                    await
                    context.SceneSettings.FirstOrDefaultAsync(
                        o => o.UniqueIdentifier == sceneSetting.UniqueIdentifier);
            }

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(setting, "Expected new scene setting saved to DB");
        }
        public async Task RegisterAsyncNewTest()
        {
            //arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());
            var ssb = new SceneSettingBuilder(dbConnection);

            var sceneSetting = new SceneSetting
            {
                Name = "Unit Test Scene Setting",
                UniqueIdentifier = "SCENE_SETTING1"
            };

            //act
            var result = await ssb.RegisterAsync(sceneSetting, CancellationToken.None);

            SceneSetting setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting =
                    await
                        context.SceneSettings.FirstOrDefaultAsync(
                            o => o.UniqueIdentifier == sceneSetting.UniqueIdentifier);

            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(setting, "Expected new scene setting saved to DB");
        }
Example #3
0
 public override async Task OnSceneSettingsCreating(SceneSettingBuilder settingBuilder)
 {
     await settingBuilder.RegisterAsync(new SceneSetting
     {
         UniqueIdentifier = SceneSettingUids.ShowInLightswitch.ToString(),
         Name             = "Show scene in LightSwitch",
         Description      = "If enabled this scene will show in the LightSwitch scene tab.",
         Value            = true.ToString(),
         ValueType        = DataType.BOOL
     }, CancellationToken);
 }
Example #4
0
 public override async Task OnSceneSettingsCreating(SceneSettingBuilder settingBuilder)
 {
     await settingBuilder.RegisterAsync(new SceneSetting
     {
         UniqueIdentifier = SceneSettingUids.ShowInWebapi.ToString(),
         Name             = "Show scene in Web API",
         Description      = "If enabled this scene will show in applications that use the Web API",
         Value            = Cache.ShowInWebapiDefaultValue.ToString(),
         ValueType        = DataType.BOOL
     }, CancellationToken);
 }
Example #5
0
        public override async Task OnSceneSettingsCreating(SceneSettingBuilder settingBuilder)
        {
            await settingBuilder.RegisterAsync(new SceneSetting
            {
                UniqueIdentifier = SceneSettingUids.ActivateAtSunrise.ToString(),
                Name             = "Activate at Sunrise",
                Description      = "Activates this scene at sunrise",
                Value            = "false",
                ValueType        = DataType.BOOL
            }, CancellationToken);

            await settingBuilder.RegisterAsync(new SceneSetting
            {
                UniqueIdentifier = SceneSettingUids.ActivateAtSunset.ToString(),
                Name             = "Activate at Sunset",
                Description      = "Activates this scene at sunset",
                Value            = "false",
                ValueType        = DataType.BOOL
            }, CancellationToken);
        }
Example #6
0
        public async Task RegisterAsyncOptionRemoveTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());
            var ssb = new SceneSettingBuilder(dbConnection);

            var sceneSetting = new SceneSetting
            {
                Name             = "Unit Test Scene Setting",
                UniqueIdentifier = "SCENE_SETTING1",
            };

            var option1 = new SceneSettingOption
            {
                Name = "Option 1"
            };
            var option2 = new SceneSettingOption
            {
                Name = "Option 2"
            };

            sceneSetting.Options.Add(option1);
            sceneSetting.Options.Add(option2);

            using (var context = new ZvsContext(dbConnection))
            {
                context.SceneSettings.Add(sceneSetting);
                await context.SaveChangesAsync();
            }

            sceneSetting.Options.Remove(option2);

            //act
            var result = await ssb.RegisterAsync(sceneSetting, CancellationToken.None);

            SceneSetting setting;

            using (var context = new ZvsContext(dbConnection))
            {
                setting = await context.SceneSettings
                          .Include(o => o.Options)
                          .FirstOrDefaultAsync(o => o.UniqueIdentifier == sceneSetting.UniqueIdentifier);
            }

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(setting, "Expected new scene setting saved to DB");
            Assert.IsTrue(setting.Options.Count == 1, "Expected 1 option!");
            Assert.IsTrue(setting.Options[0].Name == option1.Name);
        }
        public async Task RegisterAsyncNullSceneTest()
        {
            //arrange 
            var dbConnection = new UnitTestDbConnection();
            var ssb = new SceneSettingBuilder(dbConnection);

            //act
            var result = await ssb.RegisterAsync(null, CancellationToken.None);

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsTrue(result.HasError, result.Message);
        }
Example #8
0
        public async Task RegisterAsyncNullSceneTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();
            var ssb          = new SceneSettingBuilder(dbConnection);

            //act
            var result = await ssb.RegisterAsync(null, CancellationToken.None);

            //assert
            Console.WriteLine(result.Message);
            Assert.IsTrue(result.HasError, result.Message);
        }
        public async Task RegisterAsyncOptionRemoveTest()
        {
            //arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());
            var ssb = new SceneSettingBuilder(dbConnection);

            var sceneSetting = new SceneSetting
            {
                Name = "Unit Test Scene Setting",
                UniqueIdentifier = "SCENE_SETTING1",

            };

            var option1 = new SceneSettingOption
            {
                Name = "Option 1"
            };
            var option2 = new SceneSettingOption
            {
                Name = "Option 2"
            };
            sceneSetting.Options.Add(option1);
            sceneSetting.Options.Add(option2);

            using (var context = new ZvsContext(dbConnection))
            {
                context.SceneSettings.Add(sceneSetting);
                await context.SaveChangesAsync();
            }
            
            sceneSetting.Options.Remove(option2);

            //act
            var result = await ssb.RegisterAsync(sceneSetting, CancellationToken.None);

            SceneSetting setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting = await context.SceneSettings
                        .Include(o => o.Options)
                        .FirstOrDefaultAsync(o => o.UniqueIdentifier == sceneSetting.UniqueIdentifier);

            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(setting, "Expected new scene setting saved to DB");
            Assert.IsTrue(setting.Options.Count == 1, "Expected 1 option!");
            Assert.IsTrue(setting.Options[0].Name == option1.Name);
        }
        public async Task RegisterAsyncUpdateTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "ssb-RegisterAsyncUpdateTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var ssb = new SceneSettingBuilder(dbConnection);

            var sceneSetting = new SceneSetting
            {
                Name = "Unit Test Scene Setting",
                UniqueIdentifier = "SCENE_SETTING1"
            };

            using (var context = new ZvsContext(dbConnection))
            {
                context.SceneSettings.Add(sceneSetting);
                await context.SaveChangesAsync();
            }

            sceneSetting.Name = "New Name";

            //act
            var result = await ssb.RegisterAsync(sceneSetting, CancellationToken.None);

            SceneSetting setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting =
                    await
                        context.SceneSettings.FirstOrDefaultAsync(
                            o => o.UniqueIdentifier == sceneSetting.UniqueIdentifier);

            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(setting, "Expected new scene setting saved to DB");
            Assert.IsTrue(setting.Name == "New Name");
        }