コード例 #1
0
        private async Task <DatabaseUsage> LoadDatabaseUsageAsync(CancellationToken cancel)
        {
            await ExclusiveBlock.RunAsync(ExclusiveBlockKey, Guid.NewGuid().ToString(),
                                          ExclusiveBlockType.WaitForReleased, new ExclusiveLockOptions(), cancel,
                                          async() =>
            {
                var loader           = new DatabaseUsageLoader(Providers.Instance.DataProvider); //UNDONE:<?usage: GetService
                var dbUsage          = await loader.LoadAsync(cancel).ConfigureAwait(false);
                _loadedDatabaseUsage = dbUsage;
            });

            return(_loadedDatabaseUsage);
        }
コード例 #2
0
        public async Task DbUsage_PreviewsVersionsBlobsTexts()
        {
            // Use ExclusiveBlock component in the DbUsage integration tests?
            await IntegrationTestAsync(async() =>
            {
                var user1 = new User(Node.LoadNode("/Root/IMS/Public"))
                {
                    Name    = "User1",
                    Enabled = true,
                    Email   = "*****@*****.**",
                };
                user1.Save();

                var dataProvider  = Providers.Instance.DataProvider;
                var loader        = new DatabaseUsageLoader(dataProvider);
                var profileBefore = await loader.LoadAsync();

                CreateStructure(user1, out var folder, out var file);

                // ACTION
                loader      = new DatabaseUsageLoader(dataProvider);
                var profile = await loader.LoadAsync();

                // ASSERT
                var versionCount = await dataProvider.GetVersionCountAsync("/Root", CancellationToken.None);
                Assert.AreEqual(6 * 4, profile.Preview.Count);
                Assert.AreEqual(6, profile.Content.Count);
                Assert.AreEqual(4, profile.OldVersions.Count);
                Assert.AreEqual(versionCount - profile.Preview.Count - profile.Content.Count - profile.OldVersions.Count,
                                profile.System.Count);

                Assert.AreEqual(6 * (144L + 145L + 146L + 147L + 4 * 3), profile.Preview.Blob);
                Assert.AreEqual(47 + 44 + 2 * 3, profile.Content.Blob);
                Assert.AreEqual(42 + 43 + 45 + 46 + 4 * 3, profile.OldVersions.Blob);
                Assert.AreEqual(profileBefore.System.Blob, profile.System.Blob);

                var folderText = 2 * folder.Description.Length;
                var oneText    = 2 * file.Description.Length;
                Assert.AreEqual(0, profile.Preview.Text);
                Assert.AreEqual(profileBefore.Content.Text + 2 * oneText + folderText, profile.Content.Text);
                Assert.AreEqual(4 * oneText, profile.OldVersions.Text);
                Assert.AreEqual(profileBefore.System.Text, profile.System.Text);

                Assert.IsTrue(DateTime.UtcNow - profile.Executed < TimeSpan.FromSeconds(1),
                              "Expectation: DateTime.UtcNow - profile.Executed < TimeSpan.FromSeconds(1).");
                Assert.IsTrue(profile.ExecutionTime > TimeSpan.Zero,
                              "Expectation: profile.ExecutionTime > TimeSpan.Zero");
                Assert.IsTrue(profile.ExecutionTime < TimeSpan.MaxValue,
                              "Expectation: profile.ExecutionTime < TimeSpan.MaxValue");
            });
        }