示例#1
0
            public void should_modify_teams()
            {
                //arrange
                Employee employee = null;
                UnitOfWork.Do(uow =>
                {
                    var team1 = new Team() { Name = "Super", Description = "SuperBg" };
                    team1.Id = (int)uow.Repo<Team>().Insert<decimal>(team1);

                    var team2 = new Team() { Name = "Great", Description = "GreatBg" };
                    team2.Id = (int)uow.Repo<Team>().Insert<decimal>(team2);

                    employee = new Employee { Id = "666", FirstName = "John", LastName = "Smith" };
                    uow.Repo<Employee>().Insert(employee);

                    var team1Employee = new TeamEmployeeMap { EmployeeId = employee.Id, TeamId = team1.Id };
                    uow.Repo<TeamEmployeeMap>().Insert(team1Employee);

                    var team2Employee = new TeamEmployeeMap { EmployeeId = employee.Id, TeamId = team2.Id };
                    uow.Repo<TeamEmployeeMap>().Insert(team2Employee);
                });

                //act
                UnitOfWork.Do(uow =>
                {

                    var foundEmployeeTeams = (from emp in uow.Repo<Employee>().AsQueryable()
                                join teamEmp in uow.Repo<TeamEmployeeMap>().AsQueryable() on emp.Id equals teamEmp.EmployeeId
                                join team in uow.Repo<Team>().AsQueryable() on teamEmp.TeamId equals  team.Id
                                where emp.Id==employee.Id
                                select team).ToList();

                    foundEmployeeTeams[0].Name = "Super-upd";
                    foundEmployeeTeams[0].Description = "SuperBg-upd";
                    foundEmployeeTeams[1].Name = "Great-upd";
                    foundEmployeeTeams[1].Description = "GreatBg-upd";

                    uow.Repo<Team>().Update(foundEmployeeTeams[0]);
                    uow.Repo<Team>().Update(foundEmployeeTeams[1]);

                    var newTeam = new Team() { Name = "Awesome", Description = "AwesomeBg" };
                    newTeam.Id = (int)uow.Repo<Team>().Insert<decimal>(newTeam);

                    var newTeamEmployee = new TeamEmployeeMap { EmployeeId = employee.Id, TeamId = newTeam.Id };
                    uow.Repo<TeamEmployeeMap>().Insert(newTeamEmployee);
                });

                //assert
                UnitOfWork.Do(uow =>
                {
                    var resultEmployeeTeams = (from emp in uow.Repo<Employee>().AsQueryable()
                                              join teamEmp in uow.Repo<TeamEmployeeMap>().AsQueryable() on emp.Id equals teamEmp.EmployeeId
                                              join team in uow.Repo<Team>().AsQueryable() on teamEmp.TeamId equals team.Id
                                              where emp.Id == employee.Id
                                              orderby team.Id
                                              select team).ToList();

                    resultEmployeeTeams.Count.Should().Be(3);
                    resultEmployeeTeams[0].Name.Should().Be("Super-upd");
                    resultEmployeeTeams[0].Description.Should().Be("SuperBg-upd");
                    resultEmployeeTeams[1].Name.Should().Be("Great-upd");
                    resultEmployeeTeams[1].Description.Should().Be("GreatBg-upd");
                    resultEmployeeTeams[2].Name.Should().Be("Awesome");
                    resultEmployeeTeams[2].Description.Should().Be("AwesomeBg");
                });
            }
