protected LimitLoger(string configurationName, SLimits.LimitData limit)
        {
            this.ConfigurationName = configurationName;
              this.Limit = limit;

              this.UsedAmount = limit.Max - limit.Remaining;
              this.UsedPercents = (int)Math.Round((double)this.UsedAmount * 100 / limit.Max);
        }
        protected virtual void ProcessLimit(SLimits.LimitData limit, ILimitLoger limitLoger, int threshold)
        {
            if (threshold >= 0 && threshold <= 100)
              {
            if (limitLoger.UsedPercents >= threshold)
            {
              limitLoger.LogPointWarning();
            }
              }

              if (limit.Remaining == 0)
              {
            limitLoger.LogHasReachedError();
              }
        }
        public virtual void ProcessLimits(SLimits limits)
        {
            if (limits != null)
              {
            if (this.LogStatistic)
            {
              this.loger.LogStatisticInfo();
            }

            this.ProcessLimit(limits.DailyApiRequests, this.loger.ApiDailyRequestsLoger, this.ApiUsageThreshold);
            this.ProcessLimit(limits.DataStorageMb, this.loger.DataStorageLoger, this.DataStorageThreshold);
              }
              else
              {
            this.loger.LogInformationAreNotAvailableWarning();
              }
        }
 public ApiDailyRequestsLoger(string configurationName, SLimits.LimitData limit)
     : base(configurationName, limit)
 {
 }
 public DataStorageLoger(string configurationName, SLimits.LimitData limit)
     : base(configurationName, limit)
 {
 }
        public void ProcessLimitsTest(
      string configurationName,
      SLimits limits, 
      bool logStatistic, 
      int apiUsageThreshold, 
      int dataStorageThreshold,
      Times[] result)
        {
            var mockedApiDailyRequestsLoger = new Moq.Mock<ILimitLoger>();
              if (limits != null)
              {
            var apiDailyRequestsLoger = new ApiDailyRequestsLoger(configurationName, limits.DailyApiRequests);
            mockedApiDailyRequestsLoger.SetupGet(p => p.UsedAmount).Returns(apiDailyRequestsLoger.UsedAmount);
            mockedApiDailyRequestsLoger.SetupGet(p => p.UsedPercents).Returns(apiDailyRequestsLoger.UsedPercents);
              }

              mockedApiDailyRequestsLoger.Setup(m => m.LogPointWarning()).Verifiable();
              mockedApiDailyRequestsLoger.Setup(m => m.LogHasReachedError()).Verifiable();

              var mockedDataStorageLoger = new Moq.Mock<ILimitLoger>();
              if (limits != null)
              {
            var dataStorageLoger = new ApiDailyRequestsLoger(configurationName, limits.DataStorageMb);
            mockedDataStorageLoger.SetupGet(p => p.UsedAmount).Returns(dataStorageLoger.UsedAmount);
            mockedDataStorageLoger.SetupGet(p => p.UsedPercents).Returns(dataStorageLoger.UsedPercents);
              }

              mockedDataStorageLoger.Setup(m => m.LogPointWarning()).Verifiable();
              mockedDataStorageLoger.Setup(m => m.LogHasReachedError()).Verifiable();

              var mockedLoger = new Moq.Mock<ILimitsLoger>();
              mockedLoger.SetupGet(p => p.ApiDailyRequestsLoger).Returns(mockedApiDailyRequestsLoger.Object);
              mockedLoger.SetupGet(p => p.DataStorageLoger).Returns(mockedDataStorageLoger.Object);
              mockedLoger.Setup(m => m.LogStatisticInfo()).Verifiable();
              mockedLoger.Setup(m => m.LogInformationAreNotAvailableWarning()).Verifiable();

              var agent = new LimitsAgent();
              agent.LogStatistic = logStatistic;
              agent.ApiUsageThreshold = apiUsageThreshold;
              agent.DataStorageThreshold = dataStorageThreshold;
              var logerField = typeof(LimitsAgent).GetField("loger", BindingFlags.Instance | BindingFlags.NonPublic);
              if (logerField != null)
              {
            logerField.SetValue(agent, mockedLoger.Object);
              }

              agent.ProcessLimits(limits);

              mockedLoger.Verify(m => m.LogStatisticInfo(), result[0]);
              mockedLoger.Verify(m => m.LogInformationAreNotAvailableWarning(), result[1]);
              mockedApiDailyRequestsLoger.Verify(m => m.LogPointWarning(), result[2]);
              mockedApiDailyRequestsLoger.Verify(m => m.LogHasReachedError(), result[3]);
              mockedDataStorageLoger.Verify(m => m.LogPointWarning(), result[4]);
              mockedDataStorageLoger.Verify(m => m.LogHasReachedError(), result[5]);
        }