public void ReturnLatestRecords()
        {
            var inputData = new DataModel[100];
            for (var i = 0; i < 100; i++)
            {
                inputData[i] = new DataModel {MembersCount = i + 1};
            }
            dataProviderMock.Setup(m => m.GetAllRecords()).Returns(inputData);

            var expectedTable = new[]
            {
                new DataModel {MembersCount = 100},
                new DataModel {MembersCount = 99},
                new DataModel {MembersCount = 98},
                new DataModel {MembersCount = 97},
                new DataModel {MembersCount = 96}
            };

            var expectedChart = new[]
            {
                new DataModel {MembersCount = 100},
                new DataModel {MembersCount = 99},
                new DataModel {MembersCount = 98}
            };

            var provider = new DataProvider(dataProviderMock.Object, 3, 5);
            var count = provider.GetRecordsCount();
            var recordsForChart = provider.GetRecordsForChart();
            var recordsForTable = provider.GetRecordsForInfoTable();

            Assert.AreEqual(count, 100);
            CollectionAssert.AreEqual(expectedTable, recordsForTable);
            CollectionAssert.AreEqual(expectedChart, recordsForChart);
        }
Exemple #2
0
 public void AddRecord(DataModel model)
 {
     db.Statistic.Add(new Statistic
     {
         Id = 0,
         MembersCount = model.MembersCount,
         UpdatingTime = model.UpdatingTime
     });
 }
 public DataModel[] Precount(DataModel[] records)
 {
     for (var i = 0; i < records.Length; i++)
     {
         if (i < records.Length - 1)
             records[i].Delta = records[i].MembersCount - records[i + 1].MembersCount;
         records[i].UpdatingTime = ConvertToLocalTime(records[i].UpdatingTime);
     }
     return records;
 }
Exemple #4
0
        private ActionResult ParseStatistic(DataModel[] records, IGroupInfoProvider infoProvider)
        {
            for (int i = 0; i < records.Length; i++)
            {
                if (i>0)
                    records[i].Delta = records[i].MembersCount - records[i - 1].MembersCount;
                records[i].UpdatingTime = ConvertToLocalTime(records[i].UpdatingTime);
            }

            var model = new StatisticModel
            {
                GroupName = infoProvider.GetSavedGroupName(),
                GroupUrl = infoProvider.GetSavedGroupUrl(),
                RecordsCount = records.Length,
                LastUpdateTime = records.Max(st => st.UpdatingTime),
                Records = records.Reverse().ToArray() //последние записи должны отображаться в начале
            };

            return View("Index", model);
        }
        private ActionResult ParseStatistic(DataModel[] records, IGroupInfoProvider infoProvider)
        {
            records = Precount(records);

            var model = new StatisticModel
            {
                GroupName = infoProvider.GetSavedGroupName(),
                GroupUrl = infoProvider.GetSavedGroupUrl(),
                RecordsCount = dataProvider.GetRecordsCount(),
                LastUpdateTime = records.Max(st => st.UpdatingTime),
                Records = records.ToArray()
            };

            return View("GetAll", model);
        }