Esempio n. 1
0
 public void InitializeTeamTests()
 {
     _testUser1 = new User {ID = 1, Name = "testUser1"};
     _testUser2 = new User {ID = 2, Name = "testUser2"};
     _users.Add(_testUser1);
     _testTeam = new Team {ID = 1, Name = "Test Team", Users = _users};
 }
Esempio n. 2
0
        /// <summary>
        /// Convert a TeamDTO and store it in the repositoy
        /// </summary>
        /// <param name="teamDto"> DTO of the team to be created</param>
        /// <returns></returns>
        public int CreateTeam(TeamDto teamDto)
        {
            if (teamDto.UserIDs == null || teamDto.UserIDs.Length == 0)
            {
                throw new ArgumentException("The team doesn't have any users");
            }

            var teamToAdd = new Team
            {
                Name = teamDto.Name,
                ID = teamDto.Id,
                Metadata = teamDto.Metadata,
                Users = new List<User>()
            };

            foreach (var userId in teamDto.UserIDs)
            {
                if (_teamStorageManager.GetUser(userId) == null)
                {
                    throw new NullReferenceException("User doesn't exist in database");
                }
            }
            foreach (var userId in teamDto.UserIDs)
            {
                teamToAdd.Users.Add(_teamStorageManager.GetUser(userId));
            }

            return _teamStorageManager.CreateTeam(teamToAdd);
        }
        public void InitializeRepo()
        {
            _id = 1;
            _teams = new Dictionary<int, Team>();
            _mockTeamRepo = new Mock<IGenericRepository>();
            _testTeam = new Team {ID = 1};
            _testTeamStorageManager = new TeamStorageManager(_mockTeamRepo.Object);

            // Read item - Team
            _mockTeamRepo.Setup(r => r.Read<Team>(It.IsAny<int>()))
                .Returns<int>(id => _teams.First(e => e.Key == id).Value);

            // Read items - Team
            _mockTeamRepo.Setup(r => r.Read<Team>()).Returns(_teams.Values.AsQueryable());

            // Create - Team
            _mockTeamRepo.Setup(r => r.Create(It.IsAny<Team>())).Callback<Team>(team =>
            {
                var nextId = _id++;
                team.ID = nextId;
                _teams.Add(nextId, team);
            });

            // Update - Team
            _mockTeamRepo.Setup(r => r.Update(It.IsAny<Team>())).Callback<Team>(team =>
            {
                if (_teams.ContainsKey(team.ID))
                {
                    _teams[team.ID] = team;
                }
            });

            // Delete - Team
            _mockTeamRepo.Setup(r => r.Delete(It.IsAny<Team>())).Callback<Team>(team => { _teams.Remove(team.ID); });
        }
 /// <summary>
 ///     Tests get on all teams in the mock repo
 /// </summary>
 public void TestStorageGetAllTeams()
 {
     _testTeamStorageManager.CreateTeam(_testTeam);
     var testTeam2 = new Team();
     _testTeamStorageManager.CreateTeam(testTeam2);
     Assert.AreEqual(2, _testTeamStorageManager.GetAllTeams().Count());
 }
 public void TestStorageUpdateTeam()
 {
     var testTeam = new Team {ID = 1, Name = "Team"};
     _testTeamStorageManager.CreateTeam(testTeam);
     testTeam.Name = "Team Awesome";
     _testTeamStorageManager.UpdateTeam(testTeam);
     Assert.AreEqual("Team Awesome", _testTeamStorageManager.GetTeam(1).Name);
 }
Esempio n. 6
0
        public void Setup()
        {
            var item1Data = new Dictionary<FieldType, string>
            {
                {new FieldType {Type = FieldType.TypEField.Title}, "title"}
            };

            _testItem1 = new Item(Item.ItemType.Book, item1Data);
            _testItem2 = new Item(Item.ItemType.Book, item1Data);
            _testItem3 = new Item(Item.ItemType.Book, item1Data);

            _items = new List<Item> {_testItem1, _testItem2, _testItem1};

            var testUser1 = new User {Name = "chris"};
            var testUser2 = new User {Name = "ramos"};
            var testUser3 = new User {Name = "kathrin"};
            var testUser4 = new User {Name = "emil"};
            var testUser5 = new User {Name = "user1"};
            var testUser6 = new User {Name = "user2"};
            var testUser7 = new User {Name = "user3"};
            var testUser8 = new User {Name = "user4"};

            var testTeam1 = new Team
            {
                Name = "team1",
                Users = new List<User> {testUser1, testUser2, testUser3, testUser4}
            };
            var testTeam2 = new Team
            {
                Name = "team2",
                Users = new List<User> {testUser5, testUser6, testUser7, testUser8}
            };
            var testTeam3 = new Team
            {
                Name = "team3",
                Users = new List<User> {testUser1, testUser6, testUser3, testUser8}
            };

            var expectedUserData1 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "2015"}},
                UserId = 1
            };
            var expectedUserData2 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "2015"}},
                UserId = 2
            };
            var expectedUserData3 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "2015"}},
                UserId = 2
            };

            var emptyUserData1 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = null}},
                UserId = 1
            };
            var emptyUserData2 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = null}},
                UserId = 2
            };

            //Finished
            _task1 = new StudyTask
            {
                DataFields = new List<DataField>
                {
                    new DataField
                    {
                        Name = "Year",
                        UserData = new List<UserData> {expectedUserData1, expectedUserData2}
                    }
                },
                Users = new List<User> {testUser1, testUser2},
                TaskType = StudyTask.Type.Review,
                IsEditable = true,
                Paper = _testItem1
            };

            //Unfinished
            _task2 = new StudyTask
            {
                DataFields = new List<DataField>
                {
                    new DataField
                    {
                        Name = "Year",
                        UserData = new List<UserData> {emptyUserData1, expectedUserData3}
                    }
                },
                Users = new List<User> {testUser1, testUser2},
                TaskType = StudyTask.Type.Review,
                IsEditable = true,
                Paper = _testItem2
            };

            //Not Editable
            _task3 = new StudyTask
            {
                DataFields = new List<DataField>
                {
                    new DataField
                    {
                        Name = "Year",
                        UserData = new List<UserData> {expectedUserData1}
                    }
                },
                Users = new List<User> {testUser1},
                TaskType = StudyTask.Type.Review,
                IsEditable = false,
                Paper = _testItem3
            };

            _dbMock = new Mock<IGenericRepository>();
            _dbMock.Setup(t => t.Read<StudyTask>(1))
                .Returns(_task1);
            _dbMock.Setup(t => t.Read<StudyTask>(3))
                .Returns(_task3);

            _dbMock.Setup(t => t.Update(_task1))
                .Returns(true);

            _manager = new TaskManager(_dbMock.Object);
        }
