public void WhenApplierIsNotSupportedThenThrows()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();
            var applier = new Mock <IPatternApplier <int, string> >();

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => source.Merge(applier.Object));
        }
Beispiel #2
0
        public void WhenApplierIsNotSupportedThenThrows()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();
            var applier = new Mock <IPatternApplier <int, string> >();

            Executing.This(() => source.Merge(applier.Object)).Should().Throw <ArgumentOutOfRangeException>();
        }
        private IPatternsAppliersHolder GetPatternsAppliersHolderWithApplierAdded <TSubject, TApplyTo>()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();
            var applier = new Mock <IPatternApplier <TSubject, TApplyTo> >();

            source.Merge(applier.Object);
            return(source);
        }
        public void WhenAddDelegatedAdvancedApplierThenAlwaysAdd()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();

            source.Collection.Add(new DelegatedAdvancedApplier <MemberInfo, ICollectionPropertiesMapper>(x => true, (x, y) => { }));
            source.UnionWith(new DelegatedAdvancedApplier <MemberInfo, ICollectionPropertiesMapper>(x => true, (x, y) => { }));

            source.Collection.Count.Should().Be(2);
        }
        public void WhenDoesNotExistWithSameNameThenAdd()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();

            var domainInspector = new Mock <IDomainInspector>();
            var toAdd           = new ConfOrm.Patterns.BidirectionalManyToManyInverseApplier(domainInspector.Object);

            source.UnionWith(toAdd);
            source.Collection.Count.Should().Be(1);
        }
        public void WhenExistsApplierOfSameTypeThenDoesNotAdd()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();
            var toAdd = new BidirectionalManyToManyInverseApplier();

            source.Collection.Add(toAdd);
            source.Merge(new BidirectionalManyToManyInverseApplier());

            source.Collection.Count.Should().Be(1);
            source.Collection.Single().Should().Be.SameInstanceAs(toAdd);
        }
Beispiel #7
0
        public void WhenSecondIsNullThenReturnFirstCleanedOfDuplications()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();

            source.Collection.Add(new ACollectionApplier());
            source.Collection.Add(new ACollectionApplier());

            var mergeResult = source.Merge(null);

            mergeResult.Should().Not.Be.SameInstanceAs(source);
            mergeResult.Collection.Count.Should().Be(1);
        }
        public void WhenSecondIsNullThenReturnFirstCleanedOfDuplications()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();

            var domainInspector = new Mock <IDomainInspector>();

            source.Collection.Add(new ConfOrm.Patterns.BidirectionalManyToManyInverseApplier(domainInspector.Object));
            source.Collection.Add(new BidirectionalManyToManyInverseApplier());

            var unionResult = source.UnionWith(null);

            unionResult.Should().Not.Be.SameInstanceAs(source);
            unionResult.Collection.Count.Should().Be(1);
        }
        public void WhenExistWithSameNameThenRemoveAndAdd()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();

            var domainInspector = new Mock <IDomainInspector>();
            var toRemove        = new ConfOrm.Patterns.BidirectionalManyToManyInverseApplier(domainInspector.Object);

            source.Collection.Add(toRemove);

            var toAdd = new BidirectionalManyToManyInverseApplier();

            source.UnionWith(toAdd);
            source.Collection.Count.Should().Be(1);
            source.Collection.Single().Should().Be.SameInstanceAs(toAdd);
        }
        public void CallAppliersOnSimpleProperty()
        {
            var patternAppliers = new EmptyPatternsAppliersHolder();

            var applier = new Mock <IPatternApplier <PropertyPath, IPropertyMapper> >();

            applier.Setup(x => x.Match(It.IsAny <PropertyPath>())).Returns(true);
            patternAppliers.PropertyPath.Add(applier.Object);

            var mapper = new Mapper(domainInspectorMock.Object, patternAppliers);

            mapper.CompileMappingFor(new[] { typeof(MyClass) });

            applier.Verify(x => x.Apply(It.IsAny <PropertyPath>(), It.IsAny <IPropertyMapper>()));
        }
        public void CallSpecificAppliersOnMap()
        {
            var patternAppliers = new EmptyPatternsAppliersHolder();

            var applier = new Mock <IPatternApplier <MemberInfo, IMapPropertiesMapper> >();

            applier.Setup(x => x.Match(It.IsAny <MemberInfo>())).Returns(true);
            patternAppliers.Map.Add(applier.Object);

            var mapper = new Mapper(domainInspectorMock.Object, patternAppliers);

            mapper.CompileMappingFor(new[] { typeof(MyClass) });

            applier.Verify(x => x.Apply(It.Is <MemberInfo>(pp => pp.Name == "Map"), It.IsAny <IMapPropertiesMapper>()));
        }
        public void CallAppliersOnMap()
        {
            var patternAppliers = new EmptyPatternsAppliersHolder();

            var applier = new Mock <IPatternApplier <PropertyPath, ICollectionPropertiesMapper> >();

            applier.Setup(x => x.Match(It.IsAny <PropertyPath>())).Returns(true);
            patternAppliers.CollectionPath.Add(applier.Object);

            var mapper = new Mapper(domainInspectorMock.Object, patternAppliers);

            mapper.CompileMappingFor(new[] { typeof(MyClass) });

            applier.Verify(x => x.Apply(It.Is <PropertyPath>(pp => pp.LocalMember.Name == "Map"), It.IsAny <ICollectionPropertiesMapper>()));
        }
