/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(ProductAttributeValue.FormulaKey)).AsString(10).Nullable() .WithColumn(nameof(ProductAttributeMapping.ProductAttributeId)).AsInt32().ForeignKey <ProductAttribute>() .WithColumn(nameof(ProductAttributeMapping.ProductId)).AsInt32().ForeignKey <Product>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(StateProvince.Name)).AsString(100).NotNullable() .WithColumn(nameof(StateProvince.Abbreviation)).AsString(100).Nullable() .WithColumn(nameof(StateProvince.CountryId)).AsGuid().ForeignKey <Country>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(ReturnRequest.ReasonForReturn)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(ReturnRequest.RequestedAction)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(ReturnRequest.CustomerId)).AsInt32().ForeignKey <Customer>(); }
public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(CategoryAttributeMapping.CategoryAttributeId)).AsGuid() .ForeignKey <CategoryAttribute>() .WithColumn(nameof(CategoryAttributeMapping.CategoryId)).AsGuid().ForeignKey <Nop.Core.Domain.Catalog.Category>(); }
public void CallingForeignKeySetForeignKey() { var expressionMock = new Mock <CreateTableExpression>(); var contextMock = new Mock <IMigrationContext>(); contextMock.SetupGet(x => x.Expressions).Returns(new List <IMigrationExpression>()); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.CurrentColumn = new ColumnDefinition(); var fk = new ForeignKeyDefinition { Name = "foreignKeyName", PrimaryTable = "primaryTableName", PrimaryTableSchema = "primaryTableSchema", ForeignTable = builder.Expression.TableName, ForeignTableSchema = builder.Expression.SchemaName }; builder.ForeignKey(fk.Name, fk.PrimaryTableSchema, fk.PrimaryTable, "primaryColumnName"); Assert.IsTrue(builder.CurrentColumn.IsForeignKey); Assert.AreEqual(builder.CurrentColumn.ForeignKey.Name, fk.Name); Assert.AreEqual(builder.CurrentColumn.ForeignKey.PrimaryTable, fk.PrimaryTable); Assert.AreEqual(builder.CurrentColumn.ForeignKey.PrimaryTableSchema, fk.PrimaryTableSchema); Assert.AreEqual(builder.CurrentColumn.ForeignKey.ForeignTable, fk.ForeignTable); Assert.AreEqual(builder.CurrentColumn.ForeignKey.ForeignTableSchema, fk.ForeignTableSchema); }
public void Issue804() { var serviceProvider = new ServiceCollection().BuildServiceProvider(); var querySchema = new Mock <IQuerySchema>(); var context = new MigrationContext(querySchema.Object, serviceProvider, null, null); var expression = new CreateTableExpression() { TableName = "Contact", }; var builder = new CreateTableExpressionBuilder(expression, context); builder .WithColumn("Id").AsInt32().NotNullable().PrimaryKey().Identity() .WithColumn("FirstName").AsString(30).Nullable() .WithColumn("FamilyName").AsString(50).NotNullable() .WithColumn("Whatever1").AsString() .WithColumn("Whatever2").AsString(50).Nullable() .WithColumn("Whatever3").AsString(); var result = Generator.Generate(expression); result.ShouldBe("CREATE TABLE \"Contact\" (\"Id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \"FirstName\" TEXT, \"FamilyName\" TEXT NOT NULL, \"Whatever1\" TEXT NOT NULL, \"Whatever2\" TEXT, \"Whatever3\" TEXT NOT NULL)"); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(BackInStockSubscription.CustomerId)).AsGuid().ForeignKey <Customer>() .WithColumn(nameof(BackInStockSubscription.StoreId)).AsGuid().ForeignKey <Store>() .WithColumn(nameof(BackInStockSubscription.ProductId)).AsGuid().ForeignKey <Product>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(Log.ShortMessage)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(Log.IpAddress)).AsString(200).Nullable() .WithColumn(nameof(Log.CustomerId)).AsInt32().Nullable().ForeignKey <Customer>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(PermissionRecord.Name)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(PermissionRecord.SystemName)).AsString(255).NotNullable() .WithColumn(nameof(PermissionRecord.Category)).AsString(255).NotNullable(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(Enrollment.CourseId)).AsInt32().ForeignKey <Course>() .WithColumn(nameof(Enrollment.Grade)).AsInt32().NotNullable() .WithColumn(nameof(Enrollment.StudentId)).AsInt32().ForeignKey <Student>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(ForumTopic.Subject)).AsString(450).NotNullable() .WithColumn(nameof(ForumTopic.CustomerId)).AsInt32().ForeignKey <Customer>(onDelete: Rule.None) .WithColumn(nameof(ForumTopic.ForumId)).AsInt32().ForeignKey <Forum>(); }
public void CallingUniqueNamedAddsIndexExpressionToContext() { var collectionMock = new Mock <ICollection <IMigrationExpression> >(); var contextMock = new Mock <IMigrationContext>(); contextMock.Setup(x => x.Expressions).Returns(collectionMock.Object); var columnMock = new Mock <ColumnDefinition>(); columnMock.SetupGet(x => x.Name).Returns("BaconId"); var expressionMock = new Mock <CreateTableExpression>(); expressionMock.SetupGet(x => x.SchemaName).Returns("Eggs"); expressionMock.SetupGet(x => x.TableName).Returns("Bacon"); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object) { CurrentColumn = columnMock.Object }; builder.Unique("IX_Bacon_BaconId"); collectionMock.Verify(x => x.Add(It.Is <CreateIndexExpression>( ix => ix.Index.Name == "IX_Bacon_BaconId" && ix.Index.TableName == "Bacon" && ix.Index.SchemaName == "Eggs" && ix.Index.IsUnique && !ix.Index.IsClustered && ix.Index.Columns.All(c => c.Name == "BaconId") ))); contextMock.VerifyGet(x => x.Expressions); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(LocaleStringResource.ResourceName)).AsString(200).NotNullable() .WithColumn(nameof(LocaleStringResource.ResourceValue)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(LocaleStringResource.LanguageId)).AsGuid().ForeignKey <Language>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(BlogComment.StoreId)).AsInt32().ForeignKey <Store>() .WithColumn(nameof(BlogComment.CustomerId)).AsInt32().ForeignKey <Customer>() .WithColumn(nameof(BlogComment.BlogPostId)).AsInt32().ForeignKey <BlogPost>(); }
/// <summary> /// Defines the column specifications by default /// </summary> /// <param name="type">Type of entity</param> /// <param name="create">An expression builder for a FluentMigrator.Expressions.CreateTableExpression</param> /// <param name="propertyInfo">Property info</param> /// <param name="canBeNullable">The value indicating whether this column is nullable</param> protected virtual void DefineByOwnType(Type type, CreateTableExpressionBuilder create, PropertyInfo propertyInfo, bool canBeNullable = false) { var propType = propertyInfo.PropertyType; if (Nullable.GetUnderlyingType(propType) is Type uType) { propType = uType; canBeNullable = true; } if (!_typeMapping.ContainsKey(propType)) { return; } if (type == typeof(string) || propType.FindInterfaces((t, o) => t.FullName?.Equals(o.ToString(), StringComparison.InvariantCultureIgnoreCase) ?? false, "System.Collections.IEnumerable").Any()) { canBeNullable = true; } var column = create.WithColumn(NameCompatibilityManager.GetColumnName(type, propertyInfo.Name)); _typeMapping[propType](column); if (canBeNullable) { create.Nullable(); } }
public override void MapEntity(CreateTableExpressionBuilder table) { table.WithColumn(nameof(ProductAnnouncementAttributeMapping.ProductAnnouncementAttributeId)).AsGuid() .ForeignKey <ProductAnnouncementAttribute>() .WithColumn(nameof(ProductAnnouncementAttributeMapping.ProductAnnouncementId)).AsGuid() .ForeignKey <Models.ProductAnnouncement>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(Campaign.Name)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(Campaign.Subject)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(Campaign.Body)).AsString(int.MaxValue).NotNullable(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(GenericAttribute.KeyGroup)).AsString(400).NotNullable() .WithColumn(nameof(GenericAttribute.Key)).AsString(400).NotNullable() .WithColumn(nameof(GenericAttribute.Value)).AsString(int.MaxValue).NotNullable(); }
public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(ShippingByWeightByTotalRecord.WeightFrom)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.WeightTo)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.LengthFrom)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.LengthTo)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.WidthFrom)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.WidthTo)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.HeightFrom)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.HeightTo)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.OrderSubtotalFrom)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.OrderSubtotalTo)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.AdditionalFixedCost)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.PercentageRateOfSubtotal)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.RatePerWeightUnit)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.LowerWeightLimit)) .AsDecimal(18, 2) .WithColumn(nameof(ShippingByWeightByTotalRecord.Zip)) .AsString(400) .Nullable(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(ProductReview.CustomerId)).AsGuid().ForeignKey <Customer>() .WithColumn(nameof(ProductReview.ProductId)).AsGuid().ForeignKey <Product>() .WithColumn(nameof(ProductReview.StoreId)).AsGuid().ForeignKey <Store>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(MeasureDimension.Name)).AsString(100).NotNullable() .WithColumn(nameof(MeasureDimension.SystemKeyword)).AsString(100).NotNullable() .WithColumn(nameof(MeasureDimension.Ratio)).AsDecimal(18, 8); }
private static ISupportAdditionalFeatures GetColumn <TNext, TNextFk>(IColumnOptionSyntax <TNext, TNextFk> expression) where TNext : IFluentSyntax where TNextFk : IFluentSyntax { CreateTableExpressionBuilder cast1 = expression as CreateTableExpressionBuilder; if (cast1 != null) { return(cast1.CurrentColumn); } AlterTableExpressionBuilder cast2 = expression as AlterTableExpressionBuilder; if (cast2 != null) { return(cast2.CurrentColumn); } AlterColumnExpressionBuilder cast3 = expression as AlterColumnExpressionBuilder; if (cast3 != null) { return(cast3.GetColumnForType()); } CreateColumnExpressionBuilder cast4 = expression as CreateColumnExpressionBuilder; if (cast4 != null) { return(cast4.GetColumnForType()); } throw new InvalidOperationException("The seeded identity method can only be called on a valid object."); }
/// <summary> /// Returns mapped entity descriptor /// </summary> /// <param name="entityType">Type of entity</param> /// <returns>Mapped entity descriptor</returns> public virtual NopEntityDescriptor GetEntityDescriptor(Type entityType) { return(EntityDescriptors.GetOrAdd(entityType, t => { var tableName = NameCompatibilityManager.GetTableName(t); var expression = new CreateTableExpression { TableName = tableName }; var builder = new CreateTableExpressionBuilder(expression, new NullMigrationContext()); builder.RetrieveTableExpressions(t); return new NopEntityDescriptor { EntityName = tableName, Fields = builder.Expression.Columns.Select(column => new NopEntityFieldDescriptor { Name = column.Name, IsPrimaryKey = column.IsPrimaryKey, IsNullable = column.IsNullable, Size = column.Size, Precision = column.Precision, IsIdentity = column.IsIdentity, Type = getPropertyTypeByColumnName(t, column.Name) }).ToList() }; }));
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(ProductSpecificationAttribute.CustomValue)).AsString(4000).Nullable() .WithColumn(nameof(ProductSpecificationAttribute.ProductId)).AsGuid().ForeignKey <Product>() .WithColumn(nameof(ProductSpecificationAttribute.SpecificationAttributeOptionId)).AsGuid().ForeignKey <SpecificationAttributeOption>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(ProductAttributeValue.Name)).AsString(400).NotNullable() .WithColumn(nameof(ProductAttributeValue.ColorSquaresRgb)).AsString(100).Nullable() .WithColumn(nameof(ProductAttributeValue.ProductAttributeMappingId)).AsInt32().ForeignKey<ProductAttributeMapping>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(SpecificationAttributeOption.Name)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(SpecificationAttributeOption.ColorSquaresRgb)).AsString(100).Nullable() .WithColumn(nameof(SpecificationAttributeOption.SpecificationAttributeId)).AsInt32().ForeignKey <SpecificationAttribute>(); }
public void CallingForeignKeyAddsNewForeignKeyExpressionToContext() { var collectionMock = new Mock <ICollection <IMigrationExpression> >(); var contextMock = new Mock <IMigrationContext>(); contextMock.Setup(x => x.Expressions).Returns(collectionMock.Object); var columnMock = new Mock <ColumnDefinition>(); columnMock.SetupGet(x => x.Name).Returns("BaconId"); var expressionMock = new Mock <CreateTableExpression>(); expressionMock.SetupGet(x => x.TableName).Returns("Bacon"); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object) { CurrentColumn = columnMock.Object }; builder.ForeignKey("fk_foo", "FooTable", "BarColumn"); collectionMock.Verify(x => x.Add(It.Is <CreateForeignKeyExpression>( fk => fk.ForeignKey.Name == "fk_foo" && fk.ForeignKey.PrimaryTable == "FooTable" && fk.ForeignKey.PrimaryColumns.Contains("BarColumn") && fk.ForeignKey.PrimaryColumns.Count == 1 && fk.ForeignKey.ForeignTable == "Bacon" && fk.ForeignKey.ForeignColumns.Contains("BaconId") && fk.ForeignKey.ForeignColumns.Count == 1 ))); contextMock.VerifyGet(x => x.Expressions); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(NewsComment.CustomerId)).AsGuid().ForeignKey <Customer>() .WithColumn(nameof(NewsComment.NewsItemId)).AsGuid().ForeignKey <NewsItem>() .WithColumn(nameof(NewsComment.StoreId)).AsGuid().ForeignKey <Store>(); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(nameof(PrivateMessage.Subject)).AsString(450).NotNullable() .WithColumn(nameof(PrivateMessage.Text)).AsString(int.MaxValue).NotNullable() .WithColumn(nameof(PrivateMessage.FromCustomerId)).AsInt32().ForeignKey <Customer>().OnDelete(Rule.None) .WithColumn(nameof(PrivateMessage.ToCustomerId)).AsInt32().ForeignKey <Customer>().OnDelete(Rule.None); }
/// <summary> /// Apply entity configuration /// </summary> /// <param name="table">Create table expression builder</param> public override void MapEntity(CreateTableExpressionBuilder table) { table .WithColumn(NameCompatibilityManager.GetColumnName(typeof(ProductProductTagMapping), nameof(ProductProductTagMapping.ProductId))) .AsInt32().PrimaryKey().ForeignKey <Product>() .WithColumn(NameCompatibilityManager.GetColumnName(typeof(ProductProductTagMapping), nameof(ProductProductTagMapping.ProductTagId))) .AsInt32().PrimaryKey().ForeignKey <ProductTag>(); }
public void IColumnExpressionBuilder_UsesExpressionSchemaAndTableName() { var expressionMock = new Mock<CreateTableExpression>(); var contextMock = new Mock<IMigrationContext>(); expressionMock.SetupGet(n => n.SchemaName).Returns("Fred"); expressionMock.SetupGet(n => n.TableName).Returns("Flinstone"); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); var builderAsInterface = (IColumnExpressionBuilder)builder; Assert.AreEqual("Fred", builderAsInterface.SchemaName); Assert.AreEqual("Flinstone", builderAsInterface.TableName); }
private void VerifyColumnHelperCall(Action<CreateTableExpressionBuilder> callToTest, System.Linq.Expressions.Expression<Action<ColumnExpressionBuilderHelper>> expectedHelperAction) { var expressionMock = new Mock<CreateTableExpression>(); var contextMock = new Mock<IMigrationContext>(); var helperMock = new Mock<ColumnExpressionBuilderHelper>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.ColumnHelper = helperMock.Object; callToTest(builder); helperMock.Verify(expectedHelperAction); }
public void IColumnExpressionBuilder_UsesCurrentColumn() { var expressionMock = new Mock<CreateTableExpression>(); var contextMock = new Mock<IMigrationContext>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); var curColumn = new Mock<ColumnDefinition>().Object; builder.CurrentColumn = curColumn; var builderAsInterface = (IColumnExpressionBuilder)builder; Assert.AreSame(curColumn, builderAsInterface.Column); }
private void VerifyColumnSize(int expected, Action<CreateTableExpressionBuilder> callToTest) { var columnMock = new Mock<ColumnDefinition>(); var expressionMock = new Mock<CreateTableExpression>(); var contextMock = new Mock<IMigrationContext>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.CurrentColumn = columnMock.Object; callToTest(builder); columnMock.VerifySet(c => c.Size = expected); }
public void ColumnHelperSetOnCreation() { var expressionMock = new Mock<CreateTableExpression>(); var contextMock = new Mock<IMigrationContext>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); Assert.IsNotNull(builder.ColumnHelper); }
private void VerifyColumnProperty(Action<ColumnDefinition> columnExpression, Action<CreateTableExpressionBuilder> callToTest) { var columnMock = new Mock<ColumnDefinition>(); var expressionMock = new Mock<CreateTableExpression>(); var contextMock = new Mock<IMigrationContext>(); contextMock.SetupGet(mc => mc.Expressions).Returns(new Collection<IMigrationExpression>()); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.CurrentColumn = columnMock.Object; callToTest(builder); columnMock.VerifySet(columnExpression); }
public void CallingWithDefaultValueSetsDefaultValue() { const int value = 42; var contextMock = new Mock<IMigrationContext>(); var columnMock = new Mock<ColumnDefinition>(); var expressionMock = new Mock<CreateTableExpression>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.CurrentColumn = columnMock.Object; builder.WithDefaultValue(42); columnMock.VerifySet(c => c.DefaultValue = value); }
public void CallingWithColumnAddsNewColumnToExpression() { const string name = "BaconId"; var collectionMock = new Mock<IList<ColumnDefinition>>(); var expressionMock = new Mock<CreateTableExpression>(); expressionMock.SetupGet(e => e.Columns).Returns(collectionMock.Object); var contextMock = new Mock<IMigrationContext>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.WithColumn(name); collectionMock.Verify(x => x.Add(It.Is<ColumnDefinition>(c => c.Name.Equals(name)))); expressionMock.VerifyGet(e => e.Columns); }
public void CallingUniqueNamedAddsIndexExpressionToContext() { var collectionMock = new Mock<ICollection<IMigrationExpression>>(); var contextMock = new Mock<IMigrationContext>(); contextMock.Setup(x => x.Expressions).Returns(collectionMock.Object); var columnMock = new Mock<ColumnDefinition>(); columnMock.SetupGet(x => x.Name).Returns("BaconId"); var expressionMock = new Mock<CreateTableExpression>(); expressionMock.SetupGet(x => x.SchemaName).Returns("Eggs"); expressionMock.SetupGet(x => x.TableName).Returns("Bacon"); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object) { CurrentColumn = columnMock.Object }; builder.Unique("IX_Bacon_BaconId"); collectionMock.Verify(x => x.Add(It.Is<CreateIndexExpression>( ix => ix.Index.Name == "IX_Bacon_BaconId" && ix.Index.TableName == "Bacon" && ix.Index.SchemaName == "Eggs" && ix.Index.IsUnique && !ix.Index.IsClustered && ix.Index.Columns.All(c => c.Name == "BaconId") ))); contextMock.VerifyGet(x => x.Expressions); }
public void CallingReferencesAddsNewForeignKeyExpressionToContext() { var collectionMock = new Mock<ICollection<IMigrationExpression>>(); var contextMock = new Mock<IMigrationContext>(); contextMock.Setup(x => x.Expressions).Returns(collectionMock.Object); var columnMock = new Mock<ColumnDefinition>(); columnMock.SetupGet(x => x.Name).Returns("BaconId"); var expressionMock = new Mock<CreateTableExpression>(); expressionMock.SetupGet(x => x.TableName).Returns("Bacon"); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object) { CurrentColumn = columnMock.Object }; builder.References("fk_foo", "FooTable", new[] { "BarColumn" }); collectionMock.Verify(x => x.Add(It.Is<CreateForeignKeyExpression>( fk => fk.ForeignKey.Name == "fk_foo" && fk.ForeignKey.ForeignTable == "FooTable" && fk.ForeignKey.ForeignColumns.Contains("BarColumn") && fk.ForeignKey.ForeignColumns.Count == 1 && fk.ForeignKey.PrimaryTable == "Bacon" && fk.ForeignKey.PrimaryColumns.Contains("BaconId") && fk.ForeignKey.PrimaryColumns.Count == 1 ))); contextMock.VerifyGet(x => x.Expressions); }
public void CallingIdentityWithSeededIdentitySetsAdditionalProperties() { var contextMock = new Mock<IMigrationContext>(); var columnMock = new Mock<ColumnDefinition>(); var expressionMock = new Mock<CreateTableExpression>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.CurrentColumn = columnMock.Object; builder.Identity(12, 44); columnMock.Object.AdditionalFeatures.ShouldContain( new KeyValuePair<string, object>(SqlServerExtensions.IdentitySeed, 12)); columnMock.Object.AdditionalFeatures.ShouldContain( new KeyValuePair<string, object>(SqlServerExtensions.IdentityIncrement, 44)); }
public void CallingOnDeleteOrUpdateSetsOnUpdateAndOnDeleteOnForeignKeyExpression(Rule rule) { var builder = new CreateTableExpressionBuilder(null, null) { CurrentForeignKey = new ForeignKeyDefinition() }; builder.OnDeleteOrUpdate(rule); Assert.That(builder.CurrentForeignKey.OnUpdate, Is.EqualTo(rule)); Assert.That(builder.CurrentForeignKey.OnDelete, Is.EqualTo(rule)); }
public void CallingForeignKeySetForeignKey() { var expressionMock = new Mock<CreateTableExpression>(); var contextMock = new Mock<IMigrationContext>(); contextMock.SetupGet(x => x.Expressions).Returns(new List<IMigrationExpression>()); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.CurrentColumn = new ColumnDefinition(); var fk = new ForeignKeyDefinition { Name = "foreignKeyName", PrimaryTable = "primaryTableName", PrimaryTableSchema = "primaryTableSchema", ForeignTable = builder.Expression.TableName, ForeignTableSchema = builder.Expression.SchemaName }; builder.ForeignKey(fk.Name, fk.PrimaryTableSchema, fk.PrimaryTable, "primaryColumnName"); Assert.IsTrue(builder.CurrentColumn.IsForeignKey); Assert.AreEqual(builder.CurrentColumn.ForeignKey.Name, fk.Name); Assert.AreEqual(builder.CurrentColumn.ForeignKey.PrimaryTable, fk.PrimaryTable); Assert.AreEqual(builder.CurrentColumn.ForeignKey.PrimaryTableSchema, fk.PrimaryTableSchema); Assert.AreEqual(builder.CurrentColumn.ForeignKey.ForeignTable, fk.ForeignTable); Assert.AreEqual(builder.CurrentColumn.ForeignKey.ForeignTableSchema, fk.ForeignTableSchema); }
public void CallingWithDefaultSetsDefaultValue() { var contextMock = new Mock<IMigrationContext>(); var columnMock = new Mock<ColumnDefinition>(); var expressionMock = new Mock<CreateTableExpression>(); var builder = new CreateTableExpressionBuilder(expressionMock.Object, contextMock.Object); builder.CurrentColumn = columnMock.Object; builder.WithDefault(SystemMethods.CurrentDateTime); columnMock.VerifySet(c => c.DefaultValue = SystemMethods.CurrentDateTime); }