public void ExecuteTest()
        {
            //arrange
            DatabaseSchema schema = PrepareModel();
            var settings = new CodeWriterSettings();
            var target = new CodeFirstContextWriter(settings);

            //act
            var result = target.Write(schema.Tables);

            //assert
            var hasDbSet = result.Contains("public IDbSet<Product> ProductCollection");
            var hasMapping = result.Contains("modelBuilder.Configurations.Add(new ProductMapping());");
            Assert.IsTrue(hasDbSet);
            Assert.IsTrue(hasMapping);
        }
        public void ExecuteTest()
        {
            //arrange
            var schema = PrepareModel();
            var settings = new CodeWriterSettings { CodeTarget = CodeTarget.PocoEfCore};
            var target = new CodeFirstContextWriter(settings);

            //act
            var result = target.Write(schema.Tables);

            //assert
            var hasDbSet = result.Contains("public DbSet<Product> ProductCollection");
            var hasOnModelCreating = result.Contains("protected override void OnModelCreating(ModelBuilder modelBuilder)");
            var hasMapping = result.Contains("modelBuilder.Entity<Product>(ProductMapping.Map);");
            Assert.IsTrue(hasDbSet);
            Assert.IsTrue(hasOnModelCreating);
            Assert.IsTrue(hasMapping);
        }
        public void ExecuteTest()
        {
            //arrange
            DatabaseSchema schema = PrepareModel();
            var settings = new CodeWriterSettings();
            settings.IncludeViews = true;
            var target = new CodeFirstContextWriter(settings);
            var list = new List<DatabaseTable>(schema.Tables);
            list.AddRange(schema.Views.OfType<DatabaseTable>());

            //act
            var result = target.Write(list);

            //assert
            var hasDbSet = result.Contains("public IDbSet<AlphabeticCategory> AlphabeticCategoryCollection");
            var hasMapping = result.Contains("modelBuilder.Configurations.Add(new AlphabeticCategoryMapping());");
            Assert.IsTrue(hasDbSet);
            Assert.IsTrue(hasMapping);
        }
Example #4
0
 private string WriteDbContext(FileSystemInfo directory, ProjectWriter projectWriter)
 {
     var writer = new CodeFirstContextWriter(_codeWriterSettings);
     if (ProviderToSqlType.Convert(_schema.Provider) == SqlType.Oracle)
     {
         writer.IsOracle = true;
         projectWriter.AddDevartOracleReference();
     }
     var databaseTables = _schema.Tables.Where(t => !FilterIneligible(t))
         .ToList();
     if (_codeWriterSettings.IncludeViews)
     {
         databaseTables.AddRange(_schema.Views.OfType<DatabaseTable>());
     }
     var txt = writer.Write(databaseTables);
     var fileName = writer.ContextName + ".cs";
     File.WriteAllText(
         Path.Combine(directory.FullName, fileName),
         txt);
     projectWriter.AddClass(fileName);
     return writer.ContextName;
 }