コード例 #1
0
        public void Change_Heat_Setpoint_TenanetId_Is_Empty__Should_Throw_ArgumentOutOfRangeException()
        {
            ConnectToThermostatCommand cmd             = new ConnectToThermostatCommand(Guid.Empty, "ThermostatId", Guid.NewGuid(), 40, 50, 80, "Cool", "Idel");
            HeatSetpointChangeCommand  heatSetpointCmd = new HeatSetpointChangeCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), 67);

            Assert.Throws <ArgumentOutOfRangeException> (() => Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd));
        }
コード例 #2
0
 static void SendEvent(Object sender, ThermostatConnectedEventArgs e)
 {
     var tenantId = Guid.Parse(Configuration.GetSection("AppSettings").GetSection("ControllerId").Value);
     ConnectToThermostatCommand cmd = new ConnectToThermostatCommand(tenantId, e.ThermostatId, e.ThermostatGuid,
                                                                     e.Temperature, e.HeatSetpoint, e.CoolSetpoint, e.Mode, e.SystemStatus);
     var eventMetadata = new EventMetadata(tenantId, "Thermostat", Guid.NewGuid().ToString(), Guid.NewGuid(), tenantId, DateTimeOffset.UtcNow);
     var thermostat    = Domain.Thermostat.ConnectToThermostat(eventMetadata,
                                                               EventStore, cmd);
 }
コード例 #3
0
        public void Connect_To_Thermostat_Should_Send_One_Event_To_EventStore()
        {
            var moqEventStore = new Mock <IEventStore>();
            var eventMetadata = new EventMetadata(Guid.NewGuid(), "TestCategory", "TestCorrelationId", Guid.NewGuid(), Guid.NewGuid(), DateTimeOffset.UtcNow);
            ConnectToThermostatCommand cmd = new ConnectToThermostatCommand(Guid.NewGuid(), "thermostatId", Guid.NewGuid(), 56, 60, 72, "Cool", "Idel");

            var p = Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd);

            moqEventStore.Verify(m => m.SaveEvents(It.IsAny <CompositeAggregateId>(), It.IsAny <IEnumerable <IEvent> >()), Times.Once);
        }
コード例 #4
0
        public void CoolSetpoint_Changed_No_Cool_Setpoint_Temperature_Should_Throw_ArgumentNullException()
        {
            ConnectToThermostatCommand cmd             = new ConnectToThermostatCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), 40, 50, 80, "Cool", "Idel");
            CoolSetpointChangeCommand  coolSetpointCmd = new CoolSetpointChangeCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), null);

            ChangeCoolSetpoint changeCoolSetpointCommand = new ChangeCoolSetpoint(moqEventStore.Object, cmd.ThermostatId,
                                                                                  cmd.ThermostatAggregateId, Guid.NewGuid(), coolSetpointCmd.NewCoolSetpoint);
            var handler = new ThermostatCommandHandlers();

            Assert.Throws <ArgumentNullException>(() => handler.Handle(changeCoolSetpointCommand));
        }
コード例 #5
0
        public void Change_Heat_Setpoint_EventNumber_Mismatch_Should_Throw_ArgumentOutOfRangeException()
        {
            ConnectToThermostatCommand cmd             = new ConnectToThermostatCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), 40, 50, 80, "Cool", "Idel");
            HeatSetpointChangeCommand  heatSetpointCmd = new HeatSetpointChangeCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), 67);

            List <IEvent> connected = new List <IEvent>();

            connected.Add(new Connected(Guid.NewGuid(), DateTimeOffset.UtcNow, eventMetadata, 78, 56, 76, "Off", "Idel", 80));
            moqEventStore.Setup(storage => storage.GetAllEvents(It.IsAny <CompositeAggregateId>())).Returns(connected);
            var p = Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd);

            Assert.Throws <ArgumentOutOfRangeException>(() => p.ChangeHeatSetpoint(eventMetadata, moqEventStore.Object, heatSetpointCmd, 200));
            moqEventStore.Verify(m => m.SaveEvents(It.IsAny <CompositeAggregateId>(), It.IsAny <IEnumerable <IEvent> >()), Times.Once);
        }
コード例 #6
0
        public void HVAC_Mode_Changed_Should_Update_HVAC_Mode()
        {
            ConnectToThermostatCommand cmd            = new ConnectToThermostatCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), 40, 50, 80, "Cool", "Idel");
            SystemModeChangeCommand    stateChangeCmd = new SystemModeChangeCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), "Off");
            List <IEvent> connected = new List <IEvent>();

            connected.Add(new Connected(Guid.NewGuid(), DateTimeOffset.UtcNow, eventMetadata, 78, 56, 76, "Off", "Idel", 80));
            moqEventStore.Setup(storage => storage.GetAllEvents(It.IsAny <CompositeAggregateId>())).Returns(connected);

            var thermo = Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd);

            thermo.ChangeSystemMode(eventMetadata, moqEventStore.Object, stateChangeCmd, thermo.Version);
            moqEventStore.Verify(m => m.SaveEvents(It.IsAny <CompositeAggregateId>(), It.IsAny <IEnumerable <IEvent> >()), Times.Exactly(2));
            var events = thermo.GetUncommittedEvents();

            events.Count().ShouldEqual(1);
        }
