Ejemplo n.º 1
0
        public virtual async Task SetUserTournamentPropertyValueAsync(User user, UserProperty property, Tournament tournament, String value)
        {
            var repository = unitOfWork.GetRepository<UserTournamentPropertyValue>();
            if (user != null && property != null && tournament != null)
            {
                var userTournamentPropertyValue = repository.GetById(user.Id, property.Id, tournament.Id);
                if (userTournamentPropertyValue == null)
                {
                    userTournamentPropertyValue = new UserTournamentPropertyValue
                    {
                        User = user,
                        Tournament = tournament,
                        UserProperty = property,
                        Value = value
                    };
                    repository.Insert(userTournamentPropertyValue);
                }
                else
                {
                    userTournamentPropertyValue.Value = value;
                    repository.Update(userTournamentPropertyValue);
                }
                await unitOfWork.SaveAsync();
            }

        }
Ejemplo n.º 2
0
 public ActionResult DisplayPartial(Guid tournamentId) {
     var tournament = unitOfWork.GetRepository<Tournament>().GetById(tournamentId);
     if (tournament == null) {
         tournament = new Tournament();
     }
     return PartialView(tournament);
 }
        public void AddSpeakerAsync_WithValidTeamIdAndValidSpeakerId_ShouldAddSpeaker()
        {
            // Arrange

            var tournament = new Tournament
            {
                Id = Guid.NewGuid(),
                TeamSize = 2
            };

            unitOfWork.GetRepository<Tournament>().Insert(tournament);
            unitOfWork.Save();

            Organization organization = new Organization
            {
                Id = Guid.NewGuid()
            };

            unitOfWork.GetRepository<Organization>().Insert(organization);
            unitOfWork.Save();

            var teamId = Guid.NewGuid();


            Team team = new Team
            {
                Id = teamId,
                Tournament = tournament,
                TournamentId = tournament.Id,
                Organization = organization,
                OrganizationId = organization.Id
            };

            unitOfWork.GetRepository<Team>().Insert(team);
            unitOfWork.Save();

            String speakerId = Guid.NewGuid().ToString();
            User speaker = new User { Id = speakerId };
            var userTask = userManager.CreateAsync(speaker);
            if (!userTask.IsCompleted) { userTask.Wait(); }

            User user = new User();

            // Act

            var task = tournamentRegistrationsManager.AddSpeakerAsync(teamId, speakerId, user);
            if (!task.IsCompleted)
            {
                task.Wait();
            }
            var result = task.Result;

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TeamUpdated, result);
            team = tournamentRegistrationsManager.GetTeam(teamId);
            speaker = team.Speaker.FirstOrDefault(sp => sp.Id == speakerId);
            Assert.IsNotNull(speaker);

        }
        public void SetTeam_WithMaximumTeamsExceeded_ShouldReturnTooManyTeams()
        {
            #region Arrange
            // Arrange

            Guid tournamentId;
            Tournament tournament;

            {
                #region Create tournament

                // Create tournament
                tournamentId = Guid.NewGuid();
                tournament = new Tournament
                {
                    Id = tournamentId,
                    TeamSize = 2
                };

                #endregion
            }

            Guid organizationId = Guid.NewGuid();
            TournamentOrganizationRegistration registration;
            {
                #region Create registration

                // Create registration

                registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                    TeamsWanted = 2,
                    TeamsGranted = 2,
                    TeamsPaid = 2,
                };

                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();

                #endregion

            }

            Team team;

            {
                #region Create maximum number of teams

                // Create maximum number of teams

                for (int i = 0; i < registration.TeamsPaid; i++)
                {
                    team = new Team
                    {
                        Id = Guid.NewGuid(),
                        TournamentId = tournamentId,
                        Tournament = tournament,
                        OrganizationId = organizationId
                    };

                    for (int s = 0; s < tournament.TeamSize; s++)
                    {
                        var speaker = new User
                        {
                            Id = Guid.NewGuid().ToString()
                        };
                        var task = userManager.CreateAsync(speaker);
                        if (!task.IsCompleted) { task.Wait(); }
                        team.Speaker.Add(speaker);
                    }

                    unitOfWork.GetRepository<Team>().Insert(team);
                    unitOfWork.Save();
                }

                #endregion
            }

            {
                #region Create new team

                // Create new Team

                team = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                };

                #endregion
            }
            User user = new User();

            #endregion

            // Act

            var result = tournamentRegistrationsManager.SetTeam(team, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TooManyTeams, result);

        }
        public void SetTeam_WithSpeakerInOutherTeam_ShouldReturnSpeakerAlreadyInOtherTeam()
        {
            #region Arrange
            // Arrange

            Guid tournamentId;
            Tournament tournament;

            {
                #region Create tournament

                // Create tournament
                tournamentId = Guid.NewGuid();
                tournament = new Tournament
                {
                    Id = tournamentId,
                    TeamSize = 2
                };

                #endregion
            }

            Guid organizationId = Guid.NewGuid();
            TournamentOrganizationRegistration registration;
            {
                #region Create registration

                // Create registration

                registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                    TeamsWanted = 2,
                    TeamsGranted = 2,
                    TeamsPaid = 2,
                };

                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();

                #endregion

            }

            Team team;
            {
                #region Create original team

                // Create original team

                team = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId
                };

                for (int i = 0; i < tournament.TeamSize; i++)
                {
                    var speaker = new User
                    {
                        Id = Guid.NewGuid().ToString()
                    };
                    var task = userManager.CreateAsync(speaker);
                    if (!task.IsCompleted) { task.Wait(); }
                    team.Speaker.Add(speaker);
                }

                unitOfWork.GetRepository<Team>().Insert(team);
                unitOfWork.Save();

                #endregion
            }

            Team newTeam;
            {
                #region Create new team

                // Create new Team

                newTeam = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = team.TournamentId,
                    Tournament = tournament,
                    OrganizationId = team.OrganizationId,
                };

                // Add new speaker as first speaker

                User newSpeaker = new User { Id = Guid.NewGuid().ToString() };
                var task = userManager.CreateAsync(newSpeaker);
                if (!task.IsCompleted) { task.Wait(); }
                newTeam.Speaker.Add(newSpeaker);

                // Add speaker of another team as second speaker

                newTeam.Speaker.Add(team.Speaker.First());

                #endregion
            }
            User user = new User();

            #endregion

            // Act

            var result = tournamentRegistrationsManager.SetTeam(newTeam, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.SpeakerAlreadyInOtherTeam, result);

        }
