Ejemplo n.º 1
0
        public void AreEntitiesEqual_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            //Act
            var result1 = repository.AreEntitiesEqual(new EFContext(), new EFEntity()
            {
                Id = 1
            }, new EFEntity()
            {
                Id = 1
            });
            var result2 = repository.AreEntitiesEqual(new EFContext(), new EFEntity()
            {
                Id = 2
            }, new EFEntity()
            {
                Id = 1
            });

            //Assert
            Assert.IsTrue(result1);
            Assert.IsFalse(result2);
        }
Ejemplo n.º 2
0
        public void CreateQueryFilterInterpreter_Always_RetursQueryFilterInterpreter()
        {
            //Arrange
            //Act
            var interpreter = new EFRepositoryTester().CreateQueryFilterInterpreter();

            //Assert
            Assert.AreEqual(typeof(QueryFilterInterpreter), interpreter.GetType());
        }
Ejemplo n.º 3
0
        public void CreateQueryFilterInterpreter_Always_RetursQueryFilterInterpreter()
        {
            //Arrange
            //Act
            var interpreter = new EFRepositoryTester().CreateQueryFilterInterpreter();

            //Assert
            Assert.AreEqual(typeof(QueryFilterInterpreter), interpreter.GetType());
        }
Ejemplo n.º 4
0
        public void GetPrimaryKeyNames_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            //Act
            var result = repository.GetPrimaryKeyNames(new EFContext(), typeof(EFEntity));

            //Assert
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual(ReflectionHelper.GetPropertyName <EFEntity, long>(e => e.Id), result[0]);
        }
Ejemplo n.º 5
0
        public void AreEntitiesEqual_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            //Act
            var result1 = repository.AreEntitiesEqual(new EFContext(), new EFEntity() { Id = 1 }, new EFEntity() { Id = 1 });
            var result2 = repository.AreEntitiesEqual(new EFContext(), new EFEntity() { Id = 2 }, new EFEntity() { Id = 1 });

            //Assert
            Assert.IsTrue(result1);
            Assert.IsFalse(result2);
        }
Ejemplo n.º 6
0
        public void GetFilterByPrimaryKeys_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            //Act
            var result = repository.GetFilterByPrimaryKeys(new EFContext(), typeof(EFEntity), new object[] { 123L });

            //Assert
            Assert.AreEqual(typeof(EqualsCondition), result.GetType());
            Assert.AreEqual(ReflectionHelper.GetPropertyName <EFEntity, long>(e => e.Id), ((EqualsCondition)result).Property);
            Assert.AreEqual(123L, ((EqualsCondition)result).Value);
        }
Ejemplo n.º 7
0
        public void Delete_EntityNotExists_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            //Act
            //Assert
            repository.Initialize();

            repository.Delete(new DeleteOperationParameters()
            {
                PrimaryKeys = new object[] { 10000L }
            });
        }
Ejemplo n.º 8
0
        public void SynchronizeForeignKeysWithEntities_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            var entity = new EFEntity()
            {
                Id = 1,
                EFEntityChildren = new List <EFEntityChild>()
                {
                    new EFEntityChild()
                    {
                        Id = 1,
                    },
                    new EFEntityChild()
                    {
                        Id = 2,
                    }
                }
            };

            //Act
            repository.SynchronizeForeignKeysWithEntities(entity);

            //Assert
            Assert.AreEqual(1, entity.Id);
            Assert.AreEqual(2, entity.EFEntityChildren.Count);

            Assert.AreEqual(1, entity.EFEntityChildren[0].Id);
            Assert.AreEqual(1, entity.EFEntityChildren[0].EFEntityId);
            Assert.AreEqual(entity, entity.EFEntityChildren[0].EFEntity);

            Assert.AreEqual(2, entity.EFEntityChildren[1].Id);
            Assert.AreEqual(1, entity.EFEntityChildren[1].EFEntityId);
            Assert.AreEqual(entity, entity.EFEntityChildren[1].EFEntity);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public void GetTotalCount_ParametersIsNull_ThrowsArgumentNullException()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            //Act
            //Assert
            repository.GetTotalCount(null);
        }
