public void OnPrimaryKeySet_calls_apply_on_conventions_in_order(bool useBuilder) { var conventions = new ConventionSet(); InternalKeyBuilder internalKeyBuilder = null; var convention = new Mock <IPrimaryKeyConvention>(); convention.Setup(c => c.Apply(It.IsAny <InternalKeyBuilder>(), It.IsAny <Key>())) .Returns <InternalKeyBuilder, Key>((b, t) => { Assert.NotNull(b); Assert.Null(t); internalKeyBuilder = b; return(true); }); conventions.PrimaryKeySetConventions.Add(convention.Object); var nullConvention = new Mock <IPrimaryKeyConvention>(); nullConvention.Setup(c => c.Apply(It.IsAny <InternalKeyBuilder>(), It.IsAny <Key>())) .Returns <InternalKeyBuilder, Key>((b, t) => { Assert.Null(t); Assert.Same(internalKeyBuilder, b); return(false); }); conventions.PrimaryKeySetConventions.Add(nullConvention.Object); var extraConvention = new Mock <IPrimaryKeyConvention>(); extraConvention.Setup(c => c.Apply(It.IsAny <InternalKeyBuilder>(), It.IsAny <Key>())) .Returns <InternalKeyBuilder, Key>((b, t) => { Assert.False(true); return(false); }); conventions.PrimaryKeySetConventions.Add(extraConvention.Object); var entityBuilder = new InternalModelBuilder(new Model(conventions)) .Entity(typeof(Order), ConfigurationSource.Convention); entityBuilder.HasKey(new[] { "OrderId" }, ConfigurationSource.Convention); if (useBuilder) { Assert.NotNull(entityBuilder.PrimaryKey(new[] { "OrderId" }, ConfigurationSource.Convention)); } else { Assert.NotNull(entityBuilder.Metadata.SetPrimaryKey( entityBuilder.Property("OrderId", ConfigurationSource.Convention).Metadata)); } Assert.NotNull(internalKeyBuilder); }
public void OnPrimaryKeySet_calls_apply_on_conventions_in_order() { var conventions = new ConventionSet(); InternalKeyBuilder internalKeyBuilder = null; var convention = new Mock<IPrimaryKeyConvention>(); convention.Setup(c => c.Apply(It.IsAny<InternalKeyBuilder>(), It.IsAny<Key>())) .Returns<InternalKeyBuilder, Key>((b, t) => { Assert.NotNull(b); Assert.Null(t); internalKeyBuilder = b; return true; }); conventions.PrimaryKeySetConventions.Add(convention.Object); var nullConvention = new Mock<IPrimaryKeyConvention>(); nullConvention.Setup(c => c.Apply(It.IsAny<InternalKeyBuilder>(), It.IsAny<Key>())) .Returns<InternalKeyBuilder, Key>((b, t) => { Assert.Null(t); Assert.Same(internalKeyBuilder, b); return false; }); conventions.PrimaryKeySetConventions.Add(nullConvention.Object); var extraConvention = new Mock<IPrimaryKeyConvention>(); extraConvention.Setup(c => c.Apply(It.IsAny<InternalKeyBuilder>(), It.IsAny<Key>())) .Returns<InternalKeyBuilder, Key>((b, t) => { Assert.False(true); return false; }); conventions.PrimaryKeySetConventions.Add(extraConvention.Object); var entityBuilder = new InternalModelBuilder(new Model(), conventions) .Entity(typeof(Order), ConfigurationSource.Convention); entityBuilder.HasKey(new[] { "OrderId" }, ConfigurationSource.Convention); Assert.NotNull(entityBuilder.PrimaryKey(new[] { "OrderId" }, ConfigurationSource.Convention)); Assert.NotNull(internalKeyBuilder); }