Exemple #1
0
        public async Task GetDataCollectorPerformance_WhenDataCollectorsHaveReported_ShouldReturnCorrectStatus(string phoneNumber, List <RawReport> reports)
        {
            // Arrange
            var rawReportsMockDbSet = reports.AsQueryable().BuildMockDbSet();
            var dataCollectors      = new List <DataCollector>
            {
                new DataCollector
                {
                    PhoneNumber = phoneNumber,
                    Project     = new Project {
                        Id = ProjectId
                    },
                    RawReports = reports
                }
            };
            var dataCollectorsMockDbSet = dataCollectors.AsQueryable().BuildMockDbSet();

            _nyssContextMock.RawReports.Returns(rawReportsMockDbSet);
            _nyssContextMock.DataCollectors.Returns(dataCollectorsMockDbSet);

            var dateTimeNow = DateTime.UtcNow;

            // Act
            var result = await _dataCollectorService.Performance(ProjectId);

            // Assert
            result.Value[0].StatusLastWeek.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 0)));
            result.Value[0].StatusTwoWeeksAgo.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 1)));
            result.Value[0].StatusThreeWeeksAgo.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 2)));
            result.Value[0].StatusFourWeeksAgo.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 3)));
            result.Value[0].StatusFiveWeeksAgo.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 4)));
            result.Value[0].StatusSixWeeksAgo.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 5)));
            result.Value[0].StatusSevenWeeksAgo.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 6)));
            result.Value[0].StatusEightWeeksAgo.ShouldBe(DataCollectorStatusFromReports(reports.Where(r => (int)(dateTimeNow - r.ReceivedAt).TotalDays / 7 == 7)));
        }
 public async Task <Result <List <DataCollectorPerformanceResponseDto> > > Performance(int projectId) =>
 await _dataCollectorService.Performance(projectId);