Example #1
0
        public void CreatesNewThermostatWithSerialWhenNotExists()
        {
            var thermostats = new Thermostats();

            var newThermostat = thermostats.ThermostatWithSerial("Thermostat1");

            Assert.AreEqual("Thermostat1", newThermostat.Serial);
            Assert.AreSame(newThermostat, thermostats.thermostats[0]);
        }
Example #2
0
        public void CanReadFromFile()
        {
            File.WriteAllText(TEST_XML_PATH, @"
<Thermostats>
    <Thermostat>
        <Name>Test</Name>
    </Thermostat>
</Thermostats>");
            var thermostats = Thermostats.Read();

            Assert.AreEqual(1, thermostats.thermostats.Count);
            Assert.AreEqual("Test", thermostats.thermostats[0].Name);
        }
Example #3
0
        public void KnowsWhenWeHaveNoSecretAndUuidForThermostat()
        {
            var thermostat = new Thermostat
            {
                Serial = "Thermostat1"
            };

            var thermostats = new Thermostats();

            thermostats.thermostats.Add(thermostat);

            Assert.IsFalse(thermostats.HasSecretAndUuidFor("Thermostat1"));
        }
Example #4
0
        public void GivesExistingThermostatBySerialWhenExists()
        {
            var thermostat = new Thermostat
            {
                Serial = "Thermostat1"
            };

            var thermostats = new Thermostats();

            thermostats.thermostats.Add(thermostat);

            Assert.AreSame(thermostat, thermostats.ThermostatWithSerial("Thermostat1"));
        }
Example #5
0
        public void KnowsThatUuidIsNotEnoughForSecretAndUuid()
        {
            var thermostat = new Thermostat
            {
                Serial = "Thermostat1",
                Uuid   = "5D7000A0-0D45-41FC-B6AD-08CB8BC149B9",
            };

            var thermostats = new Thermostats();

            thermostats.thermostats.Add(thermostat);

            Assert.IsFalse(thermostats.HasSecretAndUuidFor("Thermostat1"));
        }
Example #6
0
        public void KnowsThatSecretIsNotEnoughForSecretAndUuid()
        {
            var thermostat = new Thermostat
            {
                Serial    = "Thermostat1",
                SecretKey = "ABC"
            };

            var thermostats = new Thermostats();

            thermostats.thermostats.Add(thermostat);

            Assert.IsFalse(thermostats.HasSecretAndUuidFor("Thermostat1"));
        }
Example #7
0
        public void KnowsWhenWeHaveSecretAndUuidForThermostat()
        {
            var thermostat = new Thermostat
            {
                Serial    = "Thermostat1",
                Uuid      = "5D7000A0-0D45-41FC-B6AD-08CB8BC149B9",
                SecretKey = "ABC"
            };

            var thermostats = new Thermostats();

            thermostats.thermostats.Add(thermostat);

            Assert.IsTrue(thermostats.HasSecretAndUuidFor("Thermostat1"));
        }
Example #8
0
        public static Thermostats Read()
        {
            var result = new Thermostats();

            if (File.Exists(xmlPath))
            {
                using (var stream = new FileStream(xmlPath, FileMode.Open))
                {
                    XmlReader reader      = new XmlTextReader(stream);
                    var       thermostats = (Thermostat[])serializer.Deserialize(reader);
                    result.thermostats.AddRange(thermostats);
                }
            }
            return(result);
        }
Example #9
0
        public void CanSaveToFile()
        {
            var from        = DateTime.Now;
            var to          = from.AddDays(2);
            var thermostat1 = new Thermostat
            {
                Name        = "Thermostat1",
                SecretKey   = "ABC",
                Uuid        = "UUID123",
                Temperature = "encoded-temperature-1",
                UpdatedSetPointTemperature = Temperature.FromDegreesCelcius(22),
                HasUpdatedVacationPeriod   = true,
                UpdatedVacationPeriod      = new Period(from, to)
            };

            var thermostat2 = new Thermostat
            {
                Name        = "Thermostat2",
                SecretKey   = "DEF",
                Temperature = "encoded-temperature-2"
            };

            var thermostats = new Thermostats();

            thermostats.thermostats.Add(thermostat1);
            thermostats.thermostats.Add(thermostat2);

            thermostats.Write();

            var readThermostats = Thermostats.Read();

            Assert.AreEqual(2, readThermostats.thermostats.Count);
            var firstReadThermostat = readThermostats.thermostats[0];

            Assert.AreEqual("Thermostat1", firstReadThermostat.Name);
            Assert.AreEqual("ABC", firstReadThermostat.SecretKey);
            Assert.AreEqual("UUID123", firstReadThermostat.Uuid);
            Assert.AreEqual("encoded-temperature-1", firstReadThermostat.Temperature);
            Assert.AreEqual(22, firstReadThermostat.UpdatedSetPointTemperature.InDegreesCelcius);
            Assert.IsTrue(firstReadThermostat.HasUpdatedVacationPeriod);
            Assert.AreEqual(from, firstReadThermostat.UpdatedVacationPeriod.From);
            Assert.AreEqual(to, firstReadThermostat.UpdatedVacationPeriod.To);
        }
Example #10
0
        public void CanRemoveThermostatWithSerial()
        {
            var thermostat1 = new Thermostat
            {
                Serial = "Thermostat1"
            };

            var thermostat2 = new Thermostat
            {
                Serial = "Thermostat2"
            };

            var thermostats = new Thermostats();

            thermostats.thermostats.Add(thermostat1);
            thermostats.thermostats.Add(thermostat2);

            thermostats.RemoveThermostatWithSerial("Thermostat1");

            Assert.AreEqual(1, thermostats.thermostats.Count);
            Assert.AreEqual("Thermostat2", thermostats.thermostats[0].Serial);
        }
Example #11
0
        public void HandlesMissingFile()
        {
            var thermostats = Thermostats.Read();

            Assert.AreEqual(0, thermostats.thermostats.Count);
        }
Example #12
0
        public void KnowsThatWeHaveNoSecretForMissingThermostat()
        {
            var thermostats = new Thermostats();

            Assert.IsFalse(thermostats.HasSecretAndUuidFor("Don't know this diddy"));
        }