示例#2
0
            public void should_return_all_employees()
            {
                //arrange
                Team team = null;
                Employee employee1 = null;
                Employee employee2 = null;
                Employee employee3 = null;
                UnitOfWork.Do(uow =>
                {
                    team = new Team() { Name = "Super", Description = "SuperBg" };
                    team.Id = (int)uow.Repo<Team>().Insert<decimal>(team);

                    employee1 = new Employee { Id = "555", FirstName = "Jack", LastName = "Black" };
                    uow.Repo<Employee>().Insert(employee1);

                    employee2 = new Employee { Id = "666", FirstName = "John", LastName = "Smith" };
                    uow.Repo<Employee>().Insert(employee2);

                    employee3 = new Employee { Id = "777", FirstName = "Billy", LastName = "Bobby"};
                    uow.Repo<Employee>().Insert(employee3);

                    var teamEmployee2 = new TeamEmployeeMap {EmployeeId = employee2.Id, TeamId = team.Id};
                    uow.Repo<TeamEmployeeMap>().Insert(teamEmployee2);

                    var teamEmployee3 = new TeamEmployeeMap { EmployeeId = employee3.Id, TeamId = team.Id };
                    uow.Repo<TeamEmployeeMap>().Insert(teamEmployee3);
                });

                UnitOfWork.Do(uow =>
                {
                    //act
                    var resultEmployees = uow.Repo<Employee>().AsQueryable().OrderBy(t=>t.Id).ToArray();
                    var resultTeamEmployeeMaps = uow.Repo<TeamEmployeeMap>().AsQueryable().OrderBy(t=>t.EmployeeId).ToArray();

                    //assert
                    resultEmployees.Length.Should().Be(3);

                    resultEmployees[0].Id.Should().Be(employee1.Id);
                    resultEmployees[0].FirstName.Should().Be(employee1.FirstName);
                    resultEmployees[0].LastName.Should().Be(employee1.LastName);
                    resultTeamEmployeeMaps.Count(t => t.EmployeeId == resultEmployees[0].Id).Should().Be(0);

                    resultEmployees[1].Id.Should().Be(employee2.Id);
                    resultEmployees[1].FirstName.Should().Be(employee2.FirstName);
                    resultEmployees[1].LastName.Should().Be(employee2.LastName);
                    resultTeamEmployeeMaps.First(t => t.EmployeeId == resultEmployees[1].Id).TeamId.Should().Be(team.Id);

                    resultEmployees[2].Id.Should().Be(employee3.Id);
                    resultEmployees[2].FirstName.Should().Be(employee3.FirstName);
                    resultEmployees[2].LastName.Should().Be(employee3.LastName);
                    resultTeamEmployeeMaps.First(t => t.EmployeeId == resultEmployees[2].Id).TeamId.Should().Be(team.Id);
                });
            }
示例#3
0
            public void should_return_employee()
            {
                //arrange
                Employee employee2 = null;
                UnitOfWork.Do(uow =>
                    {
                    var team = new Team() { Name = "Super", Description = "SuperBg"};
                    team.Id = (int)uow.Repo<Team>().Insert<decimal>(team);

                    var employee1 = new Employee { Id = "667", FirstName = "Jack", LastName = "Black" };
                    uow.Repo<Employee>().Insert(employee1);

                    employee2 = new Employee { Id = "666", FirstName = "John", LastName = "Smith"};
                    uow.Repo<Employee>().Insert(employee2);

                    var teamEmployee2Map = new TeamEmployeeMap() { TeamId = team.Id, EmployeeId = employee2.Id};
                    uow.Repo<TeamEmployeeMap>().Insert(teamEmployee2Map);
                });

                UnitOfWork.Do(uow =>
                {
                    //act
                    var resultEmployee = uow.Repo<Employee>().AsQueryable().FirstOrDefault(t => t.Id == employee2.Id);

                    //assert
                    resultEmployee.Id.Should().Be(employee2.Id);
                    resultEmployee.FirstName.Should().Be(employee2.FirstName);
                    resultEmployee.LastName.Should().Be(employee2.LastName);
                });
            }
示例#4
0
            public void should_return_employee()
            {
                //arrange
                Team team = null;
                Employee employee2 = null;
                UnitOfWork.Do(uow =>
                {
                    team = new Team() { Name = "Super", Description = "SuperBg" };
                    team.Id = (int)uow.Repo<Team>().Insert<decimal>(team);

                    var employee1 = new Employee { Id = "555", FirstName = "Jack", LastName = "Black" };
                    uow.Repo<Employee>().Insert(employee1);

                    employee2 = new Employee { Id = "666", FirstName = "John", LastName = "Smith" };
                    uow.Repo<Employee>().Insert(employee2);

                    var employee3 = new Employee { Id = "777", FirstName = "Billy", LastName = "Bobby" };
                    uow.Repo<Employee>().Insert(employee3);

                    var teamEmployee2 = new TeamEmployeeMap { EmployeeId = employee2.Id, TeamId = team.Id };
                    uow.Repo<TeamEmployeeMap>().Insert(teamEmployee2);

                    var teamEmployee3 = new TeamEmployeeMap { EmployeeId = employee3.Id, TeamId = team.Id };
                    uow.Repo<TeamEmployeeMap>().Insert(teamEmployee3);
                });

                UnitOfWork.Do(uow =>
                {
                    //act
                    var result = (from emp in uow.Repo<Employee>().AsQueryable()
                                 join teamEmp in uow.Repo<TeamEmployeeMap>().AsQueryable() on emp.Id equals teamEmp.EmployeeId
                                  where emp.FirstName=="John"
                                  select new {Emp = emp, TeamEmp=teamEmp}).ToList();

                    //assert
                    result.Count.Should().Be(1);
                    result[0].Emp.Id.Should().Be(employee2.Id);
                    result[0].Emp.FirstName.Should().Be(employee2.FirstName);
                    result[0].Emp.LastName.Should().Be(employee2.LastName);
                    result[0].TeamEmp.TeamId.Should().Be(team.Id);
                });
            }