1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Migrations.Design
{
using System.Collections.Generic;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Migrations.Model;
using System.Linq;
using Xunit;
public class MigrationCodeGeneratorTests
{
[Fact]
public void GetDefaultNamespaces_with_designer_false_returns_Migrations_namespace()
{
Assert.True(
new DummyCodeGenerator().GetDefaultNamespaces()
.SequenceEqual(
new[]
{
"System",
"System.Data.Entity.Migrations"
}));
}
[Fact]
public void GetDefaultNamespaces_with_designer_true_returns_Migrations_and_Infrastructure_namespace()
{
Assert.True(
new DummyCodeGenerator()
.GetDefaultNamespaces(designer: true)
.SequenceEqual(
new[]
{
"System.CodeDom.Compiler",
"System.Data.Entity.Migrations",
"System.Data.Entity.Migrations.Infrastructure",
"System.Resources"
}));
}
[Fact]
public void GetNamespaces_includes_spatial_namespace_when_geography_Add_column_operation_is_present()
{
Assert.True(
new DummyCodeGenerator()
.GetNamespaces(
new[]
{
new AddColumnOperation(
"T",
new ColumnModel(PrimitiveTypeKind.Geography))
})
.SequenceEqual(
new[]
{
"System",
"System.Data.Entity.Migrations",
"System.Data.Entity.Spatial"
}));
}
[Fact]
public void GetNamespaces_includes_spatial_namespace_when_geometry_Add_column_operation_is_present()
{
Assert.True(
new DummyCodeGenerator()
.GetNamespaces(
new[]
{
new AddColumnOperation(
"T",
new ColumnModel(PrimitiveTypeKind.Geometry))
})
.SequenceEqual(
new[]
{
"System",
"System.Data.Entity.Migrations",
"System.Data.Entity.Spatial"
}));
}
[Fact]
public void GetNamespaces_does_not_include_spatial_namespace_when_spatial_Add_column_operation_is_not_present()
{
Assert.True(
new DummyCodeGenerator()
.GetNamespaces(
new[]
{
new AddColumnOperation(
"T",
new ColumnModel(PrimitiveTypeKind.Int32))
})
.SequenceEqual(
new[]
{
"System",
"System.Data.Entity.Migrations"
}));
}
/// <summary>
/// Exposes protected methods for unit testing.
/// </summary>
public class DummyCodeGenerator : MigrationCodeGenerator
{
public new IEnumerable<string> GetNamespaces(IEnumerable<MigrationOperation> operations)
{
return base.GetNamespaces(operations);
}
public new IEnumerable<string> GetDefaultNamespaces(bool designer = false)
{
return base.GetDefaultNamespaces(designer);
}
public override ScaffoldedMigration Generate(
string migrationId, IEnumerable<MigrationOperation> operations,
string sourceModel, string targetModel, string @namespace,
string className)
{
throw new NotImplementedException();
}
}
}
}
|