Example #1
0
        public void ChangeCoolSetpoint(IEventMetadata eventMetadata, IEventStore eventStore,
                                       CoolSetpointChangeCommand cmd, long orginalEventNumber)
        {
            ValidateSetpoint(cmd.NewCoolSetpoint);
            ValidateEventNumber(orginalEventNumber);
            ValidateCategory(eventMetadata.Category);

            var coolSetpointChangeCommand = new ChangeCoolSetpoint(eventStore, cmd.ThermostatId,
                                                                   cmd.ThermostatGuid, cmd.TenantId, (double)cmd.NewCoolSetpoint);
            var commandBus = CommandBus.Instance;

            commandBus.Execute(coolSetpointChangeCommand);

            ApplyEvent(new CoolSetpointChanged(cmd.ThermostatGuid, DateTimeOffset.UtcNow, eventMetadata, (double)cmd.NewCoolSetpoint), -4);

            // Send Event to Event Store
            var events = this.GetUncommittedEvents();

            try
            {
                EventSender.SendEvent(eventStore, new CompositeAggregateId(eventMetadata.TenantId, AggregateGuid, eventMetadata.Category), events);
            }
            catch (ConnectionFailure conn)
            {
                Trace.TraceError($"There was a connection error: {conn}");
            }
        }
Example #2
0
        private static void DomoShare_ThermostatCoolSetpointChanged(object sender, ThermostatCoolSetpointChangedEventArgs e)
        {
            var tenantId = Guid.Parse(Configuration.GetSection("AppSettings").GetSection("ControllerId").Value);
            CoolSetpointChangeCommand cmd = new CoolSetpointChangeCommand(e.TenantId, e.ThermostatId, e.ThermostatGuid, e.NewCoolSetpoint);
            ChangeCoolSetpoint        changeCoolSetpointCommand = new ChangeCoolSetpoint(EventStore, e.ThermostatId, e.ThermostatGuid,
                                                                                         e.TenantId, (double)e.NewCoolSetpoint);
            var handler = new ThermostatCommandHandlers();

            handler.Handle(changeCoolSetpointCommand);
        }
Example #3
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));
        }
        public void Handle(ChangeCoolSetpoint message)
        {
            //Validate
            ValidateSetpoint(message.NewCoolSetpoint);

            //Process
            var tenantId      = message.TenantId;
            var eventMetadata = new EventMetadata(tenantId, "Thermostat", Guid.NewGuid().ToString(), Guid.NewGuid(), tenantId, DateTimeOffset.UtcNow);

            Repository <Domain.Thermostat> thermostatRepo = new Repository <Domain.Thermostat>(message.EventStore);

            CoolSetpointChangeCommand cmd = new CoolSetpointChangeCommand(tenantId, message.ThermostatId, message.Id, message.NewCoolSetpoint);

            var found = thermostatRepo.GetById(new CompositeAggregateId(tenantId, message.Id, "Thermostat"));

            found.ChangeCoolSetpoint(eventMetadata, message.EventStore, cmd, ((Aggregate)found).EventMetadata.EventNumber);
        }
Example #5
0
        public void Should_Change_Cool_Setpoint_To_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);
            CoolSetpointChangeCommand coolSetpointChangeCommand = new CoolSetpointChangeCommand(Guid.NewGuid(), thermostatId, thermostatGuid, 61);
            ChangeCoolSetpoint        changeHeatSetpointCommand = new ChangeCoolSetpoint(moqEventStore.Object, thermostatId, thermostatGuid, Guid.NewGuid(), (double)cmd.HeatSetpoint);
            var handler = new ThermostatCommandHandlers();

            handler.Handle(changeHeatSetpointCommand);

            Assert.IsNotNull(p.AggregateGuid);
            Assert.AreNotEqual(Guid.Empty, p.AggregateGuid);
        }