private void SetDefaultDiscriminatorValues(IReadOnlyList<EntityType> entityTypes, DiscriminatorBuilder discriminator)
 {
     foreach (var entityType in entityTypes)
     {
         discriminator.HasValue(entityType.Name, entityType.DisplayName());
     }
 }
        public void It_Should_Serialise_To_This()
        {
            Table  table  = new Table("Table1");
            Column column = new Column("Column1");

            table.AddColumn(column);

            var dis = new DiscriminatorBuilder()
                      .SingleConditionDiscriminator(column, Operator.Equal, new ExpressionValueImpl("5"));

            string outputXML = new EntitySetSerialisationScheme().SerialiseDiscriminator(dis);

            outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML);
            Assert.That(outputXML, Is.EqualTo(FullDiscriminatorXml));
        }
        public void It_Is_Built_Correctly()
        {
            var             build  = new DiscriminatorBuilder();
            ExpressionValue val    = MockRepository.GenerateMock <ExpressionValue>();
            Operator        op     = Operator.Equal;
            IColumn         column = MockRepository.GenerateMock <IColumn>();;
            Discriminator   dis    = build.SingleConditionDiscriminator(column, op, val);

            Assert.That(dis.RootGrouping, Is.Not.Null);
            Assert.That(dis.RootGrouping.Groupings, Is.Empty);
            Assert.That(dis.RootGrouping.Conditions, Has.Count(1));

            Condition condition = dis.RootGrouping.Conditions[0];

            Assert.That(condition.Column, Is.SameAs(column));
            Assert.That(condition.Operator, Is.SameAs(op));
            Assert.That(condition.ExpressionValue, Is.SameAs(val));
        }
        public void Can_access_discriminator_value_generic()
        {
            var typeBuilder = CreateBuilder().Entity(typeof(Splot), ConfigurationSource.Convention);

            var discriminatorBuilder = new DiscriminatorBuilder <int?>(
                typeBuilder.Relational(ConfigurationSource.Convention).HasDiscriminator(Splot.SplowedProperty));

            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splot), 1));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splow), 2));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splod), 3));
            Assert.Equal(1, typeBuilder.Metadata.Relational().DiscriminatorValue);
            Assert.Equal(
                2, typeBuilder.ModelBuilder.Entity(typeof(Splow), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
            Assert.Equal(
                3, typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);

            discriminatorBuilder = new DiscriminatorBuilder <int?>(
                typeBuilder.Relational(ConfigurationSource.DataAnnotation).HasDiscriminator());
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splot), 4));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splow), 5));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splod), 6));
            Assert.Equal(4, typeBuilder.Metadata.Relational().DiscriminatorValue);
            Assert.Equal(
                5, typeBuilder.ModelBuilder.Entity(typeof(Splow), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
            Assert.Equal(
                6, typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);

            discriminatorBuilder = new DiscriminatorBuilder <int?>(
                typeBuilder.Relational(ConfigurationSource.Convention).HasDiscriminator());
            Assert.Null(discriminatorBuilder.HasValue(typeof(Splot), 1));
            Assert.Null(discriminatorBuilder.HasValue(typeof(Splow), 2));
            Assert.Null(discriminatorBuilder.HasValue(typeof(Splod), 3));
            Assert.Equal(4, typeBuilder.Metadata.Relational().DiscriminatorValue);
            Assert.Equal(
                5, typeBuilder.ModelBuilder.Entity(typeof(Splow), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
            Assert.Equal(
                6, typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
        }
Beispiel #5
0
        public void Can_access_discriminator_value_generic()
        {
            var typeBuilder = CreateBuilder().Entity(typeof(Splot), ConfigurationSource.Convention);

            var discriminatorBuilder = new DiscriminatorBuilder <int?>(
                (DiscriminatorBuilder)typeBuilder.HasDiscriminator(Splot.SplowedProperty));

            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splot), 1));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splow), 2));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splod), 3));

            var splow = typeBuilder.ModelBuilder.Entity(typeof(Splow), ConfigurationSource.Convention).Metadata;
            var splod = typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention).Metadata;

            Assert.Equal(1, typeBuilder.Metadata.GetDiscriminatorValue());
            Assert.Equal(2, splow.GetDiscriminatorValue());
            Assert.Equal(
                3, typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention)
                .Metadata.GetDiscriminatorValue());

            discriminatorBuilder = new DiscriminatorBuilder <int?>(
                (DiscriminatorBuilder)typeBuilder.HasDiscriminator(fromDataAnnotation: true));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splot), 4));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splow), 5));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splod), 6));
            Assert.Equal(4, typeBuilder.Metadata.GetDiscriminatorValue());
            Assert.Equal(5, splow.GetDiscriminatorValue());
            Assert.Equal(6, splod.GetDiscriminatorValue());

            var conventionDiscriminatorBuilder = typeBuilder.HasDiscriminator();

            Assert.Null(conventionDiscriminatorBuilder.HasValue(typeBuilder.Metadata, 1));
            Assert.Null(conventionDiscriminatorBuilder.HasValue(splow, 2));
            Assert.Null(conventionDiscriminatorBuilder.HasValue(splod, 3));
            Assert.Equal(4, typeBuilder.Metadata.GetDiscriminatorValue());
            Assert.Equal(5, splow.GetDiscriminatorValue());
            Assert.Equal(6, splod.GetDiscriminatorValue());
        }
