예제 #1
0
        public void AddManyTreeAndGetAllWithStringInclude()
        {
            #region Arrange

            var repository = Context.MyDisconnectedEntities;

            var nestedEntities = new List <MyNestedEntity>
            {
                new MyNestedEntity()
                {
                    Id   = 1,
                    Name = Guid.NewGuid().ToString()
                }
                , new MyNestedEntity()
                {
                    Id   = 2,
                    Name = Guid.NewGuid().ToString()
                }
            };

            var entities = new List <MyEntity>
            {
                new MyEntity()
                {
                    Id             = 1,
                    Name           = Guid.NewGuid().ToString(),
                    MyNestedEntity = nestedEntities[0]
                }
                , new MyEntity()
                {
                    Id             = 2,
                    Name           = Guid.NewGuid().ToString(),
                    MyNestedEntity = nestedEntities[1]
                }
            };

            //-- Add and Get many
            repository.Add(entities);
            Context.Save();

            #endregion

            #region Act

            var aggregatSpecification = new AggregatSpecification <MyEntity>(includeTrees: new[] { "MyNestedEntity" });
            var entitiesAdded         = repository.AllAsync(aggregatSpecification).Result.OrderBy(o => o.Id);
            var nbEntities            = entitiesAdded.Count();

            #endregion

            #region Assert

            Assert.Equal(2, nbEntities);
            Assert.NotNull(entitiesAdded.First().MyNestedEntity);
            Assert.NotNull(entitiesAdded.ElementAt(1).MyNestedEntity);
            Assert.Equal(1, entitiesAdded.First().MyNestedEntity.Id);
            Assert.Equal(2, entitiesAdded.ElementAt(1).MyNestedEntity.Id);

            #endregion
        }
예제 #2
0
        public async Task FindSingleAsyncShouldReturnTree()
        {
            #region Arrange

            var repositoryConnected = Context.MyConnectedEntities;
            var repositoryBase      = Context.BaseEntities;

            var nestedEntities = new List <MyNestedEntity>
            {
                new MyNestedEntity()
                {
                    Id   = 1,
                    Name = Guid.NewGuid().ToString()
                }
                , new MyNestedEntity()
                {
                    Id   = 2,
                    Name = Guid.NewGuid().ToString()
                }
            };

            var entities = new List <MyEntity>
            {
                new MyEntity()
                {
                    Id             = 1,
                    Name           = Guid.NewGuid().ToString(),
                    MyNestedEntity = nestedEntities[0]
                }
                , new MyEntity()
                {
                    Id             = 2,
                    Name           = Guid.NewGuid().ToString(),
                    MyNestedEntity = nestedEntities[1]
                }
            };

            //-- Add and Get many
            await repositoryConnected.AddAsync(entities);

            await Context.SaveAsync();

            #endregion

            #region Act

            var aggregatSpecification = new AggregatSpecification <MyEntity>(includeLeafs: i => i.MyNestedEntity);
            var entitiesAdded         = await repositoryBase.FindSingleAsync(x => x.Id == 1, aggregatSpecification);

            #endregion

            #region Assert

            Assert.NotNull(entitiesAdded);
            Assert.NotNull(entitiesAdded.MyNestedEntity);

            #endregion
        }