public async void IntegrationTest(IEnumerable <Tuple <int, int> > data, DatasetStatistics expectedStatistics) { var datasets = this.datasetService.GetDatasets(); Assert.False(EnumerableExtensions.Any(datasets), "There should be no dataset when starting"); var datasetId = (await this.datasetService.CreateDataset("Test")).Id; datasets = this.datasetService.GetDatasets(); Assert.Equal(1, datasets.Count); var dataset = datasets.SingleOrDefault(d => d.Id == datasetId); Assert.NotNull(dataset); Assert.Equal(DatasetStatus.Created, dataset.Status); await this.datasetService.ImportDataset(datasetId, data); datasets = this.datasetService.GetDatasets(); Assert.Equal(1, datasets.Count); dataset = datasets.SingleOrDefault(d => d.Id == datasetId); Assert.NotNull(dataset); Assert.Equal(DatasetStatus.Imported, dataset.Status); var stats = this.datasetService.GetDatasetStatistics(datasetId); Assert.Equal(expectedStatistics.AverageFriendCount, stats.AverageFriendCount); Assert.Equal(expectedStatistics.UniqueUsers, stats.UniqueUsers); await this.datasetService.DeleteDataset(datasetId); datasets = this.datasetService.GetDatasets(); Assert.False(EnumerableExtensions.Any(datasets), "There should be no dataset after we deleted ours"); }
/// <summary> /// Loads statistics of the dataset. /// </summary> /// <returns></returns> protected override DatasetStatistics LoadDatasetStatistics() { var sql = @" -- Raw data space in 8K pages SELECT SUM(f.size) FROM sys.database_files f WHERE f.type = 0 -- Total used space SELECT SUM(a.total_pages), SUM(a.used_pages), SUM(a.data_pages) FROM sys.allocation_units a -- Log space SELECT SUM(size) FROM sys.database_files f WHERE f.type = 1 "; using (var cn = OpenConnection()) { using (var cmd = new SqlCommand(sql, cn)) { using (var dr = cmd.ExecuteReader()) { var stats = new DatasetStatistics(); // Data space dr.Read(); stats.DataSpace = dr.IsDBNull(0) ? 0L : (long)dr.GetInt32(0) * 0x2000; // 8K pages // Index space dr.NextResult(); dr.Read(); stats.UsedSpace = dr.IsDBNull(0) ? 0L : dr.GetInt64(0) * 0x2000; // 8K pages // Row count dr.NextResult(); dr.Read(); stats.LogSpace = dr.IsDBNull(0) ? 0L : (long)dr.GetInt32(0) * 0x2000; // 8K pages return(stats); } } } }