Пример #1
0
        public void ForEachSubEntity_GoodValues_Succeeds()
        {
            //Arrange
            var mock = new Mock<RepositoryTester<Manager>>();
            mock.CallBase = true;

            //Should be 2 infos. Optimization should remove the first configuration.
            mock.Object.Entity().HasSubEntities(e => e.Things);
            mock.Object.Entity().HasSubEntities(e => e.Things).WithEntity(e => e.Admin, e => e.AdminId);

            var manager = new Manager()
            {
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Admin = new Admin()
                    },
                    new Thing()
                    {
                        Admin = new Admin()
                    },
                    new Thing()
                    {
                        Admin = new Admin()
                    }
                }
            };

            int thingsCount = 0;
            int adminsCount = 0;
            int managersCount = 0;

            Action<RelatedEntityActionContext<Manager>> action =
                delegate(RelatedEntityActionContext<Manager> context)
                {
                    if (context.RelatedEntity is Manager)
                    {
                        managersCount++;
                    }

                    if (context.RelatedEntity is Admin)
                    {
                        adminsCount++;
                    }

                    if (context.RelatedEntity is Thing || context.RelatedEntity is IEnumerable<Thing>)
                    {
                        thingsCount++;
                    }
                };

            //Act
            mock.Object.ForEachSubEntity(manager, RecursionDirection.Descending, action);

            //Assert
            Assert.AreEqual(1, managersCount);
            Assert.AreEqual(3, adminsCount);
            Assert.AreEqual(4, thingsCount);
        }
        public void Update_WithRequiredSubEntitiesAndRequiredUsedEntities_UpdateAllEntities_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var addingDate = DateTime.UtcNow;

            var manager = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Data = "data"
            };

            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = addingDate
            });

            //Act
            director.Data = "data100";
            office1.Data = "data100";
            office2.Data = "data100";
            admin.Data = "data100";

            var updatingDate = DateTime.UtcNow;

            manager.Data = "data1";
            manager.Computer.Data = "data1";
            manager.Office = office2;

            repository.Update(new UpdateOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = updatingDate
            });

            //Assert
            var context = new EFContext();

            var managers = context.Managers.ToArray();
            var computers = context.Computers.ToArray();

            AssertUsingEntities();
            AssertSecondLevelUsedEntities();

            //Sub entities
            AssertComputers(addingDate, updatingDate, "data1", false);

            //Main entity
            Assert.AreEqual(1, managers.Length);
            Assert.AreEqual("data1", managers[0].Data);
            Assert.AreEqual(addingDate, managers[0].CreatedOn);
            Assert.AreEqual(updatingDate, managers[0].LastUpdateOn);
            Assert.AreEqual(null, managers[0].CarId);
            Assert.AreEqual(computers[0].Id, managers[0].ComputerId);
            Assert.AreEqual(null, managers[0].DescriptionId);
            Assert.AreEqual(null, managers[0].DirectorId);
            Assert.AreEqual(false, managers[0].IsDeleted);
            Assert.AreEqual(office2.Id, managers[0].OfficeId);

            //First level used entities
            AssertOffices();
        }
        public void Update_WithAllSubEntitiesAndAllUsedEntities_UpdateAllEntities_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var addingDate = DateTime.UtcNow;

            var manager = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data",
                Car = car1,
                Projects = new List<Project>()
                {
                    project1
                }
            };

            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = addingDate
            });

            //Act
            director.Data = "data100";
            office1.Data = "data100";
            office2.Data = "data100";
            admin.Data = "data100";
            car1.Data = "data100";
            project1.Data = "data100";
            project2.Data = "data100";

            var updatingDate = DateTime.UtcNow;

            manager.Data = "data1";
            manager.Computer.Data = "data1";
            manager.Description.Data = "data1";
            manager.Office = office2;
            manager.Things.RemoveAt(1);
            manager.Things[0].Data = "data1";
            manager.Things.Add(new Thing() { Admin = admin, Data = "data" });
            manager.Car = car2;
            manager.Projects.Clear();
            manager.Projects.Add(project2);

            repository.Update(new UpdateOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = updatingDate
            });

            //Assert
            var context = new EFContext();

            var managers = context.Managers.ToArray();
            var computers = context.Computers.ToArray();
            var things = context.Things.ToArray();
            var descriptions = context.Descriptions.ToArray();

            AssertUsingEntities();
            AssertSecondLevelUsedEntities();

            //Sub entities
            AssertComputers(addingDate, updatingDate, "data1", false);

            AssertDescriptions(addingDate, updatingDate, "data1", false);

            Assert.AreEqual(3, things.Length);

            AssertThing(things[0], addingDate, updatingDate, "data1", managers[0].Id, false);

            AssertThing(things[1], addingDate, updatingDate, "data", managers[0].Id, true);

            AssertThing(things[2], updatingDate, updatingDate, "data", managers[0].Id, false);

            //Main entity
            Assert.AreEqual(1, managers.Length);
            Assert.AreEqual("data1", managers[0].Data);
            Assert.AreEqual(addingDate, managers[0].CreatedOn);
            Assert.AreEqual(updatingDate, managers[0].LastUpdateOn);
            Assert.AreEqual(car2.Id, managers[0].CarId);
            Assert.AreEqual(computers[0].Id, managers[0].ComputerId);
            Assert.AreEqual(descriptions[0].Id, managers[0].DescriptionId);
            Assert.AreEqual(null, managers[0].DirectorId);
            Assert.AreEqual(false, managers[0].IsDeleted);
            Assert.AreEqual(office2.Id, managers[0].OfficeId);

            //First level used entities
            AssertOffices();

            AssertCars();

            AssertProjects(null, manager.Id);
        }