Ejemplo n.º 6
0
 private Tournament CreateTournament()
 {
     Tournament tournament = new Tournament
     {
         Id = Guid.NewGuid(),
         HostingOrganization = organization,
         HostingOrganizationID = organization.Id
     };
     return tournament;
 }
Ejemplo n.º 7
0
        public void UpdateTournament(Tournament tournament, User user)
        {
            var savedTournament = GetTournament(tournament.Id);

            if (savedTournament == null)
            {
                throw new ArgumentException(TournamentNotFoundMessage, "tournament.Id");
            }

            // Check if user is authorized
            if (!userManager.HasOrganizationRole(user.Id, savedTournament.HostingOrganizationID, OrganizationRole.OrganizationTournamentManager))
            {
                throw new UnauthorizedAccessException(UserNotAuthorizedMessage);
            }

            tournament.HostingOrganization = savedTournament.HostingOrganization;

            unitOfWork.Detach(savedTournament);

            // tournament.CopyProperties(savedTournament);

            tournament.UpdateTrackingData(user);
            unitOfWork.GetRepository<Tournament>().Update(tournament);
            unitOfWork.Save();
        }
        public void SetTeam_WithExistingTeam_ShouldUpdateTeam()
        {
            #region Arrange
            // Arrange

            Guid tournamentId;
            Tournament tournament;

            {
                #region Create tournament

                // Create tournament
                tournamentId = Guid.NewGuid();
                tournament = new Tournament
                {
                    Id = tournamentId,
                    TeamSize = 2
                };

                #endregion
            }

            Guid organizationId = Guid.NewGuid();
            TournamentOrganizationRegistration registration;
            {
                #region Create registration

                // Create registration

                registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                    TeamsWanted = 2,
                    TeamsGranted = 2,
                    TeamsPaid = 2,
                };

                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();

                #endregion

            }

            Team team;
            {
                #region Create original team

                // Create original team

                team = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId
                };

                for (int i = 0; i < tournament.TeamSize; i++)
                {
                    var speaker = new User
                    {
                        Id = Guid.NewGuid().ToString()
                    };
                    var task = userManager.CreateAsync(speaker);
                    if (!task.IsCompleted) { task.Wait(); }
                    team.Speaker.Add(speaker);
                }

                unitOfWork.GetRepository<Team>().Insert(team);
                unitOfWork.Save();

                #endregion
            }

            Team updatedTeam;
            {
                #region Create updated team

                // Create updated Team

                updatedTeam = new Team
                {
                    Id = team.Id,
                    TournamentId = team.TournamentId,
                    Tournament = tournament,
                    OrganizationId = team.OrganizationId,
                };

                foreach (var speaker in team.Speaker)
                {
                    updatedTeam.Speaker.Add(speaker);
                }

                {
                    #region Replace first speaker

                    // Replace first speaker

                    User newSpeaker = new User
                    {
                        Id = Guid.NewGuid().ToString()
                    };
                    var task = userManager.CreateAsync(newSpeaker);
                    if (!task.IsCompleted) { task.Wait(); }

                    updatedTeam.Speaker[0] = newSpeaker;

                    #endregion
                }

                #endregion
            }
            User user = new User();

            #endregion

            // Act

            var result = tournamentRegistrationsManager.SetTeam(updatedTeam, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TeamUpdated, result);
            var teamId = team.Id;
            team = null;
            team = tournamentRegistrationsManager.GetTeam(teamId);
            Assert.AreEqual(updatedTeam.Speaker[0].Id, team.Speaker[0].Id);


        }
        public void AddSpeakerAsync_WithUserAlreadyInOtherTeam_ShouldReturnUserAlreadyInOtherTeam()
        {
            // Arrange
            String speakerId = Guid.NewGuid().ToString();
            User speaker = new User { Id = speakerId };
            var userTask = userManager.CreateAsync(speaker);
            if (!userTask.IsCompleted) { userTask.Wait(); }

            var tournament = new Tournament
            {
                TeamSize = 2
            };
            var teamId = Guid.NewGuid();

            Team team = new Team
            {
                Id = Guid.NewGuid(),
                Tournament = tournament
            };

            team.Speaker.Add(speaker);
            unitOfWork.GetRepository<Team>().Insert(team);
            unitOfWork.Save();

            team = new Team
            {
                Id = teamId,
                Tournament = tournament
            };

            unitOfWork.GetRepository<Team>().Insert(team);
            unitOfWork.Save();


            User user = new User();

            // Act

            var task = tournamentRegistrationsManager.AddSpeakerAsync(teamId, speakerId, user);
            if (!task.IsCompleted)
            {
                task.Wait();
            }
            var result = task.Result;

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.SpeakerAlreadyInOtherTeam, result);

        }
