Beispiel #1
0
        public void InsertDeleteValidateGetUserOwnsSystemTest()
        {
            var db = new PlantRepository();

              var plantId_1 = DatabaseHelpers.CreatePlantGetId();
              var plantId_2 = DatabaseHelpers.CreatePlantGetId();

              //Insert test data
              db.StoreUserPlantRelation(3, plantId_1, E_PlantRole.Owner);
              db.StoreUserPlantRelation(2, plantId_2, E_PlantRole.Guest);

              //validate
              Assert.True(db.ValidateUserUserForPlant(3, plantId_1, E_PlantRole.Owner));
              Assert.True(db.ValidateUserUserForPlant(3, plantId_1, E_PlantRole.Guest));
              Assert.True(db.ValidateUserUserForPlant(2, plantId_2, E_PlantRole.Guest));
              Assert.False(db.ValidateUserUserForPlant(2, plantId_2, E_PlantRole.Owner));

              //get owners
              var actual = db.GetUsersOfSolarPlant(plantId_2, E_PlantRole.Guest);
              Assert.AreEqual(1, actual.Count);
              Assert.AreEqual(2, actual[0]);

              //delete relationship
              db.DeleteUserHasPlantRelation(2, plantId_2, E_PlantRole.Guest);
              Assert.False(db.ValidateUserUserForPlant(2, plantId_2, E_PlantRole.Guest));
        }
        public void CalculateKwh_by_dayToDBTest()
        {
            var plantDb = new PlantRepository();
              int testPlantId = DatabaseHelpers.CreatePlantGetId();
              int privateInverterID = DatabaseHelpers.CreateInverter(testPlantId);
              int publicInverterId = plantDb.GetAllInvertersByPlant(testPlantId).First().PublicInverterId;

              var today = Utils.GetTodaysDate();
              var tomorow = today.AddDays(1);
              var dayAfterTomorow = tomorow.AddDays(1);

              //time frame for kwh calculation
              var timeFrameStart = Utils.CropHourMinuteSecond(today);
              var timeFrameEnd = timeFrameStart.AddDays(3);

              //time frame of test measures
              var todayStart = today.AddHours(8);
              var todayEnd = todayStart.AddHours(10);

              var tomorowStart = todayStart.AddDays(1);
              var tomorowEnd = tomorowStart.AddHours(8);

              var dayAfterTomorowStart = tomorowStart.AddDays(1);
              var dayAfterTomorowEnd = dayAfterTomorowStart.AddHours(8);

              //create test data and merge into one list
              var measureList = BigMama.GetMeasureList(todayStart, todayEnd, 1000, privateInverterID);
              var measureList_tomorow = BigMama.GetMeasureList(tomorowStart, tomorowEnd, 2000, privateInverterID);
              var measureList_dayAfterTomorow = BigMama.GetMeasureList(dayAfterTomorowStart, dayAfterTomorowEnd, 3000, privateInverterID);

              measureList.AddRange(measureList_tomorow);
              measureList.AddRange(measureList_dayAfterTomorow);

              var measureDb = new MeasureRepository();

              //Add test data to database

              measureDb.StartTransaction();
              measureList.ForEach(y=> _measureRepository.InsertMeasure(y));
              measureDb.CommitTransaction();

              //calculate kwh for each day and store in database
              var mgm = new MeasureManagement();
              mgm.ReCalculateKwh_by_dayToDB(timeFrameStart, timeFrameEnd, testPlantId);

              //read the calculated kwh days from the db
              var kwhDb = new KwhRepository();
              var actual = kwhDb.GetDayKwhByDateRange(timeFrameStart, timeFrameEnd, testPlantId);

              //Check the result from the db
              Assert.AreEqual(3, actual.Count);
              Assert.AreEqual(10.0, actual.GetKwh(today, publicInverterId).Value);
              Assert.AreEqual(16.0, actual.GetKwh(tomorow, publicInverterId).Value);
              Assert.AreEqual(24.0, actual.GetKwh(dayAfterTomorow, publicInverterId).Value);

              //check that removing all measures does not delete the day_kwh values
              //truncate measure table and refill with the DaT values
              _testDb.TruncateMinuteWiseMeasures();

              measureDb.StartTransaction();
              measureList_dayAfterTomorow.ForEach(y=>  measureDb.InsertMeasure(y));
              measureDb.CommitTransaction();

              //recalculate the kwh_days
              mgm.ReCalculateKwh_by_dayToDB(timeFrameStart, timeFrameEnd, testPlantId);
              var actual_2 = kwhDb.GetDayKwhByDateRange(timeFrameStart, timeFrameEnd, testPlantId);

              //results should be equal with those above
              Assert.AreEqual(3, actual.Count);
              Assert.AreEqual(10.0, actual.GetKwh(today, publicInverterId).Value);
              Assert.AreEqual(16.0, actual.GetKwh(tomorow, publicInverterId).Value);
              Assert.AreEqual(24.0, actual.GetKwh(dayAfterTomorow, publicInverterId).Value);
        }
Beispiel #3
0
 internal static int CreateInverter(int plantId)
 {
     var plantDb = new PlantRepository();
       return plantDb.CreateInverter(plantId, null, 0.4F, "Test-Generator");
 }
        private void UpdateTodaysKwhValues()
        {
            var plantRepo = new PlantRepository();
              var today = Utils.GetTodaysDate();

              foreach (var plant in plantRepo.GetAllPlants())
              {
            _measureManagement.ReCalculateKwh_by_dayToDB(today, today.AddDays(1), plant.PlantId);
              }
        }
Beispiel #5
0
 public static int CreatePlantGetId()
 {
     var plantDb = new PlantRepository();
       var plant = BigMama.GetPlant();
       return plantDb.CreatePlant(plant);
 }