public async Task <List <GetTop10DownloadTestsDto> > Handle(GetTop10DownloadTestsQuery request, CancellationToken cancellationToken) { const string sql = "SELECT " + "d.[DeviceId], " + "SUM(dt.[TotalBytesDownloaded]) AS [TotalBytesDownloaded], " + "MAX(d.DeviceName) AS [DeviceName], " + "MAX(d.DeviceGuid) AS [DeviceGuid], " + "MAX(dt.Country) AS [Country], " + "MAX(d.OsId) AS [OsId] " + "FROM [DownloadTest] dt " + "INNER JOIN [Device] d ON d.[DeviceId] = dt.[DeviceId] " + "GROUP BY d.[DeviceId]"; using var connection = _sqlConnectionFactory.GetOpenConnection(); var result = await connection.QueryAsync <GetTop10DownloadTestsDto>(sql); return(result.ToList()); }
public void GetTop10DownloadTests_WhenCalled_ReturnsDevice1OnFirstPlace() { var expectedPositionDevice = Device1Guid; using var context = new WasteDataContext(options); var mediator = new Mock <IMediator>(); var sqlConnectionFactory = new Mock <ISqlConnectionFactory>(); GetTop10DownloadTestsQuery query = new GetTop10DownloadTestsQuery(); GetTop10DownloadTestsQueryHandler handler = new GetTop10DownloadTestsQueryHandler(sqlConnectionFactory.Object); //TODO how to test Dapper query //var result = handler.Handle(query, new System.Threading.CancellationToken()).Result; //var listOrderedByTotalBytesDownloadedDesc = result.OrderByDescending(p => p.TotalBytesDownloaded); //var deviceFirstPosition = listOrderedByTotalBytesDownloadedDesc.First(); //Assert.Equal(expectedPositionDevice, deviceFirstPosition.DeviceGuid.ToString()); }