Beispiel #13
0
        public void WhenSecondIsNotNullThenMerge()
        {
            IPatternsAppliersHolder first = new EmptyPatternsAppliersHolder();

            first.Collection.Add(new ACollectionApplier());
            first.RootClass.Add(new ARootClassApplier());

            IPatternsAppliersHolder second = new EmptyPatternsAppliersHolder();

            second.RootClass.Add(new ARootClassApplier());

            var mergeResult = first.Merge(second);

            mergeResult.Collection.Count.Should().Be(1);
            mergeResult.RootClass.Count.Should().Be(1);
        }
Beispiel #14
0
        public void CallAfterEventAfterLastCustomizer()
        {
            var callSequence = new List <string>();
            var orm          = new ObjectRelationalMapper();

            orm.TablePerClassHierarchy <MyClass>();

            var patternsAppliersHolder = new EmptyPatternsAppliersHolder();
            var mapper = new Mapper(orm, patternsAppliersHolder);

            mapper.AfterMapSubclass += (di, t, cam) => callSequence.Add("afterevent");

            mapper.Subclass <Inherited>(ca => callSequence.Add("c1"));
            mapper.Subclass <Inherited>(ca => callSequence.Add("c2"));
            mapper.CompileMappingFor(new[] { typeof(MyClass), typeof(Inherited) });

            callSequence.Should().Have.SameSequenceAs("c1", "c2", "afterevent");
        }
Beispiel #15
0
        public void CallBeforeEventBeforeFirstPatternApplier()
        {
            var callSequence = new List <string>();
            var orm          = new ObjectRelationalMapper();

            orm.TablePerClassHierarchy <MyClass>();

            var patternsAppliersHolder = new EmptyPatternsAppliersHolder();

            patternsAppliersHolder.Subclass.Add(t => true, (t, cam) => callSequence.Add("pa"));

            var mapper = new Mapper(orm, patternsAppliersHolder);

            mapper.BeforeMapSubclass += (di, t, cam) => callSequence.Add("beforeevent");
            mapper.CompileMappingFor(new[] { typeof(MyClass), typeof(Inherited) });

            callSequence.Should().Have.SameSequenceAs("beforeevent", "pa");
        }
        public void WhenSecondIsNotNullThenUnion()
        {
            IPatternsAppliersHolder first = new EmptyPatternsAppliersHolder();

            var domainInspector = new Mock <IDomainInspector>();

            first.Collection.Add(new ConfOrm.Patterns.BidirectionalManyToManyInverseApplier(domainInspector.Object));

            IPatternsAppliersHolder second            = new EmptyPatternsAppliersHolder();
            var bidirectionalManyToManyInverseApplier = new BidirectionalManyToManyInverseApplier();

            second.Collection.Add(bidirectionalManyToManyInverseApplier);
            second.RootClass.Add(new ARootClassApplier());

            var unionResult = first.UnionWith(second);

            unionResult.Collection.Count.Should().Be(1);
            unionResult.RootClass.Count.Should().Be(1);
            unionResult.Collection.Single().Should().Be.SameInstanceAs(bidirectionalManyToManyInverseApplier);
        }
        public void WhenApplierIsNullThenNotThrow()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();

            ActionAssert.NotThrow(() => source.UnionWith <PropertyPath, IPropertyMapper>(null));
        }
Beispiel #18
0
        public void WhenApplierIsNullThenNotThrow()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();

            Executing.This(() => source.Merge <PropertyPath, IPropertyMapper>(null)).Should().NotThrow();
        }