public void notify_consume_of_all_buildings_to_area_when_electricity_is_consumed()
        {
            var anArea = Substitute.For <Area>(new object[] { null });
            var aCity  = new City(id: Guid.NewGuid());

            aCity.ReceiveFrom(anArea, SomeAreaPower);
            var aBuildingReport       = new BuildingConsumptionReport(Guid.NewGuid(), Power.CreateKilowatts(2));
            var anotherBuildingReport = new BuildingConsumptionReport(Guid.NewGuid(), Power.CreateKilowatts(2));

            aCity.GetNotifiedOfElectricConsumeOff(aBuildingReport);
            aCity.GetNotifiedOfElectricConsumeOff(anotherBuildingReport);

            aCity.NotifyConsumption();

            var expectedConsumptionReport = new CityConsumptionReport(aCity.Id, new List <BuildingConsumptionReport> {
                aBuildingReport, anotherBuildingReport
            });

            anArea.GetNotifiedOfElectricConsumeOff(expectedConsumptionReport);
        }
        public void notify_consume_of_all_cities_to_power_plant_when_electricity_is_consumed()
        {
            var aPowerPlant    = Substitute.For <PowerPlant>();
            var anArea         = new Area(id: Guid.NewGuid());
            var anCityConsumer = Substitute.For <CityPowerReceiver>();

            anArea.AddPowerReceiver(anCityConsumer);
            anArea.ReceiveFrom(aPowerPlant, SomePowerPlantPower);
            var aCityConsumptionReport       = new CityConsumptionReport(Guid.NewGuid(), new List <BuildingConsumptionReport>());
            var anotherCityConsumptionReport = new CityConsumptionReport(Guid.NewGuid(), new List <BuildingConsumptionReport>());

            anArea.GetNotifiedOfElectricConsumeOff(aCityConsumptionReport);
            anArea.GetNotifiedOfElectricConsumeOff(anotherCityConsumptionReport);

            anArea.NotifyConsumption();

            var expectedConsumptionReport = new AreaConsumptionReport(anArea.Id, new List <CityConsumptionReport> {
                aCityConsumptionReport, anotherCityConsumptionReport
            });

            aPowerPlant.Received(1).GetNotifiedOfElectricConsumeOff(expectedConsumptionReport);
        }
Пример #3
0
 public virtual void GetNotifiedOfElectricConsumeOff(CityConsumptionReport consumptionReport)
 {
     consumptionReports.Add(consumptionReport);
 }