Ejemplo n.º 10
0
        public void AddTournament_WrongHostingOrganization_ShouldThrowUnauthorizedAccess()
        {
            // Arrange
            var user = CreateUserWithOrganizationRole(organization, OrganizationRole.OrganizationTournamentManager);
            var tournament = new Tournament
            {
                Id = Guid.NewGuid(),
                HostingOrganization = new Organization { Id = Guid.NewGuid() }
            };

            tournament.HostingOrganizationID = tournament.HostingOrganization.Id;

            // Act

            #region ACT

            Task task = tournamentManager.AddTournamentAsync(tournament, user);
            if (!task.IsCompleted)
            {
                task.Wait();
            }
            #endregion

            // Assert 

            #region ASSERT

            Assert.AreEqual(TaskStatus.Faulted, task.Status);
            var exception = task.Exception.InnerException;
            Assert.IsInstanceOfType(exception, typeof(UnauthorizedAccessException));
            Assert.AreEqual(TournamentManager.UserNotAuthorizedMessage, exception.Message);
            #endregion
        }
        private bool IsOpenForRegistration(Tournament tournament)
        {
            if (tournament != null)
            {
                return tournament.RegistrationStart < DateTime.UtcNow
                    && tournament.RegistrationEnd > DateTime.UtcNow
                    && tournament.Start > DateTime.UtcNow;

            }
            return false;
        }
