Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                Config.Settings = Config.LoadFromExecutablePath();
                VerifyConnectionString();

                DatabaseCommand command = DatabaseCommand.Parse(args);
                Log.i(tag, command.Description());
                System.Console.WriteLine("Using: " + Config.Settings.ConnectionString);
                Stopwatch sw = new Stopwatch();
                sw.Start();
                command.Execute();
                var totalSeconds = sw.Elapsed.TotalSeconds;
                if (totalSeconds > 5)
                {
                    Log.w(tag, "Wasted " + TimeSpanString.ToString(sw.Elapsed) + " on: " + command.Description());
                }
            }
            catch (Exception caught)
            {
                System.Console.WriteLine(caught.Message);
                Log.e(tag, caught);
                Environment.Exit(1);
            }
            finally
            {
                Log.Flush();
            }
        }
Exemplo n.º 2
0
        public static async Task AfterTestRun()
        {
            if (bool.Parse(ConfigurationManager.AppSettings["RestoreDatabaseAfterTests"]))
            {
                DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseTeardown.sql");
                DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.LookupRestore.sql");
                DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseRestore.sql");
            }
            // Cleanup screenshot files after 1 day
            var storage = ConfigurationManager.AppSettings["TestScreenCaptureStorage"];

            if (Convert.ToBoolean(ConfigurationManager.AppSettings["TakeScreenShotOnFailure"]))
            {
                Console.WriteLine("Cleaning up screen captures older than 7 days");
                if (storage.Contains("Endpoint"))
                {
                    if (CloudStorageAccount.TryParse(storage, out var storageAccount))
                    {
                        CloudBlobClient cloudBlobClient    = storageAccount.CreateCloudBlobClient();
                        var             cloudBlobContainer = cloudBlobClient.GetContainerReference("selenium");
                        await cloudBlobContainer.CreateIfNotExistsAsync();

                        if (await cloudBlobContainer.ExistsAsync())
                        {
                            BlobContinuationToken continuationToken = null;
                            do
                            {
                                var results = await cloudBlobContainer.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, continuationToken, null, null);

                                continuationToken = results.ContinuationToken;
                                foreach (IListBlobItem blobItem in results.Results)
                                {
                                    if (blobItem is CloudBlockBlob blob)
                                    {
                                        if (blob.Properties.LastModified < DateTime.UtcNow.AddDays(-7))
                                        {
                                            await blob.DeleteIfExistsAsync();
                                        }
                                    }
                                }
                            } while (continuationToken != null);
                        }
                    }
                }
                else
                {
                    if (Directory.Exists(storage))
                    {
                        var screenshots = Directory.GetFiles(storage, "*.png")
                                          .Select(a => new FileInfo(a))
                                          .Where(b => b.CreationTimeUtc < DateTime.UtcNow.AddDays(-7))
                                          .ToList();
                        foreach (var screenshot in screenshots)
                        {
                            screenshot.Delete();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static void AfterTestRun()
 {
     if (bool.Parse(ConfigurationManager.AppSettings["RestoreDatabaseAfterTests"]))
     {
         DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseTeardown.sql");
         DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.LookupRestore.sql");
         DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseRestore.sql");
     }
 }
Exemplo n.º 4
0
        public async Task ExecuteWithNoParameters()
        {
            var log = A.Fake <ILogger>();
            var configurationProvider = A.Fake <IConfigurationProvider>();
            var stationProvider       = A.Fake <IStationProvider>();
            var command = new DatabaseCommand(log, s => {}, configurationProvider, stationProvider);

            var result = await command.Execute(new string[0]);

            A.CallTo(() => configurationProvider.Upload(A <Configuration> ._)).MustNotHaveHappened();
            A.CallTo(() => stationProvider.Reset()).MustNotHaveHappened();
            Assert.Equal(CommandResult.Error, result);
        }
Exemplo n.º 5
0
        public async Task Execute()
        {
            var log = A.Fake <ILogger>();
            var configurationProvider = A.Fake <IConfigurationProvider>();
            var stationProvider       = A.Fake <IStationProvider>();
            var command = new DatabaseCommand(log, s => {}, configurationProvider, stationProvider);

            var result = await command.Execute(new[] { "http://test.com" });

            A.CallTo(() => configurationProvider.Upload(A <Configuration> ._)).MustHaveHappened();
            A.CallTo(() => stationProvider.Reset()).MustHaveHappened();
            Assert.Equal(CommandResult.OK, result);
        }
Exemplo n.º 6
0
        public static async Task AfterTestRun()
        {
            if (bool.Parse(ConfigurationManager.AppSettings["RestoreDatabaseAfterTests"]))
            {
                DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseTeardown.sql");
                DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.LookupRestore.sql");
                DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseRestore.sql");
            }
            // Cleanup screenshot files after X days
            var numberOfDays = 3;
            var storage      = ConfigurationManager.AppSettings["TestScreenCaptureStorage"];

            if (Convert.ToBoolean(ConfigurationManager.AppSettings["TakeScreenShotOnFailure"]))
            {
                Console.WriteLine($"Cleaning up screen captures older than {numberOfDays} days");
                if (storage.Contains("Endpoint"))
                {
                    BlobServiceClient cloudBlobClient = new BlobServiceClient(storage);
                    var cloudBlobContainer            = cloudBlobClient.GetBlobContainerClient("selenium");
                    await cloudBlobContainer.CreateIfNotExistsAsync();

                    if (await cloudBlobContainer.ExistsAsync())
                    {
                        var results = cloudBlobContainer.GetBlobs(BlobTraits.None, BlobStates.All, null);
                        foreach (var blobItem in results)
                        {
                            if (blobItem.Properties.LastModified.HasValue && blobItem.Properties.LastModified.Value.UtcDateTime < DateTime.UtcNow.AddDays(-numberOfDays))
                            {
                                await cloudBlobContainer.DeleteBlobAsync(blobItem.Name);
                            }
                        }
                    }
                }
                else
                {
                    if (Directory.Exists(storage))
                    {
                        var screenshots = Directory.GetFiles(storage, "*.png")
                                          .Select(a => new FileInfo(a))
                                          .Where(b => b.CreationTimeUtc < DateTime.UtcNow.AddDays(-numberOfDays))
                                          .ToList();
                        foreach (var screenshot in screenshots)
                        {
                            screenshot.Delete();
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 public static void AfterTestRun()
 {
     if (bool.Parse(ConfigurationManager.AppSettings["RestoreDatabaseAfterTests"]))
     {
         DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseTeardown.sql");
         DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.LookupRestore.sql");
         DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.DatabaseRestore.sql");
     }
     if (Convert.ToBoolean(ConfigurationManager.AppSettings["TakeScreenShotOnFailure"]) && Directory.Exists(ConfigurationManager.AppSettings["TestScreenCaptureDirectory"]))
     {
         var screenshots = Directory.GetFiles(ConfigurationManager.AppSettings["TestScreenCaptureDirectory"], "*.png")
                           .Select(a => new FileInfo(a))
                           .Where(b => b.CreationTimeUtc < DateTime.UtcNow.AddDays(-1))
                           .ToList();
         foreach (var screenshot in screenshots)
         {
             screenshot.Delete();
         }
     }
 }
Exemplo n.º 8
0
 public void GivenIHaveTheStandardSetOfLookups()
 {
     DatabaseCommand.Execute("SecurityEssentials.Acceptance.Tests.Resources.LookupRestore.sql");
 }