Esempio n. 7
0
 /// <summary>
 /// Create a team
 /// </summary>
 /// <param name="team"></param>
 /// <returns></returns>
 public int CreateTeam(Team team)
 {
     return _repo.Create(team);
 }
Esempio n. 8
0
 /// <summary>
 /// Update a team
 /// </summary>
 /// <param name="team"></param>
 /// <returns></returns>
 public bool UpdateTeam(Team team)
 {
     try
     {
         return _repo.Update(team);
     }
     catch (NullReferenceException)
     {
         throw new NullReferenceException(_teamException);
     }
 }
Esempio n. 9
0
        public void InitializeTests()
        {
            var user1 = new User {ID = 1};
            var user2 = new User {ID = 2};

            var team1 = new Team {Users = new List<User> {user1, user2}};

            var dataString1 = new StoredString {Value = "someData"};
            var datastring2 = new StoredString {Value = "someOtherData"};
            var nullString = new StoredString {Value = null};

            var userData1 = new UserData {UserId = 1, Data = new List<StoredString> {dataString1, datastring2}};
            var userData2 = new UserData {UserId = 2, Data = new List<StoredString> {nullString, nullString}};
            var userData3 = new UserData {UserId = 2, Data = new List<StoredString> {dataString1, datastring2}};
            var userData4 = new UserData {UserId = 1, Data = new List<StoredString> {nullString, nullString}};

            var dataField = new DataField {UserData = new List<UserData> {userData1, userData3}};
            var dataField2 = new DataField {UserData = new List<UserData> {userData2, userData4}};

            var task1 = new StudyTask
            {
                DataFields = new List<DataField> {dataField},
                Users = new List<User> {user1, user2}
            };
            var task2 = new StudyTask
            {
                DataFields = new List<DataField> {dataField2},
                Users = new List<User> {user1, user2}
            };

            var userstudy1 = new UserStudies {User = user1};
            var userstudy2 = new UserStudies {User = user2};

            var stage1 = new Stage
            {
                Name = "stage1",
                IsCurrentStage = true,
                ID = 1,
                Users = new List<UserStudies> {userstudy1, userstudy2},
                Tasks = new List<StudyTask> {task1, task2}
            };
            var stage2 = new Stage
            {
                Name = "stage2",
                IsCurrentStage = false,
                ID = 2,
                Users = new List<UserStudies> {userstudy1, userstudy2},
                Tasks = new List<StudyTask> {task1, task2}
            };

            _id = 1;
            _mockStudyRepo = new Mock<IGenericRepository>();

            _testStudy = new Study
            {
                ID = 1,
                IsFinished = false,
                Items = new List<Item>(),
                Stages = new List<Stage> {stage1, stage2},
                Team = team1
            };

            _studies = new Dictionary<int, Study> {{1, _testStudy}};

            _testStudyStorageManager = new StudyStorageManager(_mockStudyRepo.Object);

            _testController = new StudyOverview(_testStudyStorageManager, _testTaskStorageManager);

            // Read item
            _mockStudyRepo.Setup(r => r.Read<Study>(It.IsAny<int>()))
                .Returns<int>(id => _studies.First(e => e.Key == id).Value);

            // Read items
            _mockStudyRepo.Setup(r => r.Read<Study>()).Returns(_studies.Values.AsQueryable());

            // Create
            _mockStudyRepo.Setup(r => r.Create(It.IsAny<Study>())).Callback<Study>(study =>
            {
                var nextId = _id++;
                study.ID = nextId;
                _studies.Add(nextId, study);
            });

            // Update
            _mockStudyRepo.Setup(r => r.Update(It.IsAny<Study>())).Callback<Study>(study =>
            {
                if (_studies.ContainsKey(study.ID))
                {
                    _studies[study.ID] = study;
                }
            });

            // Delete
            _mockStudyRepo.Setup(r => r.Delete(It.IsAny<Study>()))
                .Callback<Study>(study => { _studies.Remove(study.ID); });
        }