Пример #1
0
        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."));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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."));
        }
Пример #4
0
        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());
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        public void FindTeam_WithNonExistingId_ShouldReturnNull()
        {
            TeamAddBindingModel teamModel = this.teamService.Find <TeamAddBindingModel>(-1);

            Assert.IsNull(teamModel);
        }