public void when_generating_database_from_test_document_generator_then_succeeds()
        {
            var configuration = new AnmatConfiguration {
                DocumentsPath                 = "GeneratedDb",
                TargetDatabaseName            = this.GetDatabaseName("TestDb"),
                ReplaceExistingTargetDatabase = true
            };
            var updateVersion = new UpdateVersion {
                Number = version, Date = DateTime.UtcNow
            };
            var job = new DataGenerationJob
            {
                Version = updateVersion.Number,
                Status  = DataGenerationJobStatus.InProgress
            };

            var jobService = new Mock <IDataGenerationJobService> ();

            jobService
            .Setup(s => s.GetLatestJob())
            .Returns(job);
            var versionService = new Mock <IVersionService> ();

            versionService
            .Setup(r => r.IncrementVersion())
            .Returns(updateVersion);

            var sqlGenerator      = new SQLiteGenerator(jobService.Object, versionService.Object, configuration);
            var documentName      = "FooDocument";
            var document          = this.GetDocument();
            var documentGenerator = new Mock <IDocumentGenerator> ();

            documentGenerator
            .Setup(g => g.Name)
            .Returns(documentName);
            documentGenerator
            .Setup(g => g.Metadata)
            .Returns(TestMetadataGenerator.GetTestMetadata(documentName));
            documentGenerator
            .Setup(g => g.Generate())
            .Returns(document);

            var databaseFileName = sqlGenerator.GenerateDatabase(documentGenerator.Object);

            Assert.True(File.Exists(databaseFileName));
            Assert.False(string.IsNullOrEmpty(sqlGenerator.Script));

            var connectionString = string.Format("Data Source={0};Version=3;", databaseFileName);
            var connection       = new SQLiteConnection(connectionString);

            connection.Open();

            var command = new SQLiteCommand(@"SELECT COUNT(*) FROM " + documentName, connection);
            var read    = (long)command.ExecuteScalar();

            Assert.Equal(document.Rows.Count(), int.Parse(read.ToString()));

            connection.Close();
        }
        public void when_database_already_exists_and_configuration_does_not_allow_override_then_fails()
        {
            var configuration = new AnmatConfiguration {
                DocumentsPath                 = "GeneratedDb",
                TargetDatabaseName            = this.GetDatabaseName("TestDb"),
                ReplaceExistingTargetDatabase = false
            };
            var updateVersion = new UpdateVersion {
                Number = 2, Date = DateTime.UtcNow
            };
            var job = new DataGenerationJob
            {
                Version = updateVersion.Number,
                Status  = DataGenerationJobStatus.InProgress
            };

            var jobService = new Mock <IDataGenerationJobService> ();

            jobService
            .Setup(s => s.GetLatestJob())
            .Returns(job);
            var versionService = new Mock <IVersionService> ();

            versionService
            .Setup(r => r.IncrementVersion())
            .Returns(updateVersion);

            var sqlGenerator      = new SQLiteGenerator(jobService.Object, versionService.Object, configuration);
            var documentGenerator = new Mock <IDocumentGenerator> ();

            var databaseFileName = this.GetDatabaseFileName(configuration, sqlGenerator);

            using (File.Create(databaseFileName)) {};

            Assert.Throws <SQLGenerationException>(
                () => sqlGenerator.GenerateDatabase(documentGenerator.Object));
        }