Ejemplo n.º 11
0
        public void GetTotalCount_NoEntities_ReturnsZero()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

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

            //Assert
            Assert.AreEqual(0, result);
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        public void Add_WithAllSubEntitiesAndAllUsedEntities_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,
                    project2
                }
            };

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

            //Assert
            var context = new EFContext();

            var managers = context.Managers
                .Include(ReflectionHelper.GetPropertyName<Manager, Car>(e => e.Car))
                .Include(ReflectionHelper.GetPropertyName<Manager, Computer>(e => e.Computer))
                .Include(ReflectionHelper.GetPropertyName<Manager, Description>(e => e.Description))
                .Include(ReflectionHelper.GetPropertyName<Manager, Director>(e => e.Director))
                .Include(ReflectionHelper.GetPropertyName<Manager, Office>(e => e.Office))
                .ToArray();
            var computers = context.Computers.ToArray();
            var things = context.Things
                .Include(ReflectionHelper.GetPropertyName<Thing, Admin>(e => e.Admin))
                .Include(ReflectionHelper.GetPropertyName<Thing, Manager>(e => e.Manager))
                .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);

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

            //Main entity
            Assert.AreEqual(1, managers.Length);
            Assert.AreEqual("data", managers[0].Data);
            Assert.AreEqual(car1.Id, managers[0].Car.Id);
            Assert.AreEqual(computers[0].Id, managers[0].Computer.Id);
            Assert.AreEqual(descriptions[0].Id, managers[0].Description.Id);
            Assert.AreEqual(null, managers[0].Director);
            Assert.AreEqual(office1.Id, managers[0].Office.Id);

            //First level used entities
            AssertOffices();

            AssertCars();

            AssertProjects(manager.Id, manager.Id);
        }
Ejemplo n.º 15
0
        public void Delete_WithRequiredSubEntitiesAndRequiredUsedEntities_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
            var deletingDate = DateTime.UtcNow;

            repository.Delete(new DeleteOperationParameters()
            {
                PrimaryKeys = new object[]
                {
                    manager.Id
                },
                OperationDateTime = deletingDate
            });

            //Assert
            var context = new EFContext();

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

            AssertUsingEntities();
            AssertSecondLevelUsedEntities();

            //Sub entities
            AssertComputers(addingDate, deletingDate, "data", true);

            //Main entity
            Assert.AreEqual(0, managers.Length);

            //First level used entities
            AssertOffices();
        }
Ejemplo n.º 16
0
        public void Get_WhenPageNumberIs0AndPageSizeIs3_ReturnsFirstThreeEntities()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            Add10Managers();

            //Act
            var getParameters = new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    PagingParameters = new QueryPagingParameters()
                    {
                        PageNumber = 0,
                        PageSize = 3,
                    }
                }
            };

            var entities = repository.Get(getParameters);

            //Assert
            Assert.AreEqual(3, entities.Length);
            Assert.AreEqual(10, getParameters.QueryParameters.PagingParameters.TotalCount);

            for (int i = 0; i < 3; i++)
            {
                Assert.IsTrue(entities[i].Data == "data0"
                    || entities[i].Data == "data1"
                    || entities[i].Data == "data2");
            }
        }
Ejemplo n.º 17
0
        public void Get_ByPrimaryKeysAndNoEntities_ReturnsEmptyArray()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    Filter = new EqualsCondition()
                    {
                        Property = ReflectionHelper.GetPropertyName<Manager, long>(e => e.Id),
                        Value = 123L
                    }
                }
            });

            //Assert
            Assert.IsNotNull(entities);
            Assert.AreEqual(0, entities.Length);
        }
