Пример #1
0
        public void initialize()
        {
            //Initialize repository
            var mockRepo = new Mock <IProjectManagerDL>();

            //create sample user data
            _userList = new List <UserEntity>()
            {
                new UserEntity {
                    UserId = 1, FirstName = "Ravi", LastName = "Ramm", EmpId = 101131, UserStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new UserEntity {
                    UserId = 2, FirstName = "Raja", LastName = "Suresh", EmpId = 101132, UserStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new UserEntity {
                    UserId = 3, FirstName = "Sanjay", LastName = "Vikram", EmpId = 101133, UserStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new UserEntity {
                    UserId = 4, FirstName = "Suresh", LastName = "Hari", EmpId = 101134, UserStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new UserEntity {
                    UserId = 5, FirstName = "Bharath", LastName = "Vinayak", EmpId = 101135, UserStatus = "N", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                }
            };

            //Setup mocking behavior

            //Get the list of all the Active Users
            mockRepo.Setup(u => u.GetAllUsers()).Returns(_userList);

            //Get the user by sending User ID
            mockRepo.Setup(u => u.GetUser(It.IsAny <int>()))
            .Returns((int id) => _userList.Find(u => u.UserId.Equals(id)));

            //Add the user
            mockRepo.Setup(u => u.AddUser(It.IsAny <UserEntity>()))
            .Callback((UserEntity user) => _userList.Add(user));

            //Update the user
            mockRepo.Setup(u => u.UpdateUser(It.IsAny <UserEntity>()))
            .Callback((UserEntity updatedUser) =>
            {
                var actualUser = _userList.Find(u => u.UserId.Equals(updatedUser.UserId));

                actualUser.FirstName  = updatedUser.FirstName;
                actualUser.LastName   = updatedUser.LastName;
                actualUser.EmpId      = updatedUser.EmpId;
                actualUser.UserStatus = updatedUser.UserStatus;
                actualUser.UpdtDate   = new DateTime();
            }
                      );

            _mockRepository = mockRepo.Object;
        }
Пример #2
0
        public void initialize()
        {
            //Initialize repository
            var mockRepo = new Mock <IProjectManagerDL>();

            //create sample user data
            _projectList = new List <ProjectEntity>()
            {
                new ProjectEntity {
                    ProjectId = 1, ProjectName = "Requirement Analysis", ProjectPriority = 2, DateReqd = "N", StartDate = null, EndDate = null, ManagerId = 1, ProjectStatus = "N", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new ProjectEntity {
                    ProjectId = 2, ProjectName = "Creating Prototype", ProjectPriority = 3, DateReqd = "Y", StartDate = new DateTime(2018, 9, 9), EndDate = new DateTime(2018, 9, 15), ManagerId = 1, ProjectStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new ProjectEntity {
                    ProjectId = 3, ProjectName = "Design Preparation", ProjectPriority = 4, DateReqd = "Y", StartDate = new DateTime(2018, 9, 10), EndDate = new DateTime(2018, 9, 20), ManagerId = 1, ProjectStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new ProjectEntity {
                    ProjectId = 4, ProjectName = "New Project", ProjectPriority = 11, DateReqd = "N", StartDate = null, EndDate = null, ManagerId = 6, ProjectStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new ProjectEntity {
                    ProjectId = 5, ProjectName = "New Project 123", ProjectPriority = 5, DateReqd = "Y", StartDate = new DateTime(2018, 9, 15), EndDate = new DateTime(2018, 9, 25), ManagerId = 5, ProjectStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                }
            };

            //Setup mocking behavior

            //Get the list of all the Active Projects
            mockRepo.Setup(p => p.GetAllProjects()).Returns(_projectList);

            //Get the Project by project Id
            mockRepo.Setup(p => p.GetProject(It.IsAny <int>()))
            .Returns((int id) => _projectList.Find(p => p.ProjectId.Equals(id)));

            //Add the project
            mockRepo.Setup(p => p.AddProject(It.IsAny <ProjectEntity>()))
            .Callback((ProjectEntity project) => _projectList.Add(project));

            //Updated the project
            mockRepo.Setup(p => p.UpdateProject(It.IsAny <ProjectEntity>()))
            .Callback((ProjectEntity updatedProject) =>
            {
                var actualProject = _projectList.Find(p => p.ProjectId.Equals(updatedProject.ProjectId));

                actualProject.ProjectName     = updatedProject.ProjectName;
                actualProject.ProjectPriority = updatedProject.ProjectPriority;
                actualProject.ManagerId       = updatedProject.ManagerId;
                actualProject.StartDate       = updatedProject.StartDate;
            }
                      );

            _mockRepository = mockRepo.Object;
        }
        public void initialize()
        {
            // Initialize repository
            var mockRepo = new Mock <IProjectManagerDL>();

            //create sample data

            _parentTaskList = new List <ParentTaskEntity>()
            {
                new ParentTaskEntity {
                    ParentId = 1, ParentTask = "Test project Creation", ParentStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new ParentTaskEntity {
                    ParentId = 2, ParentTask = "Project Testing", ParentStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new ParentTaskEntity {
                    ParentId = 3, ParentTask = "Repository Creation", ParentStatus = "Y", AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
            };

            _taskList = new List <TaskEntity>()
            {
                new TaskEntity {
                    TaskId = 1, Task = "Test project Creation", ParentId = 1, ParentTask = "Test project Creation", TaskPriority = 1, TaskStatus = "Y", StartDate = new DateTime(2018, 9, 9), EndDate = new DateTime(2018, 9, 9), ProjectId = 1, UserId = 2, AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new TaskEntity {
                    TaskId = 2, Task = "Setup Creation", ParentId = 1, ParentTask = "Test project Creation", TaskPriority = 2, TaskStatus = "Y", StartDate = new DateTime(2018, 9, 9), EndDate = new DateTime(2018, 9, 9), ProjectId = 2, UserId = 1, AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new TaskEntity {
                    TaskId = 3, Task = "Repository Creation", ParentId = 1, ParentTask = "Test project Creation", TaskPriority = 2, TaskStatus = "Y", StartDate = new DateTime(2018, 9, 9), EndDate = new DateTime(2018, 9, 9), ProjectId = 3, UserId = 4, AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new TaskEntity {
                    TaskId = 4, Task = "Test case creation", ParentId = 3, ParentTask = "Repository Creation", TaskPriority = 3, TaskStatus = "Y", StartDate = new DateTime(2018, 9, 9), EndDate = new DateTime(2018, 9, 10), ProjectId = 1, UserId = 1, AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
                new TaskEntity {
                    TaskId = 5, Task = "Test case execution", ParentId = 3, ParentTask = "Repository Creation", TaskPriority = 4, TaskStatus = "N", StartDate = new DateTime(2018, 9, 9), EndDate = new DateTime(2018, 9, 9), ProjectId = 2, UserId = 5, AddDate = new DateTime(2018, 9, 9), UpdtDate = new DateTime(2018, 9, 9)
                },
            };

            // Setup mocking behavior

            //Get the list of all the parent tasks
            mockRepo.Setup(p => p.GetAllParentTasks()).Returns(_parentTaskList);

            //Add the parent task
            mockRepo.Setup(p => p.AddParentTask(It.IsAny <ParentTaskEntity>()))
            .Callback((ParentTaskEntity parentTask) => _parentTaskList.Add(parentTask));


            //Get the list of all the tasks
            mockRepo.Setup(p => p.GetAllTasks()).Returns(_taskList);

            //Get the list of all the tasks by project Id
            mockRepo.Setup(p => p.GetAllTasks(It.IsAny <int>()))
            .Returns((int projectId) => _taskList.Where(p => p.ProjectId == projectId).ToList());


            //Get the one particular task
            mockRepo.Setup(p => p.GetTask(It.IsAny <int>()))
            .Returns((int id) => _taskList.Find(p => p.TaskId.Equals(id)));

            //Add the task
            mockRepo.Setup(p => p.AddTask(It.IsAny <TaskEntity>()))
            .Callback((TaskEntity task) => _taskList.Add(task));

            //Update the task
            mockRepo.Setup(p => p.UpdateTask(It.IsAny <TaskEntity>()))
            .Callback((TaskEntity updatedTask) =>
            {
                var actualTask = _taskList.Find(p => p.TaskId.Equals(updatedTask.TaskId));

                actualTask.Task         = updatedTask.Task;
                actualTask.ParentId     = updatedTask.ParentId;
                actualTask.TaskPriority = updatedTask.TaskPriority;
                actualTask.StartDate    = updatedTask.StartDate;
                actualTask.EndDate      = updatedTask.EndDate;
                actualTask.TaskStatus   = updatedTask.TaskStatus;
                actualTask.UserId       = updatedTask.UserId;
            }
                      );

            //End the Task
            mockRepo.Setup(p => p.EndTask(It.IsAny <int>()))
            .Callback((int taskId) =>
            {
                var actualTask = _taskList.Find(p => p.TaskId.Equals(taskId));

                actualTask.TaskStatus = "N";
            }
                      );

            _mockRepository = mockRepo.Object;
        }
 public ProjectManagerBL(IProjectManagerDL projDL)
 {
     _projDL = projDL;
 }