Exemplo n.º 1
0
        public async Task WhenInstanceCreated_ThenListInstanceEventsAsyncCanFeedHistorySetBuilder(
            [LinuxInstance] InstanceRequest testInstance)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var instanceBuilder = new InstanceSetHistoryBuilder(
                DateTime.UtcNow.AddDays(-7),
                DateTime.UtcNow);

            var computeAdapter = new ComputeEngineAdapter(Defaults.GetCredential());

            instanceBuilder.AddExistingInstances(
                await computeAdapter.ListInstancesAsync(Defaults.ProjectId, CancellationToken.None),
                await computeAdapter.ListDisksAsync(Defaults.ProjectId, CancellationToken.None),
                Defaults.ProjectId);

            var adapter = new AuditLogAdapter(Defaults.GetCredential());

            await adapter.ListInstanceEventsAsync(
                new[] { Defaults.ProjectId },
                null,  // all zones.
                null,  // all instances.
                instanceBuilder.StartDate,
                instanceBuilder,
                CancellationToken.None);

            var set = instanceBuilder.Build();
            var testInstanceHistory = set.Instances.FirstOrDefault(i => i.Reference == instanceRef);

            Assert.IsNotNull(testInstanceHistory, "Instance found in history");
        }
Exemplo n.º 2
0
        public async Task WhenUserNotInRole_ThenListInstanceEventsAsyncThrowsResourceAccessDeniedException(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var instanceBuilder = new InstanceSetHistoryBuilder(
                DateTime.UtcNow.AddDays(-7),
                DateTime.UtcNow);

            var adapter = new AuditLogAdapter(await credential.GetCredentialAsync());

            AssertEx.ThrowsAggregateException <ResourceAccessDeniedException>(
                () => adapter.ListInstanceEventsAsync(
                    new[] { TestProject.ProjectId },
                    null,  // all zones.
                    null,  // all instances.
                    instanceBuilder.StartDate,
                    instanceBuilder,
                    CancellationToken.None).Wait());
        }