Ejemplo n.º 12
0
        public void Init()
        {
            // Create user for finance and tournament management

            DebRegDataMocks dataMocks = new DebRegDataMocks();
            DebRegUserManager userManager = dataMocks.UserManager;
            {
                var task = userManager.CreateAsync(financeManagerUser);
                if (!task.IsCompleted)
                {
                    task.Wait();
                }
            }

            // Create hosting organization

            SecurityMocks securityMocks = new SecurityMocks();
            IAuthenticationManager authManager = securityMocks.AuthManager;
            ISecurityManager securityManager = new SecurityManager(userManager, authManager);

            IUnitOfWork unitOfWork = dataMocks.UnitOfWork;
            IOrganizationManager organizationManager = new OrganizationManager(unitOfWork, userManager);
            {
                var task = organizationManager.CreateOrganizationAsync(hostingOrganization, financeManagerUser);
                if (!task.IsCompleted)
                {
                    task.Wait();
                }
            }

            // Make user tournament manager

            OrganizationUser organizationUser = new OrganizationUser
            {
                Organization = hostingOrganization,
                OrganizationId = hostingOrganization.Id,
                User = financeManagerUser,
                UserId = financeManagerUser.Id,
                Role = OrganizationRole.OrganizationTournamentManager
            };
            financeManagerUser.OrganizationAssociations.Add(organizationUser);
            hostingOrganization.UserAssociations.Add(organizationUser);
            financeManagerUser.OrganizationAssociations.Add(organizationUser);
            unitOfWork.GetRepository<OrganizationUser>().Insert(organizationUser);
            unitOfWork.Save();

            // Create tournament

            ITournamentManager tournamentManager = new TournamentManager(unitOfWork, userManager);

            tournament = new Tournament
            {
                Id = Guid.NewGuid(),
                HostingOrganization = hostingOrganization,
                HostingOrganizationID = hostingOrganization.Id
            };
            {
                var task = tournamentManager.AddTournamentAsync(tournament, financeManagerUser);
                if (!task.IsCompleted)
                {
                    task.Wait();
                }
            }

            // Create Controller

            DebRegCommunicationMocks communicationMocks = new DebRegCommunicationMocks();
            IEMailService mailService = communicationMocks.EMailService;

            registrationManager = new TournamentRegistrationsManager(unitOfWork, mailService, userManager);
            IBookingManager bookingManager = new BookingManager(unitOfWork);
            IPaymentManager paymentManager = new PaymentManager(registrationManager, bookingManager, mailService);

            financeController = new FinanceController(tournamentManager, registrationManager, paymentManager, bookingManager, userManager);

            // Set controller context
            httpMocks.UserId = financeManagerUser.Id;
            httpMocks.UserName = financeManagerUser.UserName;

            financeController.ControllerContext = httpMocks.ControllerContext;
        }
Ejemplo n.º 13
0
        public async Task AddTournamentAsync(Tournament tournament, User user)
        {
            // Check if user is authorized
            if (!userManager.HasOrganizationRole(user.Id, tournament.HostingOrganizationID, OrganizationRole.OrganizationTournamentManager))
            {
                throw new UnauthorizedAccessException(UserNotAuthorizedMessage);
            }

            tournament.UpdateTrackingData(user);


            unitOfWork.GetRepository<Tournament>().Insert(tournament);
            unitOfWork.Save();

            // Give user all management roles

            await AssignTournamentUserRoleAsync(tournament, user, TournamentRole.OrganizationApprover);
            await AssignTournamentUserRoleAsync(tournament, user, TournamentRole.SlotManager);
            await AssignTournamentUserRoleAsync(tournament, user, TournamentRole.FinanceManager);

            // make tournament the current tournament for user

            user.CurrentTournament = tournament; user.CurrentTournamentId = tournament.Id;
            await userManager.UpdateAsync(user);

            // TODO: Redesign layout, so we don't use claims anymore and the switch goes smoothly
        }
Ejemplo n.º 14
0
        private async Task AssignTournamentUserRoleAsync(Tournament tournament, User user, TournamentRole role)
        {
            TournamentUserRole tournamentUserRole = new TournamentUserRole
            {
                Tournament = tournament,
                TournamentId = tournament.Id,
                User = user,
                UserId = user.Id,
                Role = TournamentRole.FinanceManager
            };

            var repository = unitOfWork.GetRepository<TournamentUserRole>();

            repository.Insert(tournamentUserRole);
            await unitOfWork.SaveAsync();
        }
        public void AddSpeakerAsync_ExceedingTeamSize_ShouldReturnTooManySpeakers()
        {
            // Arrange
            var tournament = new Tournament
            {
                TeamSize = 2
            };
            var teamId = Guid.NewGuid();

            Team team = new Team
            {
                Id = teamId,
                Tournament = tournament
            };

            for (int i = 0; i < 2; i++)
            {
                team.Speaker.Add(new User());
            }

            unitOfWork.GetRepository<Team>().Insert(team);
            unitOfWork.Save();

            String speakerId = Guid.NewGuid().ToString();
            User speaker = new User { Id = speakerId };
            var userTask = userManager.CreateAsync(speaker);
            if (!userTask.IsCompleted) { userTask.Wait(); }

            User user = new User();

            // Act

            var task = tournamentRegistrationsManager.AddSpeakerAsync(teamId, speakerId, user);
            if (!task.IsCompleted)
            {
                task.Wait();
            }
            var result = task.Result;

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TooManySpeakers, result);

        }
