public void AddTeam_WithIvalidData_ShouldThrowException() { TeamAddBindingModel expectedTeam = new TeamAddBindingModel { Name = Utilities.GenerateRandomString(0), Acronym = Utilities.GenerateRandomString(AcronymLength), Description = Utilities.GenerateRandomString(DescriptionLength) }; string userId = Utilities.GenerateRandomString(UserIdLength); ValidationException exception = Assert.Throws <ValidationException>( () => { this.teamService.Add(expectedTeam, userId); }); Assert.That(exception.Message, Is.EqualTo("Team not valid.")); }
public ActionResult Create([Bind(Include = "Name,Description,Acronym,Image")] TeamAddBindingModel teamBindingModel) { if (ModelState.IsValid) { if (this.teamService.IsTeamNameTaken(teamBindingModel.Name)) { ModelState.AddModelError("Name", "Team with same name already exists!"); return(this.View(teamBindingModel)); } string userId = this.User.Identity.GetUserId(); Team team = this.teamService.Add(teamBindingModel, userId); this.teamService.AddUserToTeam(userId, team.Id); return(this.RedirectToAction("Details", new { teamName = team.Name })); } return(this.View(teamBindingModel)); }
public void AddTeam_WithTakenName_ShouldThrowException() { Team firstTeam = this.AddTeam(); Team secondTeam = new Team { Acronym = Utilities.GenerateRandomString(AcronymLength), Description = Utilities.GenerateRandomString(DescriptionLength) }; TeamAddBindingModel teamToAdd = Mapper.Instance.Map <TeamAddBindingModel>(secondTeam); teamToAdd.Name = firstTeam.Name; InvalidOperationException ioe = Assert.Throws <InvalidOperationException>( () => { this.teamService.Add(teamToAdd, Utilities.GenerateRandomString(UserIdLength)); }); Assert.That(ioe.Message, Is.EqualTo("Team with same name already exists.")); }
public void AddTeam_WithProperData_ShouldAddTeam() { TeamAddBindingModel expectedTeam = new TeamAddBindingModel { Name = Utilities.GenerateRandomString(NameLength), Acronym = Utilities.GenerateRandomString(AcronymLength), Description = Utilities.GenerateRandomString(DescriptionLength) }; string userId = Utilities.GenerateRandomString(UserIdLength); Team actualTeam = this.teamService.Add(expectedTeam, userId); Assert.IsNotNull(actualTeam); Assert.AreEqual(expectedTeam.Name, actualTeam.Name); Assert.AreEqual(expectedTeam.Acronym, actualTeam.Acronym); Assert.AreEqual(expectedTeam.Description, actualTeam.Description); Assert.AreEqual(userId, actualTeam.CreatorId); Assert.IsNull(actualTeam.ImageFileName); Assert.AreEqual(1, this.repository.GetAll(t => t.Name == actualTeam.Name).Count()); }
public void FindTeam_ByName_OnAlreadyExistingTeam_ShouldReturnTeam() { string userId = Utilities.GenerateRandomString(UserIdLength); Team expectedTeam = new Team { Id = Utilities.GenerateUniqueRandomInteger(), Name = Utilities.GenerateRandomString(NameLength), Acronym = Utilities.GenerateRandomString(AcronymLength), Description = Utilities.GenerateRandomString(DescriptionLength), CreatorId = userId }; this.repository.Add(expectedTeam); TeamAddBindingModel actualTeam = this.teamService.Find <TeamAddBindingModel>(expectedTeam.Id); Assert.IsNotNull(actualTeam); Assert.AreEqual(expectedTeam.Name, actualTeam.Name); Assert.AreEqual(expectedTeam.Acronym, actualTeam.Acronym); Assert.AreEqual(expectedTeam.Description, actualTeam.Description); Assert.IsNull(actualTeam.Image); }
public Team Add(TeamAddBindingModel teamBindingModel, string creatorId) { Team team = Mapper.Instance.Map <Team>(teamBindingModel); team.CreatorId = creatorId; if (teamBindingModel.Image != null) { team.ImageFileName = this.fileService.Upload(teamBindingModel.Image.InputStream); } if (this.IsTeamNameTaken(team.Name)) { throw new InvalidOperationException(string.Format(ServicesConstants.EntityAlreadyExists, "Team", "name")); } if (!this.teamRepository.IsEntityValid(team)) { throw new ValidationException(string.Format(ServicesConstants.EntityNotValid, "Team")); } this.teamRepository.Add(team); return(team); }
public void FindTeam_WithNonExistingId_ShouldReturnNull() { TeamAddBindingModel teamModel = this.teamService.Find <TeamAddBindingModel>(-1); Assert.IsNull(teamModel); }