Пример #4
0
        private void Add10Managers()
        {
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var addingDate = DateTime.UtcNow;

            var manager = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data",
                Car = car1,
                Projects = new List<Project>()
                {
                    project1,
                    project2
                }
            };

            for (int i = 0; i < 10; i++)
            {
                manager.Data = "data" + i;

                repository.Add(new AddOperationParameters<Manager>()
                {
                    Entity = manager,
                    OwnerId = i / 3L,
                    OperationDateTime = addingDate
                });
            }
        }
Пример #5
0
        public void Get_WithUsingEntities_IsUsedIsTrue()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var manager = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data",
                Car = car1,
                Projects = new List<Project>()
                {
                    project1,
                    //project2
                }
            };

            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = initializingDate
            });

            //Attach using entities
            var context = new EFContext();

            context.Directors.Attach(director);
            context.Managers.Attach(manager);
            director.Managers = new List<Manager>();
            director.Managers.Add(manager);

            context.ManagerTrackers.Add(new ManagerTracker()
            {
                ManagerId = manager.Id,
                Data = "data",
                CreatedOn = initializingDate,
                LastUpdateOn = initializingDate
            });

            context.SaveChanges();

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                LoadSubEntities = true,
                LoadUsedEntities = true,
                LoadUsingEntities = true,
            });

            //Assert
            Assert.AreEqual(true, entities[0].IsUsed);
        }
