Beispiel #1
0
        public void DeserializeProgramSets_DeserializesProgramSetsAndBringsThemToInitialConditions()
        {
            //arrange
            TestHelpers.InitializeZoneScaffolder();

            byte fcChannel = 1;
            var  zones     = new BetterList <Zone>();

            FadeCandyController.Instance.Initialize();
            ((FadeCandyZone)zones.Add(new FadeCandyZone(FadeCandyController.Instance, "TestZone1"))).AddFadeCandyLights(PixelType.FadeCandyWS2812Pixel, 6, fcChannel);
            ((FadeCandyZone)zones.Add(new FadeCandyZone(FadeCandyController.Instance, "TestZone2"))).AddFadeCandyLights(PixelType.FadeCandyWS2812Pixel, 12, fcChannel);
            ((FadeCandyZone)zones.Add(new FadeCandyZone(FadeCandyController.Instance, "TestZone3"))).AddFadeCandyLights(PixelType.FadeCandyWS2812Pixel, 12, fcChannel);
            ((FadeCandyZone)zones.Add(new FadeCandyZone(FadeCandyController.Instance, "TestZone4"))).AddFadeCandyLights(PixelType.FadeCandyWS2812Pixel, 12, fcChannel);

            var programSets = new BetterList <ProgramSet>
            {
                new ProgramSet("Stepper", zones["TestZone1"].Listify().Union(zones["TestZone3"].Listify()), true, null, "StepperSet1"),
                new ProgramSet("Stepper", zones["TestZone2"].Listify().Union(zones["TestZone4"].Listify()), true, null, "StepperSet2")
            };

            var serializedProgramSets = Config.SerializeProgramSets(programSets);

            //act
            var deserializedProgramSets = Config.DeserializeProgramSets(serializedProgramSets, zones);

            //assert
            Assert.AreEqual(programSets.Count, deserializedProgramSets.Count());
            deserializedProgramSets.ForEach(deserializedProgramSet =>
            {
                Assert.AreEqual(deserializedProgramSet.ProgramName, programSets[deserializedProgramSet.Name].ProgramName);
                Assert.AreEqual(deserializedProgramSet.Sync, programSets[deserializedProgramSet.Name].Sync);
                Assert.AreEqual(deserializedProgramSet.Zones, programSets[deserializedProgramSet.Name].Zones);
            });

            TestHelpers.ValidateSteppersRunning(zones.Select(z => z.ZoneProgram).Cast <IStepper>(), 100);

            zones.ForEach(zone => zone.Dispose(true));
        }