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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace FunctionalTests
{
using System;
using System.Data.Entity;
using FunctionalTests.Fixtures;
using Xunit;
public class SpatialScenarioTests : TestBase
{
[Fact]
public void Simple_spatial_mapping_scenario()
{
var modelBuilder = new DbModelBuilder();
modelBuilder.Entity<Spatial_Customer>();
var databaseMapping = BuildMapping(modelBuilder);
databaseMapping.AssertValid();
databaseMapping.Assert<Spatial_Customer>(c => c.Geography).DbEqual("geography", c => c.TypeName);
databaseMapping.Assert<Spatial_Customer>(c => c.Geometry).DbEqual("geometry", c => c.TypeName);
}
[Fact]
public void Complex_type_spatial_mapping_scenario()
{
var modelBuilder = new DbModelBuilder();
modelBuilder.Entity<Spatial_ComplexClass>();
var databaseMapping = BuildMapping(modelBuilder);
databaseMapping.AssertValid();
databaseMapping.Assert<Spatial_ComplexType>(c => c.Geography).DbEqual("geography", c => c.TypeName);
databaseMapping.Assert<Spatial_ComplexType>(c => c.Geometry).DbEqual("geometry", c => c.TypeName);
}
[Fact]
public void Configure_spatial_members_on_type()
{
var modelBuilder = new DbModelBuilder();
modelBuilder.Entity<Spatial_Customer>().Property(c => c.Geography).HasColumnName("the_column");
var databaseMapping = BuildMapping(modelBuilder);
databaseMapping.AssertValid();
databaseMapping.Assert<Spatial_Customer>(c => c.Geography).DbEqual("the_column", c => c.Name);
}
[Fact]
public void Should_be_able_to_use_v4_1_model_builder_without_spatials()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>();
var databaseMapping = BuildMapping(modelBuilder);
databaseMapping.AssertValid();
Assert.Equal(2.0, databaseMapping.Model.Version);
Assert.Equal(2.0, databaseMapping.Database.Version);
}
[Fact]
public void Explicitly_mapping_a_DbGeography_property_using_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().Property(e => e.Geography);
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_Customer", "Geography");
}
[Fact]
public void Explicitly_mapping_a_DbGeography_property_on_a_complex_type_using_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.ComplexType<Spatial_ComplexType>().Property(c => c.Geography);
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_ComplexType", "Geography");
}
[Fact]
public void Explicitly_using_a_DbGeography_property_as_a_key_with_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().HasKey(e => e.Geography);
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_Customer", "Geography");
}
[Fact]
public void Explicitly_using_a_DbGeography_property_as_part_of_a_composite_key_with_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().HasKey(
e => new
{
e.Id,
e.Geography
});
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_Customer", "Geography");
}
[Fact]
public void Explicitly_mapping_a_DbGeography_property_with_Map_using_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().Map(
mapping =>
{
mapping.ToTable("Table1");
mapping.Properties(e => e.Geography);
});
Assert.Throws<InvalidOperationException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("EntityMappingConfiguration_CannotMapIgnoredProperty", "Spatial_Customer", "Geography");
}
[Fact]
public void Explicitly_mapping_a_DbGeometry_property_using_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().Property(e => e.Geometry);
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_Customer", "Geometry");
}
[Fact]
public void Explicitly_mapping_a_DbGeometry_property_on_a_complex_type_using_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.ComplexType<Spatial_ComplexType>().Property(c => c.Geometry);
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_ComplexType", "Geometry");
}
[Fact]
public void Explicitly_using_a_DbGeometry_property_as_a_key_with_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().HasKey(e => e.Geometry);
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_Customer", "Geometry");
}
[Fact]
public void Explicitly_using_a_DbGeometry_property_as_part_of_a_composite_key_with_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().HasKey(
e => new
{
e.Id,
e.Geometry
});
Assert.Throws<NotSupportedException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("UnsupportedUseOfV3Type", "Spatial_Customer", "Geometry");
}
[Fact]
public void Explicitly_mapping_a_DbGeometry_property_with_Map_using_4_1_throws()
{
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<Spatial_Customer>().Map(
mapping =>
{
mapping.ToTable("Table1");
mapping.Properties(e => e.Geometry);
});
Assert.Throws<InvalidOperationException>(
() =>
BuildMapping(modelBuilder))
.ValidateMessage("EntityMappingConfiguration_CannotMapIgnoredProperty", "Spatial_Customer", "Geometry");
}
}
namespace Fixtures
{
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public class Spatial_Customer
{
public int Id { get; set; }
public DbGeometry Geometry { get; set; }
[Required]
public DbGeography Geography { get; set; }
}
public class Spatial_ComplexClass
{
public int Id { get; set; }
public Spatial_ComplexType Complex { get; set; }
}
[ComplexType]
public class Spatial_ComplexType
{
[Column("c")]
public DbGeometry Geometry { get; set; }
public DbGeography Geography { get; set; }
}
}
}
|