Ejemplo n.º 16
0
        public void UpdateTournament_WithValidUser_ShouldUpdateTournament()
        {
            // Arrange
            #region ARRANGE

            #region CREATE ORIGINAL TOURNAMENT

            var tournament = CreateTournament();

            unitOfWork.GetRepository<Tournament>().Insert(tournament);
            unitOfWork.Save();
            #endregion

            #region CREATE UPDATED TOURNAMENT

            string tournamentName = "test tournament";
            string tournamentLocation = "test location";
            DateTime tournamentStart = DateTime.Today.AddDays(30);
            DateTime tournamentEnd = tournamentStart.AddDays(2);
            DateTime tournamentRegistrationStart = tournamentStart.AddDays(-30);
            DateTime tournamentRegistrationEnd = tournamentRegistrationStart.AddDays(7);
            int? tournamentAdjudicatorSubtract = 2;
            int tournamentTeamSize = 2;
            int tournamentTeamCap = 48;
            int tournamentAdjudicatorCap = 48;
            Product teamProduct = new Product
            {
                Id = Guid.NewGuid()
            };
            Product adjudicatorProduct = new Product
            {
                Id = Guid.NewGuid()
            };
            bool tournamentUniversityRequired = false;
            Currency tournamentCurrency = new Currency
            {
                Id = Guid.NewGuid()
            };
            string tournamentFinanceEmail = "*****@*****.**";
            string tournamentTC = "Terms & Conditions";
            string tournamentTCLink = "http://tournamnet.org/tc.html";
            string tournamentMoneyTransferLinkCaption = "Money transfer";
            string tournamentMondeyTransferLink = "http://moneytransfer.com";
            string tournamentPaymentReference = "Payment reference";
            BankAccount bankAccount = new BankAccount
            {
                Id = Guid.NewGuid()
            };

            tournament = new Tournament
            {
                Id = tournament.Id,
                HostingOrganization = organization,
                Name = tournamentName,
                Location = tournamentLocation,
                Start = tournamentStart,
                End = tournamentEnd,
                RegistrationStart = tournamentRegistrationStart,
                RegistrationEnd = tournamentRegistrationEnd,
                AdjucatorSubtract = tournamentAdjudicatorSubtract,
                TeamSize = tournamentTeamSize,
                TeamCap = tournamentTeamCap,
                AdjudicatorCap = tournamentAdjudicatorCap,
                TeamProduct = teamProduct,
                AdjudicatorProduct = adjudicatorProduct,
                UniversityRequired = tournamentUniversityRequired,
                Currency = tournamentCurrency,
                FinanceEMail = tournamentFinanceEmail,
                TermsConditions = tournamentTC,
                TermsConditionsLink = tournamentTCLink,
                MoneyTransferLinkCaption = tournamentMoneyTransferLinkCaption,
                MoneyTransferLink = tournamentMondeyTransferLink,
                PaymentReference = tournamentPaymentReference,
                BankAccount = bankAccount
            };
            #endregion

            var user = CreateUserWithOrganizationRole(organization, OrganizationRole.OrganizationTournamentManager);

            #endregion

            // Act

            tournamentManager.UpdateTournament(tournament, user);

            // Assert

            #region ASSERT

            var savedTournament = unitOfWork.GetRepository<Tournament>().GetById(tournament.Id);
            //Assert.AreNotEqual(tournament, savedTournament);
            Assert.AreEqual(tournament.Id, savedTournament.Id);
            Assert.AreEqual(tournament.HostingOrganization, savedTournament.HostingOrganization);
            Assert.AreEqual(tournament.Name, savedTournament.Name);
            Assert.AreEqual(tournament.Location, savedTournament.Location);
            Assert.AreEqual(tournament.Start, savedTournament.Start);
            Assert.AreEqual(tournament.End, savedTournament.End);
            Assert.AreEqual(tournament.RegistrationStart, savedTournament.RegistrationStart);
            Assert.AreEqual(tournament.RegistrationEnd, savedTournament.RegistrationEnd);
            Assert.AreEqual(tournament.AdjucatorSubtract, savedTournament.AdjucatorSubtract);
            Assert.AreEqual(tournament.TeamSize, savedTournament.TeamSize);
            Assert.AreEqual(tournament.TeamCap, savedTournament.TeamCap);
            Assert.AreEqual(tournament.AdjudicatorCap, savedTournament.AdjudicatorCap);
            Assert.AreEqual(tournament.TeamProduct, savedTournament.TeamProduct);
            Assert.AreEqual(tournament.AdjudicatorProduct, savedTournament.AdjudicatorProduct);
            Assert.AreEqual(tournament.UniversityRequired, savedTournament.UniversityRequired);
            Assert.AreEqual(tournament.Currency, savedTournament.Currency);
            Assert.AreEqual(tournament.FinanceEMail, savedTournament.FinanceEMail);
            Assert.AreEqual(tournament.TermsConditions, savedTournament.TermsConditions);
            Assert.AreEqual(tournament.TermsConditionsLink, savedTournament.TermsConditionsLink);
            Assert.AreEqual(tournament.MoneyTransferLinkCaption, savedTournament.MoneyTransferLinkCaption);
            Assert.AreEqual(tournament.MoneyTransferLink, savedTournament.MoneyTransferLink);
            Assert.AreEqual(tournament.PaymentReference, savedTournament.PaymentReference);
            Assert.AreEqual(tournament.BankAccount, savedTournament.BankAccount);

            Assert.AreEqual(savedTournament.ModifiedBy, user);
            Assert.IsNotNull(savedTournament.Modified);

            #endregion
        }
        public void AddSpeakerAsync_WithInvalidUserId_ShouldReturnUserNotFound()
        {
            // Arrange
            String speakerId = Guid.NewGuid().ToString();

            var tournament = new Tournament
            {
                TeamSize = 2
            };
            var teamId = Guid.NewGuid();

            Team team = new Team
            {
                Id = teamId,
                Tournament = tournament
            };

            unitOfWork.GetRepository<Team>().Insert(team);
            unitOfWork.Save();


            User user = new User();

            // Act

            var task = tournamentRegistrationsManager.AddSpeakerAsync(teamId, speakerId, user);
            if (!task.IsCompleted)
            {
                task.Wait();
            }
            var result = task.Result;

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.UserNotFound, result);

        }