Пример #6
0
        public void Get_WithAllRelatedEntities_ReturnsEntities()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var manager = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data",
                Car = car1,
                Projects = new List<Project>()
                {
                    project1,
                    //project2
                }
            };

            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = initializingDate
            });

            //Attach using entities
            var context = new EFContext();

            context.Directors.Attach(director);
            context.Managers.Attach(manager);
            director.Managers = new List<Manager>();
            director.Managers.Add(manager);

            context.ManagerTrackers.Add(new ManagerTracker()
            {
                ManagerId = manager.Id,
                Data = "data",
                CreatedOn = initializingDate,
                LastUpdateOn = initializingDate
            });

            context.SaveChanges();

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                LoadSubEntities = true,
                LoadUsedEntities = true,
                LoadUsingEntities = true,
            });

            //Assert
            Assert.AreEqual(true, entities[0].IsUsed);

            AssertUsingEntities();

            AssertSecondLevelUsedEntities();

            //Sub entities
            Assert.AreEqual(1, entities.Length);
            Assert.AreEqual(initializingDate, entities[0].Computer.CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].Computer.LastUpdateOn);
            Assert.AreEqual("data", entities[0].Computer.Data);
            Assert.AreEqual(false, entities[0].Computer.IsDeleted);
            Assert.AreEqual(admin.Id, entities[0].Computer.AdminId);

            Assert.AreEqual(initializingDate, entities[0].Description.CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].Description.LastUpdateOn);
            Assert.AreEqual("data", entities[0].Description.Data);
            Assert.AreEqual(false, entities[0].Description.IsDeleted);

            Assert.AreEqual(initializingDate, entities[0].Things[0].CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].Things[0].LastUpdateOn);
            Assert.AreEqual("data", entities[0].Things[0].Data);
            Assert.AreEqual(false, entities[0].Things[0].IsDeleted);
            Assert.AreEqual(admin.Id, entities[0].Things[0].AdminId);
            Assert.AreEqual(entities[0].Id, entities[0].Things[0].ManagerId);

            Assert.AreEqual(initializingDate, entities[0].Things[1].CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].Things[1].LastUpdateOn);
            Assert.AreEqual("data", entities[0].Things[1].Data);
            Assert.AreEqual(false, entities[0].Things[1].IsDeleted);
            Assert.AreEqual(admin.Id, entities[0].Things[1].AdminId);
            Assert.AreEqual(entities[0].Id, entities[0].Things[1].ManagerId);

            //Main entity
            Assert.AreEqual("data", entities[0].Data);
            Assert.AreEqual(initializingDate, entities[0].CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].LastUpdateOn);
            Assert.AreEqual(car1.Id, entities[0].CarId);
            Assert.AreEqual(director.Id, entities[0].DirectorId);
            Assert.AreEqual(false, entities[0].IsDeleted);
            Assert.AreEqual(office1.Id, entities[0].OfficeId);

            //First level used entities
            Assert.AreEqual(office1.Id, entities[0].Office.Id);
            Assert.AreEqual(initializingDate, entities[0].Office.CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].Office.LastUpdateOn);
            Assert.AreEqual("data", entities[0].Office.Data);
            Assert.AreEqual(false, entities[0].Office.IsDeleted);

            Assert.AreEqual(admin.Id, entities[0].Car.AdminId);
            Assert.AreEqual(car1.Id, entities[0].Car.Id);
            Assert.AreEqual(initializingDate, entities[0].Car.CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].Car.LastUpdateOn);
            Assert.AreEqual("data", entities[0].Car.Data);
            Assert.AreEqual(false, entities[0].Car.IsDeleted);

            Assert.AreEqual(admin.Id, entities[0].Projects[0].AdminId);
            Assert.AreEqual(project1.Id, entities[0].Projects[0].Id);
            Assert.AreEqual(initializingDate, entities[0].Projects[0].CreatedOn);
            Assert.AreEqual(initializingDate, entities[0].Projects[0].LastUpdateOn);
            Assert.AreEqual("data", entities[0].Projects[0].Data);
            Assert.AreEqual(false, entities[0].Projects[0].IsDeleted);
            Assert.AreEqual(manager.Id, entities[0].Projects[0].ManagerId);

            //Assert.AreEqual(admin.Id, entities[0].Projects[1].AdminId);
            //Assert.AreEqual(project2.Id, entities[0].Projects[1].Id);
            //Assert.AreEqual(initializingDate, entities[0].Projects[1].CreatedOn);
            //Assert.AreEqual(initializingDate, entities[0].Projects[1].LastUpdateOn);
            //Assert.AreEqual("data", entities[0].Projects[1].Data);
            //Assert.AreEqual(false, entities[0].Projects[1].IsDeleted);
            //Assert.AreEqual(manager.Id, entities[0].Projects[1].ManagerId);

            //Using entities
            Assert.AreEqual(initializingDate, entities[0].ManagerTrackers[0].CreatedOn);
            Assert.AreEqual("data", entities[0].ManagerTrackers[0].Data);
            Assert.AreEqual(false, entities[0].ManagerTrackers[0].IsDeleted);
            Assert.AreEqual(initializingDate, entities[0].ManagerTrackers[0].LastUpdateOn);
            Assert.AreEqual(manager.Id, entities[0].ManagerTrackers[0].ManagerId);

            //Get result
        }