Ejemplo n.º 18
0
        public void SynchronizeForeignKeysWithEntities_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            var entity = new EFEntity()
            {
                Id = 1,
                EFEntityChildren = new List<EFEntityChild>()
                {
                    new EFEntityChild()
                    {
                        Id = 1,
                    },
                    new EFEntityChild()
                    {
                        Id = 2,
                    }
                }
            };

            //Act
            repository.SynchronizeForeignKeysWithEntities(entity);

            //Assert
            Assert.AreEqual(1, entity.Id);
            Assert.AreEqual(2, entity.EFEntityChildren.Count);

            Assert.AreEqual(1, entity.EFEntityChildren[0].Id);
            Assert.AreEqual(1, entity.EFEntityChildren[0].EFEntityId);
            Assert.AreEqual(entity, entity.EFEntityChildren[0].EFEntity);

            Assert.AreEqual(2, entity.EFEntityChildren[1].Id);
            Assert.AreEqual(1, entity.EFEntityChildren[1].EFEntityId);
            Assert.AreEqual(entity, entity.EFEntityChildren[1].EFEntity);
        }
Ejemplo n.º 19
0
        public void GetPrimaryKeyNames_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            //Act
            var result = repository.GetPrimaryKeyNames(new EFContext(), typeof(EFEntity));

            //Assert
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual(ReflectionHelper.GetPropertyName<EFEntity, long>(e => e.Id), result[0]);
        }
Ejemplo n.º 20
0
        public void GetFilterByPrimaryKeys_GoodValues_Succeeds()
        {
            //Arrange
            var repository = new EFRepositoryTester();

            //Act
            var result = repository.GetFilterByPrimaryKeys(new EFContext(), typeof(EFEntity), new object[] { 123L });

            //Assert
            Assert.AreEqual(typeof(EqualsCondition), result.GetType());
            Assert.AreEqual(ReflectionHelper.GetPropertyName<EFEntity, long>(e => e.Id), ((EqualsCondition)result).Property);
            Assert.AreEqual(123L, ((EqualsCondition)result).Value);
        }
Ejemplo n.º 21
0
        public void Delete_WithAllSubEntitiesAndAllUsedEntities_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,
                    project2
                }
            };

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

            //Act
            var deletingDate = DateTime.UtcNow;

            repository.Delete(new DeleteOperationParameters()
            {
                PrimaryKeys = new object[]
                {
                    manager.Id
                },
                OperationDateTime = deletingDate
            });

            //Assert
            var context = new EFContext();

            var managers = context.Managers.ToArray();
            var things = context.Things.ToArray();

            AssertUsingEntities();
            AssertSecondLevelUsedEntities();

            //Sub entities
            AssertComputers(addingDate, deletingDate, "data", true);

            AssertDescriptions(addingDate, deletingDate, "data", true);

            Assert.AreEqual(0, things.Length);

            //Main entity
            Assert.AreEqual(0, managers.Length);

            //First level used entities
            AssertOffices();

            AssertCars();

            AssertProjects(null, null);
        }
Ejemplo n.º 22
0
        public void Get_ByFilterForUsedEntity_ReturnsEntities()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            Add10Managers();

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    Filter = new EqualsCondition()
                    {
                        Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Car.Data),
                        Value = "data"
                    }
                }
            });

            //Assert
            Assert.AreEqual(10, entities.Length);
            for (int i = 1; i < 10; i++)
            {
                Assert.IsTrue(entities[i].Id - entities[i - 1].Id == 1);
            }
        }
Ejemplo n.º 23
0
        public void Get_ByFilterWhenDeletedEntitiesExist_ReturnsNotDeletedEntities()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            Add10Managers();

            var entitiesToDelete = repository.Get(new GetOperationParameters());

            repository.Delete(new DeleteOperationParameters()
            {
                PrimaryKeys = new object[] { entitiesToDelete[0].Id }
            });

            repository.Delete(new DeleteOperationParameters()
            {
                PrimaryKeys = new object[] { entitiesToDelete[1].Id }
            });

            repository.Delete(new DeleteOperationParameters()
            {
                PrimaryKeys = new object[] { entitiesToDelete[2].Id }
            });

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    Filter = new OrOperator()
                    {
                        LeftOperand = new ContainsCondition()
                        {
                            Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                            Value = "data9"
                        },
                        RightOperand = new OrOperator()
                        {
                            LeftOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data1"
                            },
                            RightOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data2"
                            }
                        }
                    }
                }
            });

            //Assert
            Assert.AreEqual(1, entities.Length);
            foreach (var entity in entities)
            {
                Assert.AreEqual("data9", entity.Data);
            }
        }