コード例 #7
0
        public void Should_Connect_To_Thermostat()
        {
            var moqEventStore = new Mock <IEventStore>();
            var eventMetadata = new EventMetadata(Guid.NewGuid(), "TestCategory", "TestCorrelationId", Guid.NewGuid(), Guid.NewGuid(), DateTimeOffset.UtcNow);
            ConnectToThermostatCommand cmd = new ConnectToThermostatCommand(Guid.NewGuid(), "theremostatId", Guid.NewGuid(), 76, 60.9, 77.2, "Heat", "Heating", 77.4);
            List <IEvent> connected        = new List <IEvent>();

            connected.Add(new ESEvents.Common.Events.Thermostat.Connected(Guid.NewGuid(), DateTimeOffset.UtcNow, eventMetadata, 78, 56, 76, "Off", "Idel", 80));
            moqEventStore.Setup(storage => storage.GetAllEvents(It.IsAny <CompositeAggregateId>())).Returns(connected);

            var p = Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd);

            var events = p.GetUncommittedEvents();

            Assert.IsNotNull(p.AggregateGuid);
            Assert.AreNotEqual(Guid.Empty, p.AggregateGuid);
        }
コード例 #8
0
        public void Should_Change_AmbientTemperature_For_Thermostat()
        {
            var moqEventStore              = new Mock <IEventStore>();
            var eventMetadata              = new EventMetadata(Guid.NewGuid(), "TestCategory", "TestCorrelationId", Guid.NewGuid(), Guid.NewGuid(), DateTimeOffset.UtcNow);
            var thermostatId               = "termostatId";
            var thermostatGuid             = Guid.NewGuid();
            ConnectToThermostatCommand cmd = new ConnectToThermostatCommand(Guid.NewGuid(), thermostatId, thermostatGuid, 76, 60.9, 77.2, "Heat", "Heating", 77.4);
            List <IEvent> connected        = new List <IEvent>();

            connected.Add(new ESEvents.Common.Events.Thermostat.Connected(Guid.NewGuid(), DateTimeOffset.UtcNow, eventMetadata, 78, 56, 76, "Off", "Idel", 80));
            moqEventStore.Setup(storage => storage.GetAllEvents(It.IsAny <CompositeAggregateId>())).Returns(connected);

            var p = Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd);
            ChangeAmbientTemperature changeAmbientTemperatureCommand = new ChangeAmbientTemperature(moqEventStore.Object, thermostatId, thermostatGuid,
                                                                                                    Guid.NewGuid(), (double)cmd.Temperature);
            var handler = new ThermostatCommandHandlers();

            handler.Handle(changeAmbientTemperatureCommand);

            Assert.IsNotNull(p.AggregateGuid);
            Assert.AreNotEqual(Guid.Empty, p.AggregateGuid);
        }
コード例 #9
0
        public void Connect_To_Thermostat_No_System_Status_Should_Throw_ArgumentNullException()
        {
            ConnectToThermostatCommand cmd = new ConnectToThermostatCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), 40, 50, 80, "Cool", string.Empty);

            Assert.Throws <ArgumentNullException>(() => Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd));
        }
コード例 #10
0
        public void Connect_To_Thermostat_No_Cool_Setpoint_Temperature_Should_Throw_ArgumentNullException()
        {
            ConnectToThermostatCommand cmd = new ConnectToThermostatCommand(Guid.NewGuid(), "ThermostatId", Guid.NewGuid(), 40, 50, null, "Cool/Heat", "Idel");

            Assert.Throws <ArgumentNullException>(() => Domain.Thermostat.ConnectToThermostat(eventMetadata, moqEventStore.Object, cmd));
        }
コード例 #11
0
ファイル: Thermostat.cs プロジェクト: cato976/DomoTroller2
        public static Thermostat ConnectToThermostat(IEventMetadata eventMetadata, IEventStore eventStore, ConnectToThermostatCommand cmd)
        {
            ValidateTemperature(cmd.Temperature);
            ValidateSetpoint(cmd.HeatSetpoint);
            ValidateCoolSetpoint(cmd.CoolSetpoint);
            ValidateMode(cmd.Mode);
            ValidateSystemStatus(cmd.SystemStatus);
            ValidateTenantId(cmd.TenantId);

            var thermostatId = cmd.ThermostatId;
            var connectToControllerCommand = new ConnectThermostat(cmd.ThermostatAggregateId);
            var commandBus = CommandBus.Instance;

            commandBus.Execute(connectToControllerCommand);

            var thermostat = new Thermostat(cmd.ThermostatAggregateId, eventMetadata, eventStore,
                                            (double)cmd.Temperature, (double)cmd.HeatSetpoint, (double)cmd.CoolSetpoint,
                                            cmd.Mode, cmd.SystemStatus, cmd.Humidity);

            Repository <Thermostat> thermostatRepo = new Repository <Thermostat>(eventStore);
            var found = thermostatRepo.GetById(new CompositeAggregateId(cmd.TenantId, cmd.ThermostatAggregateId, "Thermostat"));

            return(found);
        }