Пример #7
0
        public void Get_WhenNoUsingEntities_IsUsedIsFalse()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var manager = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data",
                Car = car1,
                Projects = new List<Project>()
                {
                    project1,
                    //project2
                }
            };

            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = initializingDate
            });

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                LoadSubEntities = true,
                LoadUsedEntities = true,
                LoadUsingEntities = true,
            });

            //Assert
            Assert.AreEqual(false, entities[0].IsUsed);
        }
Пример #8
0
        public void GetTotalCount_EntitiesExist_ReturnsEntitiesCount()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var addingDate = DateTime.UtcNow;

            var manager1 = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data",
                Car = car1,
                Projects = new List<Project>()
                {
                    project1
                }
            };

            var manager2 = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office2,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data",
                Car = car2,
                Projects = new List<Project>()
                {
                    project2
                }
            };

            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager1,
                OperationDateTime = addingDate
            });

            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager2,
                OperationDateTime = addingDate
            });

            repository.Delete(new DeleteOperationParameters()
            {
                OperationDateTime = DateTime.UtcNow,
                PrimaryKeys = new object[] { manager2.Id }
            });

            //Act
            var result = repository.GetTotalCount(new OperationParameters());

            //Assert
            Assert.AreEqual(1, result);
        }
Пример #9
0
        public void Add_WithAllSubEntitiesAndRequiredUsedEntities_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var addingDate = DateTime.UtcNow;

            var manager = new Manager()
            {
                Director = director,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = office1,
                Computer = new Computer() { Data = "data", Admin = admin },
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Id = 1,
                        Admin = admin,
                        Data = "data"
                    },
                    new Thing()
                    {
                        Id = 2,
                        Admin = admin,
                        Data = "data"
                    }
                },
                Description = new Description()
                {
                    Data = "data"
                },
                Data = "data"
            };

            //Act
            repository.Add(new AddOperationParameters<Manager>()
            {
                Entity = manager,
                OperationDateTime = addingDate
            });

            //Assert
            var context = new EFContext();

            var managers = context.Managers.ToArray();
            var computers = context.Computers.ToArray();
            var things = context.Things.ToArray();
            var descriptions = context.Descriptions.ToArray();

            AssertUsingEntities();

            AssertSecondLevelUsedEntities();

            //Sub entities
            AssertComputers(addingDate, addingDate, "data", false);

            AssertDescriptions(addingDate, addingDate, "data", false);

            Assert.AreEqual(2, things.Length);

            AssertThing(things[0], addingDate, addingDate, "data", managers[0].Id, false);

            AssertThing(things[1], addingDate, addingDate, "data", managers[0].Id, false);

            //Main entity
            Assert.AreEqual(1, managers.Length);
            Assert.AreEqual("data", managers[0].Data);
            Assert.AreEqual(addingDate, managers[0].CreatedOn);
            Assert.AreEqual(addingDate, managers[0].LastUpdateOn);
            Assert.AreEqual(null, managers[0].CarId);
            Assert.AreEqual(computers[0].Id, managers[0].ComputerId);
            Assert.AreEqual(descriptions[0].Id, managers[0].DescriptionId);
            Assert.AreEqual(null, managers[0].DirectorId);
            Assert.AreEqual(false, managers[0].IsDeleted);
            Assert.AreEqual(office1.Id, managers[0].OfficeId);

            //First level used entities
            AssertOffices();
        }
Пример #10
0
        public void GetPropertyValue_PropertyEqualsNull_ReturnsNull()
        {
            //Arrange
            var manager = new Manager();

            //Act
            var value = ReflectionHelper.GetPropertyValue<object>(manager,
                ReflectionHelper.GetPropertyName<Manager, Description>(e => e.Description));

            //Assert
            Assert.IsNull(value);
        }
Пример #11
0
        public void SetPropertyValue_PropertyExists_Succeeds()
        {
            //Arrange
            var manager = new Manager()
            {
                Director = new Director()
                {
                    Managers = null
                }
            };

            //Act
            ReflectionHelper.SetPropertyValue(manager, ReflectionHelper
                .GetPropertyName<Manager, IList<Manager>>(e => e.Director.Managers),
                new List<Manager>() { new Manager() { Id = 123 } });

            //Assert
            Assert.AreEqual(123L, manager.Director.Managers[0].Id);
        }