Ejemplo n.º 18
0
        public void UpdateTournament_UserDelegate_ShouldThrowUnauthorizedAccess()
        {
            // arrange
            #region ARRANGE
            var tournament = CreateTournament();
            unitOfWork.GetRepository<Tournament>().Insert(tournament);
            unitOfWork.Save();

            var user = CreateUserWithOrganizationRole(organization, OrganizationRole.Delegate);

            tournament = new Tournament
            {
                Id = tournament.Id
            };

            #endregion

            // act
            #region ACT
            try
            {
                tournamentManager.UpdateTournament(tournament, user);
            }
            #endregion

            // assert
            #region ASSERT
            catch (UnauthorizedAccessException e)
            {
                StringAssert.Contains(e.Message, TournamentManager.UserNotAuthorizedMessage);
                return;
            }
            Assert.Fail("No exception was thrown.");
            #endregion


        }
        public void SetTeam_WithNewTeam_ShouldCreateNewTeam()
        {
            #region Arrange
            // Arrange

            Guid tournamentId = Guid.NewGuid();
            Tournament tournament = new Tournament
            {
                Id = tournamentId,
                TeamSize = 2
            };

            Guid organizationId = Guid.NewGuid();

            TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration
            {
                TournamentId = tournamentId,
                Tournament = tournament,
                OrganizationId = organizationId,
                TeamsWanted = 2,
                TeamsGranted = 2,
                TeamsPaid = 2,
            };

            unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
            unitOfWork.Save();

            Team team = new Team
            {
                Id = Guid.NewGuid(),
                TournamentId = tournamentId,
                Tournament = tournament,
                OrganizationId = organizationId
            };

            for (int i = 0; i < tournament.TeamSize; i++)
            {
                var speaker = new User
                {
                    Id = Guid.NewGuid().ToString()
                };
                var task = userManager.CreateAsync(speaker);
                if (!task.IsCompleted) { task.Wait(); }
                team.Speaker.Add(speaker);
            }

            User user = new User();

            #endregion
            // Act

            var result = tournamentRegistrationsManager.SetTeam(team, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TeamAdded, result);
            var teamId = team.Id;
            team = null;
            team = tournamentRegistrationsManager.GetTeam(teamId);
            Assert.AreEqual(teamId, team.Id);

        }
