public void AddTeamCorrect() { var team = new Team { Id = 1, Naam = "Team A" }; //Arange var teamRepo = new Mock <ISQLRepository <Team> >(); teamRepo.Setup(x => x.Add(It.IsAny <Team>())).Returns(team); var teamService = new TeamService(teamRepo.Object); //Act var teamDTO = new TeamDTO { Id = 1, Naam = "Team A" }; //Assert Assert.DoesNotThrow(() => teamService.AddTeam(teamDTO)); }
// public async Task<IActionResult> AddTeam(Team team, int roomId, int parentTeamId) public async Task <IActionResult> AddTeam(int roomId, int parentTeamId, TeamDto teamDto) { try { var userId = userService.GetUserId(); // var newTeam = await teamService.AddTeam(team, roomId, userId,parentTeamId); var user = await userService.getUserById(userId); var team = mapper.Map <Team>(teamDto); var newTeam = await teamService.AddTeam(team, roomId, userId, parentTeamId); var JoinChatOfTeam = await teamChatService.GetTeamChatOfTeam(newTeam.Id); // await chatHub.Clients.Group(JoinChatOfTeam.ChatName).SendAsync("ReceiveMessageOnJoin", $"User: {user.UserName} Join Group of {JoinChatOfTeam} "); //Not Show to New User That Join *Must Saved inHistory // await chatHub.Groups.AddToGroupAsync(chatHub.Clients.User(userId), JoinChatOfTeam.ChatName); //add to Group to tell Clients on Group new User Come var parentTeam = await teamService.GetTeamOnlyById(parentTeamId); // var notification = notificationService.CreateNewNotificaition(new Notification // { // Content = $"the leader of team {parentTeam.Name} accept your request to creatث a sub team from this team", // UserId = userId // }); // await notificationHub.Clients.User(userId).SendAsync("recievenotification",notification); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void AddTeam_WhenTheTeamNameAlreadyExists() { //Arrange myTeamRepository.Expect(x => x.GetAll()).Return(new List <Team> { new Team { TeamId = 1, TeamName = "TeamName" } }.AsQueryable()).Repeat.Once(); myUnitOfWork.Expect(x => x.GetGenericRepository <Team>()).Return(myTeamRepository).Repeat.Once(); myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once(); var newTeam = new Team { TeamName = "TeamName" }; var teamService = new TeamService { UnitOfWorkFactory = myUnitOfWorkFactory }; //Act var result = teamService.AddTeam(newTeam); //Asserts Assert.AreEqual(StatusCode.Error, result.StatusCode); Assert.AreEqual("The team name already exists in the system.", result.StatusMessage); myUnitOfWork.VerifyAllExpectations(); myUnitOfWorkFactory.VerifyAllExpectations(); myTeamRepository.VerifyAllExpectations(); }
public async Task CreateTeam(TeamViewModel teamVieweDto, int roomId) //Change => Enter Team{Name , Description} { try { var userId = userService.GetUserId(); var Team = mapper.Map <TeamViewModel, Team>(teamVieweDto); var newTeam = await teamService.AddTeam(Team, roomId, userId, 0); if (newTeam != null) { var JoinChatOfTeamByDefault = await teamChatService.GetTeamChatOfTeam(newTeam.Id); if (JoinChatOfTeamByDefault != null) { //await Groups.AddToGroupAsync(Context.ConnectionId, JoinChatOfTeamByDefault.ChatName); await Clients.Caller.SendAsync("ReceiveMessageOnAdd", $" Chat Group Called {JoinChatOfTeamByDefault} Created"); } var teamViewModel = mapper.Map <Team, TeamViewModel>(newTeam); await Clients.All.SendAsync("addTeam", teamViewModel); //Change soon Tell all Clients on Hub That a New Team Added } } catch (Exception ex) { await Clients.Caller.SendAsync("onError", "Couldn't create team: " + ex.Message); } }
public void AddTeam_Saves_Team() { //Arrange var teamSet = new Mock <DbSet <Team> >(); var mockContext = new Mock <BookmakerContext>(); mockContext.Setup(m => m.Teams).Returns(teamSet.Object); var teamService = new TeamService(mockContext.Object); //Act Team team = new Team() { Name = "Name", Division = 1, Budget = 1000000 }; teamService.AddTeam(team); //Assert teamSet.Verify(m => m.Add(It.IsAny <Team>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
private static string ProcessInitialData(string pdfText, SACServiceContext db) { string[] lines = pdfText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); using (TeamService teamService = new TeamService(db)) using (AthleteService athleteService = new AthleteService(db)) using (AgeRankService ageRankService = new AgeRankService(db)) { foreach (var line in lines) { int bibNumber; string firstName; string lastName; string teamName; string fullName; string ageRank; string[] fields = line.Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries); if (fields.Length < 5) { continue; } if (!Int32.TryParse(fields[0], out bibNumber)) { continue; } firstName = fields[1]; lastName = fields[2]; teamName = fields[3]; ageRank = fields[4]; int teamId = teamService.TeamExists(teamName); if (teamId == -1) { teamId = teamService.AddTeam(teamName).Id; } int ageRankId = ageRankService.AgeRankExists(AgeRankMappings.GetAgeRankNameByCode(ageRank)); if (ageRankId == -1) { ageRankId = ageRankService.AddAgeRank(AgeRankMappings.GetAgeRankNameByCode(ageRank)).Id; } fullName = firstName.Trim() + " " + lastName.Trim(); Athlete athlete; int athleteId = athleteService.AthleteExists(fullName); if (athleteId == -1) { athlete = athleteService.AddAthlete(fullName, bibNumber, ageRankId, teamId); } } } return(""); }
public void AddTeamNull() { var team = new Team { Id = 1, Naam = "Team A" }; //Arange var teamRepo = new Mock <ISQLRepository <Team> >(); teamRepo.Setup(x => x.Add(It.IsAny <Team>())).Returns(team); var teamService = new TeamService(teamRepo.Object); //Assert Assert.IsTrue(teamService.AddTeam(null).DidError); Assert.IsNull(teamService.AddTeam(null).DTO); }
private void AddTeam() { Team team = new Team(); team.Id = 1; team.Name = "Komanda"; team.Description = "desc"; teamService.AddTeam(team); }
public void AddTeam_TeamIsNull_ExpectArgumentException() { // arrange TeamService service = new TeamService(repoMock.Object); // act + assert var ex = Assert.Throws <ArgumentException>(() => service.AddTeam(null)); Assert.Equal("Team is missing", ex.Message); repoMock.Verify(repo => repo.Add(It.Is <Team>(team => team == null)), Times.Never); }
public async Task <IActionResult> AddTeam(DTOTeam team) { bool success = await _service.AddTeam(team); if (success) { return(Ok()); } else { return(BadRequest()); } }
public void AddTeam_WhenTeamNameIsMissing() { //Arrange var newTeam = new Team { TeamName = string.Empty }; var teamService = new TeamService(); //Act var result = teamService.AddTeam(newTeam); //Asserts Assert.AreEqual(StatusCode.Error, result.StatusCode); Assert.AreEqual("The TeamName field is required.", result.StatusMessage); }
public void AddTeam_InvalidStudentsList_ExpectArgumentException() { // arrange Team t = new Team() { Id = 1, Students = null }; TeamService service = new TeamService(repoMock.Object); // act + assert var ex = Assert.Throws <ArgumentException>(() => service.AddTeam(t)); Assert.Equal("Invalid Students property", ex.Message); repoMock.Verify(repo => repo.Add(It.Is <Team>(team => team == t)), Times.Never); }
public void AddTeam_TeamExists_ExpectInvalidOperationException() { // arrange Team t = new Team() { Id = 1, Students = new List <Student>() }; // Team t already exists in the TeamRepository repoMock.Setup(repo => repo.GetById(It.Is <int>(id => id == t.Id))).Returns(() => t); TeamService service = new TeamService(repoMock.Object); // act + assert var ex = Assert.Throws <InvalidOperationException>(() => service.AddTeam(t)); Assert.Equal("Team already in Repository", ex.Message); repoMock.Verify(repo => repo.Add(It.Is <Team>(team => team == t)), Times.Never); }
public void AddTeam_NonExistingValidTeam() { // arrange Team t = new Team() { Id = 1, Students = new List <Student>() }; // Team t does not exist in the TeamRepository repoMock.Setup(repo => repo.GetById(It.Is <int>(id => id == t.Id))).Returns(() => null); TeamService service = new TeamService(repoMock.Object); // act service.AddTeam(t); // assert repoMock.Verify(repo => repo.Add(It.Is <Team>(team => team == t)), Times.Once); }
public void TeamsService_addTeam_should_Throw_FormatException() { //arrange TeamMaster master = new TeamMaster() { TeamId = 1 }; List <TeamMaster> team = new List <TeamMaster>(); team.Add(master); var mockRepo = new Mock <ITeamRepo>(); mockRepo.Setup(m => m.AddTeam(It.IsAny <TeamMaster>())).Throws(new FormatException()); TeamService teamService = new TeamService(mockRepo.Object); //act var ex = Record.Exception(() => teamService.AddTeam(master)); //assert Assert.IsType <FormatException>(ex); }
public void AddTeam_Success_Test() { // Arrange TeamDTO dto = SampleTeamDTO(1); // create mock for repository var mock = new Mock <ITeamRepository>(); mock.Setup(s => s.AddTeam(Moq.It.IsAny <R_Team>())).Returns(1); // service TeamService teamService = new TeamService(); TeamService.Repository = mock.Object; // Act int id = teamService.AddTeam(dto); // Assert Assert.AreEqual(1, id); Assert.AreEqual(1, dto.TeamId); }
public void AddTeam_WhenTheProjectDoesntExist() { //Arrange myTeamRepository.Expect(x => x.GetAll()).Return(new List <Team> { new Team { TeamId = 1, TeamName = "TeamName", ProjectId = 5 } }.AsQueryable()).Repeat.Once(); myProjectRepository.Expect(x => x.GetAll()).Return(new List <Project> { new Project { ProjectId = 5, ProjectName = "TestProject" } }.AsQueryable()).Repeat.Once(); myUnitOfWork.Expect(x => x.GetGenericRepository <Team>()).Return(myTeamRepository).Repeat.Once(); myUnitOfWork.Expect(x => x.GetGenericRepository <Project>()).Return(myProjectRepository).Repeat.Once(); myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once(); var newTeam = new Team { TeamName = "TeamName2", ProjectId = 6 }; var teamService = new TeamService { UnitOfWorkFactory = myUnitOfWorkFactory }; //Act var result = teamService.AddTeam(newTeam); //Asserts Assert.AreEqual(StatusCode.Error, result.StatusCode); Assert.AreEqual("The project doesn't exist in the system.", result.StatusMessage); myUnitOfWork.VerifyAllExpectations(); myUnitOfWorkFactory.VerifyAllExpectations(); myTeamRepository.VerifyAllExpectations(); myProjectRepository.VerifyAllExpectations(); }
public string Execute(string[] inputArgs) { //CreateTeam <name> <acronym> <description> AuthenticationManager.Authorize(); if (inputArgs.Length != 2 && inputArgs.Length != 3) { throw new ArgumentOutOfRangeException(nameof(inputArgs)); } string teamName = inputArgs[0]; if (teamName.Length > 25) { throw new ArgumentException(string.Format(Constants.ErrorMessages.InvalidTeamName, teamName)); } if (CommandHelper.IsTeamExisting(teamName)) { throw new ArgumentException(string.Format(Constants.ErrorMessages.TeamExists, teamName)); } string acronym = inputArgs[1]; if (acronym.Length != 3) { throw new ArgumentException(string.Format(Constants.ErrorMessages.InvalidAcronym, acronym)); } string description = inputArgs.Length == 3 ? inputArgs[2] : null; TeamService.AddTeam(teamName, acronym, description); return($"Team {teamName} successfully created!"); }
public async Task AddTeam([FromBody] Team team) { _teamService.AddTeam(team); }
private static string ProcessText(string pdfText, DateTime?raceDate, SACServiceContext db) { string[] lines = pdfText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int currentAgeRankId = -1; using (RaceService raceService = new RaceService(db)) using (AgeRankService ageRankService = new AgeRankService(db)) using (TeamService teamService = new TeamService(db)) using (AthleteService athleteService = new AthleteService(db)) using (RaceResultService raceResultService = new RaceResultService(db)) { int raceId = -1; for (int i = 0; i < lines.Length; i++) { if (i < 2) { continue; } if (string.IsNullOrEmpty(lines[i])) { continue; } if (i == 2) { if ((raceId = raceService.RaceExists(lines[i])) != -1) { return("A Race with this name already exists!"); } raceId = raceService.AddRace(lines[i], raceDate).Id; continue; } if (lines[i].StartsWith("Class.")) { string currentAgeRank = lines[i - 1]; if (currentAgeRank.ToLower().Contains("(cont.)")) { continue; } if ((currentAgeRankId = ageRankService.AgeRankExists(currentAgeRank)) == -1) { currentAgeRankId = ageRankService.AddAgeRank(SAC.Models.AgeRankMappings.GetAgeRankNameByCode(currentAgeRank)).Id; } continue; } string[] result = lines[i].Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries); if (result.Length < 5) { continue; } int test; int position; int bibNumber; string athleteName; string teamName; int points; if (int.TryParse(result[1].Trim(), out test)) { position = Convert.ToInt16(result[0].Replace("º", "").Trim()); bibNumber = Convert.ToInt16(result[1].Trim()); athleteName = result[2]; teamName = result[3]; points = 0; Int32.TryParse(result[4].Trim(), out points); } else { position = Convert.ToInt16(result[0].Replace("º", "").Trim()); bibNumber = Convert.ToInt16(result[2].Trim()); athleteName = result[1]; teamName = result[3]; points = 0; Int32.TryParse(result[4].Trim(), out points); } int athleteId; if ((athleteId = athleteService.AthleteExists(bibNumber)) == -1) { int teamId; if ((teamId = teamService.TeamExists(teamName)) == -1) { teamId = teamService.AddTeam(teamName).Id; } athleteId = athleteService.AddAthlete(athleteName, bibNumber, currentAgeRankId, teamId).Id; } else { Athlete athlete = athleteService.GetAthlete(athleteId); if (athlete.AgeRankId != currentAgeRankId) { athleteService.UpdateAthlete(athleteId, currentAgeRankId); } } if (raceId != -1) { raceResultService.AddRaceResult(position, points, athleteId, currentAgeRankId, raceId); } } } return(string.Empty); }
public void AddTeam(string name) { teamService.AddTeam(new Team(name)); }