Пример #12
0
        public void RemoveAllReferences_GoodValues_Succeeds()
        {
            //Arrange
            var date = DateTime.UtcNow;

            var obj = new Manager()
            {
                Car = new Car(),
                CarId = 1,
                Computer = new Computer(),
                ComputerId = 2,
                CreatedById = 3,
                CreatedOn = date,
                Data = "data",
                Description = new Description(),
                DescriptionId = 4,
                Director = new Director(),
                DirectorId = 5,
                Id = 6,
                IsDeleted = false,
                LastUpdatedById = 7,
                LastUpdateOn = date,
                ManagerTrackers = new List<ManagerTracker>()
                {
                    new ManagerTracker()
                },
                Office = new Office(),
                OfficeId = 8,
                Projects = new List<Project>()
                {
                    new Project()
                },
                Things = new List<Thing>()
                {
                    new Thing()
                }
            };

            //Act
            ReflectionHelper.RemoveAllReferences(obj);

            //Assert
            Assert.AreEqual(null, obj.Car);
            Assert.AreEqual(1, obj.CarId);
            Assert.AreEqual(null, obj.Computer);
            Assert.AreEqual(2, obj.ComputerId);
            Assert.AreEqual(3, obj.CreatedById);
            Assert.AreEqual(date, obj.CreatedOn);
            Assert.AreEqual("data", obj.Data);
            Assert.AreEqual(null, obj.Description);
            Assert.AreEqual(4, obj.DescriptionId);
            Assert.AreEqual(null, obj.Director);
            Assert.AreEqual(5, obj.DirectorId);
            Assert.AreEqual(6, obj.Id);
            Assert.AreEqual(false, obj.IsDeleted);
            Assert.AreEqual(7, obj.LastUpdatedById);
            Assert.AreEqual(date, obj.LastUpdateOn);
            Assert.AreEqual(null, obj.ManagerTrackers);
            Assert.AreEqual(null, obj.Office);
            Assert.AreEqual(8, obj.OfficeId);
            Assert.AreEqual(null, obj.Projects);
            Assert.AreEqual(null, obj.Things);
        }
Пример #13
0
        public void GetPropertyValue_PropertyIsNotNull_ReturnsValue()
        {
            //Arrange
            var manager = new Manager();
            var description = new Description();
            manager.Description = description;

            //Act
            var value = ReflectionHelper.GetPropertyValue<object>(manager,
                ReflectionHelper.GetPropertyName<Manager, Description>(e => e.Description));

            //Assert
            Assert.AreEqual(description, value);
        }
Пример #14
0
        public void ForEachUsingEntity_NullifiedUsingEntities_Succeeds()
        {
            //Arrange
            var mock = new Mock<RepositoryTester<Manager>>();
            mock.CallBase = true;

            //Should be 2 infos. Optimization should remove the first configuration.
            mock.Object.Entity().IsUsedByEntities(e => e.Things);
            mock.Object.Entity().IsUsedByEntities(e => e.Things).WithEntity(e => e.Admin, e => e.AdminId);

            var manager = new Manager()
            {
                Things = new List<Thing>()
                {
                    new Thing()
                    {
                        Admin = new Admin()
                    },
                    null,
                    new Thing()
                    {
                        Admin = new Admin()
                    }
                }
            };

            int thingsCount = 0;
            int adminsCount = 0;
            int managersCount = 0;

            Action<RelatedEntityActionContext<Manager>> action =
                delegate(RelatedEntityActionContext<Manager> context)
                {
                    if (context.RelatedEntity is Manager)
                    {
                        managersCount++;
                    }

                    if (context.RelatedEntity is Admin)
                    {
                        adminsCount++;
                    }

                    if (context.RelatedEntity is Thing || context.RelatedEntity is IEnumerable<Thing>
                        || (ReflectionHelper.IsInherited(typeof(IEnumerable<object>),
                        context.RelatedEntityPropertyInfo.PropertyType) && context.RelatedEntity == null))
                    {
                        thingsCount++;
                    }
                };

            //Act
            mock.Object.ForEachUsingEntity(manager, RecursionDirection.Descending, action);

            //Assert
            Assert.AreEqual(0, managersCount);
            Assert.AreEqual(2, adminsCount);
            Assert.AreEqual(4, thingsCount);
        }