Ejemplo n.º 24
0
        public void Add_WithRequiredSubEntitiesAndRequiredUsedEntities_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"
            };

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

            //Assert
            var context = new EFContext();

            var managers = context.Managers
                .Include(ReflectionHelper.GetPropertyName<Manager, Car>(e => e.Car))
                .Include(ReflectionHelper.GetPropertyName<Manager, Computer>(e => e.Computer))
                .Include(ReflectionHelper.GetPropertyName<Manager, Description>(e => e.Description))
                .Include(ReflectionHelper.GetPropertyName<Manager, Director>(e => e.Director))
                .Include(ReflectionHelper.GetPropertyName<Manager, Office>(e => e.Office))
                .ToArray();

            var computers = context.Computers.ToArray();

            AssertUsingEntities();

            AssertSecondLevelUsedEntities();

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

            //Main entity
            Assert.AreEqual(1, managers.Length);
            Assert.AreEqual("data", managers[0].Data);
            Assert.AreEqual(null, managers[0].Car);
            Assert.AreEqual(computers[0].Id, managers[0].Computer.Id);
            Assert.AreEqual(null, managers[0].Description);
            Assert.AreEqual(null, managers[0].Director);
            Assert.AreEqual(office1.Id, managers[0].Office.Id);

            //First level used entities
            AssertOffices();
        }
Ejemplo n.º 25
0
        public void Get_WhenFilteredAndSortedAndPaged_ReturnsEntities()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            Add10Managers();

            //Act
            var getParameters = new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    Filter = new OrOperator()
                    {
                        LeftOperand = new OrOperator()
                        {
                            LeftOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data1"
                            },
                            RightOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data2"
                            }
                        },
                        RightOperand = new OrOperator()
                        {
                            LeftOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data3"
                            },
                            RightOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data4"
                            }
                        },
                    },
                    SortingParameters = new QuerySortingParameters()
                    {
                        SortBy = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                        SortingType = SortingType.Descending
                    },
                    PagingParameters = new QueryPagingParameters()
                    {
                        PageNumber = 0,
                        PageSize = 3,
                    }
                }
            };

            var entities = repository.Get(getParameters);

            //Assert
            Assert.AreEqual(3, entities.Length);
            Assert.AreEqual(4, getParameters.QueryParameters.PagingParameters.TotalCount);
            Assert.AreEqual("data4", entities[0].Data);
            Assert.AreEqual("data3", entities[1].Data);
            Assert.AreEqual("data2", entities[2].Data);
        }
Ejemplo n.º 26
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()
            {
                Manager = manager,
                Data = "data"
            });

            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("data", entities[0].Computer.Data);
            Assert.AreEqual(admin.Id, entities[0].Computer.Admin.Id);

            Assert.AreEqual("data", entities[0].Description.Data);

            Assert.AreEqual("data", entities[0].Things[0].Data);
            Assert.AreEqual(admin.Id, entities[0].Things[0].Admin.Id);
            Assert.AreEqual(entities[0].Id, entities[0].Things[0].Manager.Id);

            Assert.AreEqual("data", entities[0].Things[1].Data);
            Assert.AreEqual(admin.Id, entities[0].Things[1].Admin.Id);
            Assert.AreEqual(entities[0].Id, entities[0].Things[1].Manager.Id);

            //Main entity
            Assert.AreEqual("data", entities[0].Data);
            Assert.AreEqual(car1.Id, entities[0].Car.Id);
            Assert.AreEqual(director.Id, entities[0].Director.Id);
            Assert.AreEqual(office1.Id, entities[0].Office.Id);

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

            Assert.AreEqual(admin.Id, entities[0].Car.Admin.Id);
            Assert.AreEqual(car1.Id, entities[0].Car.Id);
            Assert.AreEqual("data", entities[0].Car.Data);

            Assert.AreEqual(admin.Id, entities[0].Projects[0].Admin.Id);
            Assert.AreEqual(project1.Id, entities[0].Projects[0].Id);
            Assert.AreEqual("data", entities[0].Projects[0].Data);
            Assert.AreEqual(manager.Id, entities[0].Projects[0].Manager.Id);

            //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("data", entities[0].ManagerTrackers[0].Data);
            Assert.AreEqual(manager.Id, entities[0].ManagerTrackers[0].Manager.Id);

            //Get result
        }
