Пример #1
0
        public void DbAggregator_AllNonNullPrimariesAreWritten()
        {
            var aggregates = new[]
            {
                new SinglePrimaryAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 1, Name = "one"
                    }
                },
                null,
                new SinglePrimaryAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 3, Name = "three"
                    }
                },
            };

            var accessor = new Mock <IDbAccessor>();
            var actual   = 0;

            accessor.Setup(a => a.WriteEntities(It.IsAny <IEnumerable <IDbEntity> >()))
            .Callback <IEnumerable <IDbEntity> >((e) => actual += e.Count());

            var sut = new DbAggregator();

            sut.WriteAggregates(accessor.Object, aggregates);

            Assert.Equal(2, actual);
        }
Пример #2
0
        public void DbAggregator_AllMixedForeignsAreSavedAfterUpdate()
        {
            var aggregates = new[]
            {
                new MixedForeignsAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 1, Name = "one"
                    },
                    Foreign  = new MyForeign1(),
                    Foreigns = new[]
                    {
                        new MyForeign2(), new MyForeign2(),
                    }
                },

                new MixedForeignsAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 2, Name = "two"
                    },
                    Foreign  = new MyForeign1(),
                    Foreigns = new[]
                    {
                        new MyForeign2(), new MyForeign2(),
                    }
                },
                new MixedForeignsAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 3, Name = "three"
                    },
                    Foreign  = new MyForeign1(),
                    Foreigns = new[]
                    {
                        new MyForeign2(), new MyForeign2(),
                    }
                },
            };

            var accessor = new Mock <IDbAccessor>();
            var actual   = 0;

            accessor.Setup(a => a.WriteEntities(It.IsAny <IEnumerable <IDbEntity> >()))
            .Callback <IEnumerable <IDbEntity> >((e) => actual += e.Count());

            var sut = new DbAggregator();

            sut.WriteAggregates(accessor.Object, aggregates);

            Assert.NotNull(aggregates.SingleOrDefault(a => a.Foreign.PrimaryId == 1 && a.Foreigns.All(f => f.MyPrimaryId == 1)));
            Assert.NotNull(aggregates.SingleOrDefault(a => a.Foreign.PrimaryId == 2 && a.Foreigns.All(f => f.MyPrimaryId == 2)));
            Assert.NotNull(aggregates.SingleOrDefault(a => a.Foreign.PrimaryId == 3 && a.Foreigns.All(f => f.MyPrimaryId == 3)));
            Assert.Equal(12, actual);
        }
Пример #3
0
        public void DbAggregator_AllMultiForeignsAreUpdateAfterPrimariesAreWritten()
        {
            var aggregates = new[]
            {
                new EnumerableForeignAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 1, Name = "one"
                    }, Foreigns = new[]
                    {
                        new MyForeign1(), new MyForeign1(),
                    }
                },
                new EnumerableForeignAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 2, Name = "two"
                    }, Foreigns = new[]
                    {
                        new MyForeign1(), new MyForeign1(),
                    }
                },
                new EnumerableForeignAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 3, Name = "three"
                    }, Foreigns = new[]
                    {
                        new MyForeign1(), new MyForeign1(),
                    }
                },
            };

            var accessor = new Mock <IDbAccessor>();
            var sut      = new DbAggregator();

            sut.WriteAggregates(accessor.Object, aggregates);

            Assert.NotNull(aggregates.SingleOrDefault(a => a.Foreigns.All(f => f.PrimaryId == 1)));
            Assert.NotNull(aggregates.SingleOrDefault(a => a.Foreigns.All(f => f.PrimaryId == 2)));
            Assert.NotNull(aggregates.SingleOrDefault(a => a.Foreigns.All(f => f.PrimaryId == 3)));
        }
Пример #4
0
        public void DbAggregator_AllSingleForeignsAreSavedAfterUpdate()
        {
            var aggregates = new[]
            {
                new SingleForeignAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 1, Name = "one"
                    }, Foreign1 = new MyForeign1()
                },
                new SingleForeignAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 2, Name = "two"
                    }, Foreign1 = new MyForeign1()
                },
                new SingleForeignAggregate()
                {
                    Primary = new MyPrimary()
                    {
                        Id = 3, Name = "three"
                    }, Foreign1 = new MyForeign1()
                },
            };

            var accessor = new Mock <IDbAccessor>();
            var actual   = 0;

            accessor.Setup(a => a.WriteEntities(It.IsAny <IEnumerable <IDbEntity> >()))
            .Callback <IEnumerable <IDbEntity> >((e) => actual += e.Count());

            var sut = new DbAggregator();

            sut.WriteAggregates(accessor.Object, aggregates);

            Assert.Equal(6, actual);
        }