Ejemplo n.º 20
0
        public void DeleteTournament_WrongHostingOrganization_ShouldThrowUnauthorizedAccess()
        {
            // Arrange
            Tournament tournament = new Tournament
            {
                Id = Guid.NewGuid(),
                HostingOrganization = new Organization { Id = Guid.NewGuid() }
            };
            tournament.HostingOrganizationID = tournament.HostingOrganization.Id;
            unitOfWork.GetRepository<Tournament>().Insert(tournament);
            unitOfWork.Save();

            var user = CreateUserWithOrganizationRole(organization, OrganizationRole.OrganizationTournamentManager);

            try
            {
                // Act
                tournamentManager.DeleteTournament(tournament.Id, user);
            }
            catch (UnauthorizedAccessException e)
            {
                // Assert
                StringAssert.Equals(e.Message, TournamentManager.UserNotAuthorizedMessage);
                return;
            }
            Assert.Fail("No exception thrown.");
        }
Ejemplo n.º 21
0
        public void Init()
        {
            // Create mocks
            DebRegDataMocks dataMocks = new DebRegDataMocks();
            DebRegCommunicationMocks communicationMocks = new DebRegCommunicationMocks();
            userManager = dataMocks.UserManager;

            unitOfWork = dataMocks.UnitOfWork;
            // Create Managers
            slotAssignmentManager = new SlotAssignmentManager(unitOfWork);
            tournamentManager = new TournamentManager(unitOfWork, userManager);
            tournamentRegistrationsManager = new TournamentRegistrationsManager(unitOfWork, communicationMocks.EMailService, userManager);
            bookingManager = new BookingManager(unitOfWork);

            slotManager = new SlotManager(slotAssignmentManager, tournamentRegistrationsManager, tournamentManager, bookingManager, communicationMocks.EMailService, userManager);

            // Create basic objects

            Organization hostingOrganization = new Organization { Id = Guid.NewGuid() };
            Random rand = new Random();

            User user = CreateUserWithOrganizationRole(hostingOrganization, OrganizationRole.OrganizationTournamentManager);

            // Create tournament

            tournament = new Tournament
            {
                Id = Guid.NewGuid(),
                HostingOrganization = hostingOrganization,
                HostingOrganizationID = hostingOrganization.Id,
                TeamProduct = new Product
                {
                    Id = Guid.NewGuid(),
                    Price = 40
                },
                AdjudicatorProduct = new Product
                {
                    Id = Guid.NewGuid(),
                    Price = 20
                }
            };
            {
                var task = tournamentManager.AddTournamentAsync(tournament, user);
                if (!task.IsCompleted)
                {
                    task.Wait();
                }
            }

            // Create registrations
            Guid[] organizationIds = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };

            for (int i = 0; i < organizationIds.Length; i++)
            {
                int teamsWanted = i + 1;
                int adjudicatorsWanted = i;
                var registration = tournamentRegistrationsManager.AddRegistration(
                    tournament.Id,
                    organizationIds[i],
                    organizationIds[i],
                    teamsWanted,
                    adjudicatorsWanted,
                    null,
                    user
                );

                registration.OrganizationStatus = OrganizationStatus.Approved;
                registration.OrganizationStatusDraft = false;
            }

        }
Ejemplo n.º 22
0
 private IEnumerable<SlotAssignmentViewModel> GetSlotAssignmentChanges(Tournament tournament, User user)
 {
     return GetSlotAssignmentViewModels(tournament.Id, user).Where(
     a => a.Assignment.TeamsGranted != a.Registration.TeamsGranted
         || a.Assignment.AdjucatorsGranted != a.Registration.AdjudicatorsGranted);
 }