Ejemplo n.º 27
0
        public void Get_WhenPageNumberIs4AndPageSizeIs3_ReturnsLastEntity()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            Add10Managers();

            //Act
            var getParameters = new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    PagingParameters = new QueryPagingParameters()
                    {
                        PageNumber = 3,
                        PageSize = 3,
                    }
                }
            };

            var entities = repository.Get(getParameters);

            //Assert
            Assert.AreEqual(1, entities.Length);
            Assert.AreEqual(10, getParameters.QueryParameters.PagingParameters.TotalCount);
            Assert.AreEqual("data9", entities[0].Data);
        }
Ejemplo n.º 28
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()
            {
                Manager = manager,
                Data = "data"
            });

            context.SaveChanges();

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

            //Assert
            Assert.AreEqual(true, entities[0].IsUsed);
        }
Ejemplo n.º 29
0
        public void Get_WithSorting_ReturnsSortedEntities()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            Add10Managers();

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    Filter = new OrOperator()
                    {
                        LeftOperand = new ContainsCondition()
                        {
                            Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                            Value = "9"
                        },
                        RightOperand = new OrOperator()
                        {
                            LeftOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data1"
                            },
                            RightOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                                Value = "data2"
                            }
                        }
                    },
                    SortingParameters = new QuerySortingParameters()
                    {
                        SortBy = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                        SortingType = SortingType.Descending
                    }
                }
            });

            //Assert
            Assert.AreEqual(3, entities.Length);
            foreach (var entity in entities)
            {
                Assert.IsTrue(entity.Data == "data1"
                    || entity.Data == "data2"
                    || entity.Data == "data9");
            }
        }
Ejemplo n.º 30
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();
        }
Ejemplo n.º 31
0
        private void Add10Managers()
        {
            var repository = new EFRepositoryTester();
            repository.Initialize();

            var addingDate = DateTime.UtcNow;

            for (int i = 0; i < 10; i++)
            {
                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
                    //}
                };

                manager.Data = "data" + i;

                repository.Add(new AddOperationParameters<Manager>()
                {
                    Entity = manager,
                    OperationDateTime = addingDate
                });
            }
        }
Ejemplo n.º 32
0
        public void Get_ByFilter_ReturnsEntities()
        {
            //Arrange
            var repository = new EFRepositoryTester();
            repository.Initialize();

            Add10Managers();

            //Act
            var entities = repository.Get(new GetOperationParameters()
            {
                QueryParameters = new QueryParameters()
                {
                    Filter = new OrOperator()
                    {
                        LeftOperand = new ContainsCondition()
                        {
                            Property = ReflectionHelper.GetPropertyName<Manager, string>(e => e.Data),
                            Value = "9"
                        },
                        RightOperand = new OrOperator()
                        {
                            LeftOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, long>(e => e.CreatedById),
                                Value = 0L
                            },
                            RightOperand = new EqualsCondition()
                            {
                                Property = ReflectionHelper.GetPropertyName<Manager, long>(e => e.CreatedById),
                                Value = 1L
                            }
                        }
                    }
                }
            });

            //Assert
            Assert.AreEqual(7, entities.Length);
            foreach (var entity in entities)
            {
                Assert.IsTrue(entity.CreatedById == 0
                    || entity.CreatedById == 1
                    || entity.Data == "data9");
            }
        }