Esempio n. 1
0
        public void Add_AddsAugmentToTypeConfiguration()
        {
            var tc = new TypeConfiguration <TestModel1>();

            tc.Add("Foo", (x, _) => $"({x.Id})");

            tc.Augments.First().Invoking(o =>
            {
                o.Name.Should().Be("Foo");
                o.Kind.Should().Be(AugmentKind.Add);
                o.ValueFunc.Should().NotBeNull();
            });
        }
        public void IgnoresStaticReferences()
        {
            var modelTypeConfiguration = new TypeConfiguration <TestModelWithStaticReference>();

            modelTypeConfiguration.Add("Some", (x, state) => "some");
            var list = new List <TypeConfiguration>
            {
                modelTypeConfiguration
            };
            var builder = new TypeConfigurationBuilder(list);
            var result  = builder.Build(modelTypeConfiguration, typeof(TestModelWithStaticReference));

            modelTypeConfiguration.Properties.Should().HaveCount(1);
        }
        public void DetectsSelfReferencing()
        {
            var modelTypeConfiguration = new TypeConfiguration <TestModelSelfReferencing>();

            modelTypeConfiguration.Add("Some", (x, state) => "some");
            var list = new List <TypeConfiguration>
            {
                modelTypeConfiguration
            };
            var builder = new TypeConfigurationBuilder(list);
            var result  = builder.Build(modelTypeConfiguration, typeof(TestModelSelfReferencing));

            modelTypeConfiguration.Properties.Should().HaveCount(2);
            modelTypeConfiguration.Properties[1].TypeConfiguration.Should().Be(modelTypeConfiguration);
        }
        public void EnsureConfigurationIsBuiltOnlyOnce()
        {
            var modelATypeConfiguration = new TypeConfiguration <TestModelA>();

            modelATypeConfiguration.Add("Some", (x, state) => "some");
            var modelBTypeConfiguration = new TypeConfiguration(typeof(TestModelB));
            var list = new List <TypeConfiguration>
            {
                modelATypeConfiguration,
                modelBTypeConfiguration
            };
            var builder = new TypeConfigurationBuilder(list);
            var result  = builder.Build(modelBTypeConfiguration, typeof(TestModelB));

            var anon = new { Model = new TestModelB() };

            result = builder.Build(null, anon.GetType());

            modelBTypeConfiguration.BaseTypeConfigurations.Should().HaveCount(1);
        }