Beispiel #6
0
 protected virtual TestDiscriminatorBuilder <TDiscriminator> Wrap(DiscriminatorBuilder discriminatorBuilder)
 => new NonGenericTestDiscriminatorBuilder <TDiscriminator>(discriminatorBuilder);
Beispiel #7
0
 public NonGenericTestDiscriminatorBuilder(DiscriminatorBuilder discriminatorBuilder)
 {
     DiscriminatorBuilder = discriminatorBuilder;
 }
Beispiel #8
0
 public GenericTestDiscriminatorBuilder(DiscriminatorBuilder <TDiscriminator> discriminatorBuilder)
 {
     DiscriminatorBuilder = discriminatorBuilder;
 }
Beispiel #9
0
 public DiscriminatorBuilder(DiscriminatorBuilder builder)
 {
     Builder = builder;
 }
 private static void SetDefaultDiscriminatorValues(IReadOnlyList <EntityType> entityTypes, DiscriminatorBuilder discriminator)
 {
     foreach (var entityType in entityTypes)
     {
         discriminator.HasValue(entityType.Name, entityType.ShortName());
     }
 }
        public void Can_access_discriminator_value_generic()
        {
            var typeBuilder = CreateBuilder().Entity(typeof(Splot), ConfigurationSource.Convention);

            var discriminatorBuilder = new DiscriminatorBuilder<int?>(
                typeBuilder.Relational(ConfigurationSource.Convention).Discriminator(Splot.SplowedProperty));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splot), 1));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splow), 2));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splod), 3));
            Assert.Equal(1, typeBuilder.Metadata.Relational().DiscriminatorValue);
            Assert.Equal(2, typeBuilder.ModelBuilder.Entity(typeof(Splow), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
            Assert.Equal(3, typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);

            discriminatorBuilder = new DiscriminatorBuilder<int?>(
                typeBuilder.Relational(ConfigurationSource.DataAnnotation).Discriminator());
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splot), 4));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splow), 5));
            Assert.NotNull(discriminatorBuilder.HasValue(typeof(Splod), 6));
            Assert.Equal(4, typeBuilder.Metadata.Relational().DiscriminatorValue);
            Assert.Equal(5, typeBuilder.ModelBuilder.Entity(typeof(Splow), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
            Assert.Equal(6, typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);

            discriminatorBuilder = new DiscriminatorBuilder<int?>(
                typeBuilder.Relational(ConfigurationSource.Convention).Discriminator());
            Assert.Null(discriminatorBuilder.HasValue(typeof(Splot), 1));
            Assert.Null(discriminatorBuilder.HasValue(typeof(Splow), 2));
            Assert.Null(discriminatorBuilder.HasValue(typeof(Splod), 3));
            Assert.Equal(4, typeBuilder.Metadata.Relational().DiscriminatorValue);
            Assert.Equal(5, typeBuilder.ModelBuilder.Entity(typeof(Splow), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
            Assert.Equal(6, typeBuilder.ModelBuilder.Entity(typeof(Splod), ConfigurationSource.Convention)
                .Metadata.Relational().DiscriminatorValue);
        }