Ejemplo n.º 1
0
 private BookingRecord CreateBookingRecord(
             DateTime date,
             Guid organizationId,
             Guid tournamentId,
             Product product,
             Decimal quantity,
             Decimal value,
             Boolean credit,
             User user)
 {
     BookingRecord record = CreateBookingRecord(
         date,
         organizationId,
         tournamentId,
         value,
         credit,
         null,
         user
     );
     record.Product = product;
     record.ProductId = product.Id;
     record.ProductName = product.Name;
     record.Price = product.Price;
     record.VatRate = product.VatRate;
     record.Quantity = quantity;
     return record;
 }
Ejemplo n.º 2
0
        public async Task DeleteOrganizationAsync(Guid organizationId, User user)
        {
            // Check permissions

            if (!userManager.HasOrganizationRole(user.Id, organizationId, OrganizationRole.Delegate))
            {
                throw new UnauthorizedAccessException(UserNotAuthorizedMessage);
            }

            // Set deleted flags


            var organization = GetOrganization(organizationId);
            foreach (var linkedOrganization in organization.LinkedOrganizations)
            {
                linkedOrganization.LinkedOrganization = null;
                linkedOrganization.Deleted = true;
                linkedOrganization.UpdateTrackingData(user);
                await unitOfWork.SaveAsync();
            }

            organization.LinkedOrganization = null;
            organization.Deleted = true;
            organization.UpdateTrackingData(user);
            await unitOfWork.SaveAsync();

        }
        public TournamentOrganizationRegistration AddRegistration(Guid tournamentId, Guid organizationId, Guid billedOrganizationId, int teamsWanted, int adjudicatorsWanted, String notes, User user)
        {
            if (tournamentId != Guid.Empty
                && organizationId != Guid.Empty
                && billedOrganizationId != Guid.Empty
                && (teamsWanted > 0 || adjudicatorsWanted > 0))
            {

                TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    OrganizationId = organizationId,
                    BilledOrganizationId = billedOrganizationId,
                    TeamsWanted = teamsWanted,
                    AdjudicatorsWanted = adjudicatorsWanted,
                    TeamsGranted = 0,
                    TeamsPaid = 0,
                    AdjudicatorsGranted = 0,
                    AdjudicatorsPaid = 0,
                    LockAutoAssign = false,
                    OrganizationStatusDraft = true,
                    Notes = notes
                };
                registration.UpdateTrackingData(user);
                SetBookingCode(registration);
                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();
                return registration;
            }
            return null;
        }
Ejemplo n.º 4
0
        public DebReg.Models.BookingRecord AddBooking(
            DateTime date,
            Guid organizationId,
            Guid tournamentId,
            Product product,
            Decimal quantity,
            Boolean credit,
            DateTime? paymentsDueDate,
            User user)
        {

            Decimal value = quantity * product.Price;

            BookingRecord record = CreateBookingRecord(
                date,
                organizationId,
                tournamentId,
                product,
                quantity,
                value,
                credit,
                user);

            record.PaymentsDueDate = paymentsDueDate;

            unitOfWork.GetRepository<BookingRecord>().Insert(record);
            unitOfWork.Save();
            return record;
        }
Ejemplo n.º 5
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.º 6
0
 public void UserRegisteredForTournament(User user, TournamentOrganizationRegistration registration, Boolean adjudicator, string personalDataLink)
 {
     var role = adjudicator ? Resources.Strings.Adjudicator : Resources.Strings.Speaker;
     var message = CreateEMailMessage(new List<String> { user.NewEMail });
     message.Subject = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentSubject,
         role
     );
     message.Body = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentBody,
         user.FirstName,
         registration.Organization.Name,
         role,
         registration.Tournament.Name,
         personalDataLink
     );
     message.HTMLBody = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentBodyHTML,
         user.FirstName,
         registration.Organization.Name,
         role,
         registration.Tournament.Name,
         personalDataLink
     );
     mailService.SendCompleted += mailService_SendCompleted;
     mailService.Send(message);
 }
Ejemplo n.º 7
0
        public void AddBooking_WithNote_ShouldCreateBooking() {
            // Arrange

            Random rand = new Random();
            DateTime date = DateTime.Now;
            Guid organizationId = Guid.NewGuid();
            Guid tournamentId = Guid.NewGuid();
            Decimal value = rand.Next(10, 1000);
            Boolean credit = false;
            String note = "Testnote";
            User user = new User { Id = Guid.NewGuid().ToString() };

            // Act

            var record = bookingManager.AddBooking(
                date,
                organizationId,
                tournamentId,
                value,
                credit,
                note,
                user
            );

            var id = record.Id;

            // Assert

            record = null;

            record = bookingManager.GetBookings(organizationId, tournamentId)
                .FirstOrDefault(r => r.Id == id);
            Assert.AreEqual(note, record.Note);
        }
Ejemplo n.º 8
0
        private IEnumerable<SlotAssignmentViewModel> GetSlotAssignmentViewModels(Guid tournamentId, User user)
        {
            // Build wait list
            var waitList = tournamentRegistrationsManager.GetRegistrationsSortedByRank(tournamentId, user);

            // Get latest version
            var latestVersion = slotAssignmentManager.GetLatestVersion(tournamentId);
            if (latestVersion == null)
            {
                latestVersion = slotAssignmentManager.CreateVersion(tournamentId);
            }

            // Get assignments
            var assignments = slotManager.GetSlotAssignments(tournamentId, latestVersion, user);

            // Build view model
            List<SlotAssignmentViewModel> assignmentsViewModel = new List<SlotAssignmentViewModel>();
            foreach (var registration in waitList)
            {
                var assignment = assignments.FirstOrDefault(
                    a => a.OrganizationId == registration.OrganizationId);
                if (assignment == null)
                {
                    assignment = new SlotAssignment();
                }
                assignmentsViewModel.Add(new SlotAssignmentViewModel
                {
                    Assignment = assignment,
                    Registration = registration
                });
            }
            return assignmentsViewModel;
        }
        public IEnumerable<TournamentOrganizationRegistration> GetRegistrationsSortedByRank(Guid tournamentId, User user)
        {

            // Get registrations, where either the status is approved and not draft,
            // or slots have been assigned or paid
            var registrations = unitOfWork.GetRepository<TournamentOrganizationRegistration>().Get(
                r => (r.TournamentId == tournamentId
                    && (
                        (
                            r.OrganizationStatus == OrganizationStatus.Approved
                            && !r.OrganizationStatusDraft
                        )
                        || r.TeamsGranted > 0
                        || r.TeamsPaid > 0
                        || r.AdjudicatorsGranted > 0
                        || r.AdjudicatorsPaid > 0
                    )
                )
            );

            // Create seed for random

            Random rand = new Random();

            // Build a random ranking, if needed

            Boolean duplicateRandomRanks;
            do
            {
                duplicateRandomRanks = false;

                // Get groups of equal random rank

                var groupedByRandomRank = from r in registrations
                                          group r by r.RandomRank into grp
                                          select grp;


                foreach (var registrationsGroup in groupedByRandomRank)
                {

                    // if there is more than one registration in a group, randomize group
                    if (registrationsGroup.Count() > 1)
                    {
                        foreach (var registration in registrationsGroup)
                        {
                            SetRandomRank(registration.TournamentId, registration.OrganizationId, rand.Next(), user);
                        }
                        duplicateRandomRanks = true;
                    }
                }
            } while (duplicateRandomRanks);

            var result = registrations.OrderByDescending(r => r.Rank).ThenBy(r => r.RandomRank);

            return result;
        }
Ejemplo n.º 10
0
 public void UserRegistered(User user, String resetUrl)
 {
     var message = CreateEMailMessage(new List<String> { user.Email });
     message.Subject = Resources.DebRegCommunication.SendMail.Strings.UserRegisteredSubject;
     message.Body = String.Format(Resources.DebRegCommunication.SendMail.Strings.UserRegisteredBody, user.FirstName, resetUrl);
     message.HTMLBody = String.Format(Resources.DebRegCommunication.SendMail.Strings.UserRegisteredBodyHTML, user.FirstName, resetUrl);
     mailService.SendCompleted += mailService_SendCompleted;
     mailService.Send(message);
 }
Ejemplo n.º 11
0
        public async Task LoginAsync(User user)
        {
            ClaimsIdentity ident = await userManager.CreateIdentityAsync(user, CookieAuthenticationDefaults.AuthenticationType);


            // Sign in

            authManager.SignOut();
            authManager.SignIn(new AuthenticationProperties { IsPersistent = false }, ident);
        }
Ejemplo n.º 12
0
 public UserViewModel(User user)
     : this()
 {
     User = user;
     if (user != null)
     {
         foreach (var value in user.PropertyValues)
         {
             UserProperties.Add(new UserPropertyValueViewModel(value));
         }
     }
 }
Ejemplo n.º 13
0
 public UserViewModel(User user, Guid tournamentId)
     : this(user)
 {
     if (User != null)
     {
         var tournamentPropertyValues = user.TournamentPropertyValues.Where(v => v.TournamentId == tournamentId);
         foreach (var value in tournamentPropertyValues)
         {
             UserProperties.Add(new UserPropertyValueViewModel(value.ToUserPropertyValue()));
         }
     }
 }
Ejemplo n.º 14
0
        public void ConfirmSlots(Guid tournamentId, Guid organizationId, int paidTeams, int paidAdjudicators, String paymentPageUrl, User user) {
            var registration = registrationsManager.SetTeamsAndAdjudicatorsPaid(tournamentId, organizationId, paidTeams, paidAdjudicators, user);

            if (registration != null
                && registration.Tournament != null
                && registration.Tournament.HostingOrganization != null
                && registration.Tournament.HostingOrganization.SMTPHostConfiguration != null) {

                if (lastTournamentId != tournamentId) {
                    while (sentMessages.Count > 0) {
                        // wait for messages to be sent
                    }
                    ConfigureMailService(registration.Tournament.HostingOrganization.SMTPHostConfiguration);
                }

                paymentPageUrl = String.Format(paymentPageUrl, registration.TournamentId, registration.OrganizationId);
                SendAssignmentNotification(registration, paymentPageUrl, user);
            }
        }
Ejemplo n.º 15
0
 public void UpdateTrackingData(User user)
 {
     if (Created == null)
     {
         Created = DateTime.UtcNow;
     }
     if (CreatedBy == null)
     {
         CreatedBy = user;
     }
     if (String.IsNullOrWhiteSpace(CreatedById))
     {
         CreatedById = CreatedBy.Id;
     }
     Modified = DateTime.UtcNow;
     ModifiedBy = user;
     if (user != null)
     {
         ModifiedById = user.Id;
     }
 }
Ejemplo n.º 16
0
 public void ConfirmEMailAddress(User user, string confirmUrl)
 {
     var message = CreateEMailMessage(new List<String> { user.NewEMail });
     message.Subject = Resources.DebRegCommunication.SendMail.Strings.ConfirmEMailSubject;
     message.Body = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.ConfirmEMailBody,
         user.FirstName,
         user.NewEMail,
         confirmUrl
     );
     message.HTMLBody = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.ConfirmEMailBodyHTML,
         user.FirstName,
         user.NewEMail,
         confirmUrl
     );
     mailService.SendCompleted += mailService_SendCompleted;
     mailService.Send(message);
 }
Ejemplo n.º 17
0
        public void Register_WithOrganizationIdAndAuthorizedUser_ShouldReturnViewWithOrganization()
        {
            // Arrange

            User user = new User { Id = Guid.NewGuid().ToString(), UserName = "******" };

            var task = userManager.CreateAsync(user);
            if (!task.IsCompleted)
            {
                task.Wait();
            }

            Guid organizationId = Guid.NewGuid();
            Organization organization = new Organization { Id = organizationId };
            unitOfWork.GetRepository<Organization>().Insert(organization);
            unitOfWork.Save();

            unitOfWork.GetRepository<OrganizationUser>().Insert(new OrganizationUser
            {
                OrganizationId = organization.Id,
                UserId = user.Id,
                Role = OrganizationRole.Delegate
            });
            unitOfWork.Save();

            httpMocks.UserId = user.Id;
            httpMocks.UserName = user.UserName;



            // Act

            ViewResult result = (ViewResult)organizationController.Register(organization.Id);

            // Assert

            organization = (Organization)result.Model;
            Assert.AreEqual(organizationId, organization.Id);

        }
Ejemplo n.º 18
0
        public void AddBooking_ShouldCreateBooking() {
            // Arrange

            Random rand = new Random();
            DateTime date = DateTime.Now;
            Guid organizationId = Guid.NewGuid();
            Guid tournamentId = Guid.NewGuid();
            Decimal value = rand.Next(10, 1000);
            Boolean credit = false;
            User user = new User { Id = Guid.NewGuid().ToString() };

            // Act

            var record = bookingManager.AddBooking(
                date,
                organizationId,
                tournamentId,
                value,
                credit,
                user
            );

            var id = record.Id;

            // Assert

            record = null;

            record = bookingManager.GetBookings(organizationId, tournamentId)
                .FirstOrDefault(r => r.Id == id);
            Assert.AreEqual(date, record.Date);
            Assert.AreEqual(organizationId, record.OrganizationId);
            Assert.AreEqual(tournamentId, record.TournamentId);
            Assert.AreEqual(value, record.Value);
            Assert.AreEqual(credit, record.Credit);
            Assert.AreEqual(user.Id, record.CreatedById);
            Assert.AreEqual(user.Id, record.ModifiedById);
            Assert.IsNotNull(record.Created);
            Assert.IsNotNull(record.Modified);
        }
Ejemplo n.º 19
0
 private BookingRecord CreateBookingRecord(
     DateTime date,
     Guid organizationId,
     Guid tournamentId,
     Decimal value,
     Boolean credit,
     String note,
     User user)
 {
     BookingRecord record = new BookingRecord
     {
         Id = Guid.NewGuid(),
         Date = date,
         OrganizationId = organizationId,
         TournamentId = tournamentId,
         Value = value,
         Credit = credit,
         Note = note
     };
     record.UpdateTrackingData(user);
     return record;
 }
Ejemplo n.º 20
0
        public void PublishAssignments_WithInvalidTournamentId_ShouldDoNothing()
        {
            // Arrange

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);

            // Create new draft version

            CreateDraftVersion(user);


            // Act

            var oldBookingsCount = bookingManager.GetBookings(tournament.Id).Count;
            slotManager.PublishAssignments(Guid.Empty, paymentsDueDate, null, user);

            // Assert

            var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Assert.AreEqual(VersionStatus.Draft, latestVersion.Status);
            var newBookingsCount = bookingManager.GetBookings(tournament.Id).Count;
            Assert.AreEqual(oldBookingsCount, newBookingsCount);

        }
Ejemplo n.º 21
0
        public void PublishAssignments_WithNewDraftVersion_ShouldInvalidateOldPublishedVersion()
        {
            // Arrange

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);

            {
                // Create first published version

                CreateDraftVersion(user);
                slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);
            }

            var latestVersionOld = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Dictionary<Guid, Decimal> expectedBalances = new Dictionary<Guid, Decimal>();

            slotAssignmentManager.CreateVersion(tournament.Id);

            foreach (var assignment in slotAssignmentManager.GetSlotAssignments(tournament.Id, latestVersionOld.Id))
            {

                var teamsGranted = assignment.TeamsGranted;
                if (assignment.TeamsGranted > 2)
                {
                    teamsGranted--;
                }

                if (assignment.TeamsGranted < 2)
                {
                    teamsGranted++;
                }

                var adjudicatorsGranted = assignment.AdjucatorsGranted;
                if (assignment.AdjucatorsGranted > 2)
                {
                    adjudicatorsGranted--;
                }

                if (assignment.AdjucatorsGranted < 2)
                {
                    adjudicatorsGranted++;
                }

                slotAssignmentManager.AssignSlots(assignment.TournamentId, assignment.OrganizationId, teamsGranted, adjudicatorsGranted, user);

                var oldBalance = bookingManager.GetBalance(assignment.OrganizationId, assignment.TournamentId);
                var expectedBalance =
                    oldBalance +
                    (assignment.TeamsGranted - teamsGranted) * tournament.TeamProduct.Price +
                    (assignment.AdjucatorsGranted - adjudicatorsGranted) * tournament.AdjudicatorProduct.Price;
                expectedBalances.Add(assignment.OrganizationId, expectedBalance);
            }


            // Act

            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);

            // Assert

            Assert.AreEqual(VersionStatus.Outdated, latestVersionOld.Status);

            var latestVersionNew = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Assert.AreEqual(VersionStatus.Public, latestVersionNew.Status);

            foreach (var assignment in slotAssignmentManager.GetSlotAssignments(tournament.Id, latestVersionNew.Id))
            {
                Decimal expectedBalance;
                expectedBalances.TryGetValue(assignment.OrganizationId, out expectedBalance);
                var actualBalance = bookingManager.GetBalance(assignment.OrganizationId, assignment.TournamentId);
                Assert.AreEqual(expectedBalance, actualBalance);
            }
        }
Ejemplo n.º 22
0
        public void PublishAssignments_WithSMTPHostConfiguration()
        {
            // Arrange
            tournament.HostingOrganization.SMTPHostConfiguration = new SMTPHostConfiguration();
            tournament.HostingOrganization.SMTPHostConfiguration.Password = "******";
            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);
            CreateDraftVersion(user);

            // Act

            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);

            // Assert
        }
Ejemplo n.º 23
0
        public void PublishAssignments_WithAlreadyPublishedVersion_ShouldDoNothing()
        {
            // Arrange

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);

            {
                // Create first published version

                CreateDraftVersion(user);
                slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);
            }

            var latestVersionOld = slotAssignmentManager.GetLatestVersion(tournament.Id);
            var bookingsCountOld = bookingManager.GetBookings(tournament.Id).Count;

            // Act

            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);

            // Assert

            var latestVersionNew = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Assert.AreEqual(latestVersionOld.Id, latestVersionNew.Id);
            Assert.AreEqual(bookingsCountOld, bookingManager.GetBookings(tournament.Id).Count);
        }
Ejemplo n.º 24
0
        public void PublishAssignments_WithNoVersion_ShouldDoNothing()
        {
            // Arrange

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);
            var bookingsCountOld = bookingManager.GetBookings(tournament.Id).Count;

            // Act

            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);

            // Assert

            var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Assert.IsNull(latestVersion);
            Assert.AreEqual(bookingsCountOld, bookingManager.GetBookings(tournament.Id).Count);
        }
Ejemplo n.º 25
0
        public void PublishAssignments_WithMissingProductLinks_ShouldPublishAssignedSlotsWithNoBookings()
        {
            // Arrange
            #region ARRANGE

            // Basic parameters and objects

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);

            // Create new draft version

            CreateDraftVersion(user);

            // Remove Product Links

            var teamProduct = tournament.TeamProduct;
            var adjudicatorProduct = tournament.AdjudicatorProduct;
            tournament.TeamProduct = null;
            tournament.AdjudicatorProduct = null;

            #endregion

            // Act
            var oldBookingsCount = bookingManager.GetBookings(tournament.Id).Count;
            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);

            // Restore product links
            tournament.TeamProduct = teamProduct;
            tournament.AdjudicatorProduct = adjudicatorProduct;

            // Assert

            var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Assert.AreEqual(latestVersion.Status, VersionStatus.Public);

            foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id))
            {
                var assignment = slotAssignmentManager.GetSlotAssignment(tournament.Id, registration.OrganizationId);
                Assert.AreEqual(registration.AdjudicatorsGranted, assignment.AdjucatorsGranted);
                Assert.AreEqual(registration.TeamsGranted, assignment.TeamsGranted);
            }

            var newbookingsCount = bookingManager.GetBookings(tournament.Id).Count;
            Assert.AreEqual(oldBookingsCount, newbookingsCount);

            #region ASSERT
            #endregion
        }
Ejemplo n.º 26
0
        public void PublishAssignments_WithEmptySMTPConfiguration()
        {
            // Arrange

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);

            // Create new draft version

            CreateDraftVersion(user);


            // Act

            var oldBookingsCount = bookingManager.GetBookings(tournament.Id).Count;
            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);

            // Assert

        }
Ejemplo n.º 27
0
        public void PublishAssignments_WithFewerSlotsThanPaid_ShouldDecreaseSlotsPaid()
        {
            // Arrange

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);

            {
                // Create first published version

                CreateDraftVersion(user);
                slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);
            }

            var latestVersionOld = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Dictionary<Guid, Decimal> expectedBalances = new Dictionary<Guid, Decimal>();

            slotAssignmentManager.CreateVersion(tournament.Id);

            foreach (var assignment in slotAssignmentManager.GetSlotAssignments(tournament.Id, latestVersionOld.Id))
            {

                var registration = tournamentRegistrationsManager.GetRegistration(tournament.Id, assignment.OrganizationId);
                registration.TeamsPaid = registration.TeamsGranted;
                registration.AdjudicatorsPaid = registration.AdjudicatorsWanted;

                var teamsGranted = assignment.TeamsGranted;
                if (assignment.TeamsGranted > 1)
                {
                    teamsGranted--;
                }

                if (assignment.TeamsGranted < 2)
                {
                    teamsGranted++;
                }

                var adjudicatorsGranted = assignment.AdjucatorsGranted;
                if (assignment.AdjucatorsGranted > 1)
                {
                    adjudicatorsGranted--;
                }

                if (assignment.AdjucatorsGranted < 2)
                {
                    adjudicatorsGranted++;
                }

                slotAssignmentManager.AssignSlots(assignment.TournamentId, assignment.OrganizationId, teamsGranted, adjudicatorsGranted, user);

                var oldBalance = bookingManager.GetBalance(assignment.OrganizationId, assignment.TournamentId);
                var expectedBalance =
                    oldBalance +
                    (assignment.TeamsGranted - teamsGranted) * tournament.TeamProduct.Price +
                    (assignment.AdjucatorsGranted - adjudicatorsGranted) * tournament.AdjudicatorProduct.Price;
                expectedBalances.Add(assignment.OrganizationId, expectedBalance);
            }


            // Act

            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);

            // Assert


            var latestVersionNew = slotAssignmentManager.GetLatestVersion(tournament.Id);

            foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id))
            {
                Assert.IsTrue(registration.TeamsPaid <= registration.TeamsGranted);
            }
        }
Ejemplo n.º 28
0
        private Dictionary<Guid, Decimal> CreateDraftVersion(User user)
        {
            Dictionary<Guid, Decimal> expectedBalances = new Dictionary<Guid, Decimal>();

            DebReg.Models.Version version = slotAssignmentManager.CreateVersion(tournament.Id);

            foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id))
            {
                int teamsGranted = registration.TeamsWanted;

                int adjudicatorsGranted = registration.AdjudicatorsWanted;

                slotAssignmentManager.AssignSlots(
                    registration.TournamentId,
                    registration.OrganizationId,
                    teamsGranted,
                    adjudicatorsGranted,
                    user
                );
                var oldBalance = bookingManager.GetBalance(registration.OrganizationId, registration.TournamentId);
                var expectedBalance =
                    (registration.TeamsGranted - teamsGranted) * tournament.TeamProduct.Price +
                    (registration.AdjudicatorsGranted - adjudicatorsGranted) * tournament.AdjudicatorProduct.Price;
                expectedBalances.Add(registration.OrganizationId, expectedBalance);
            }

            return expectedBalances;
        }
Ejemplo n.º 29
0
        private User CreateUserWithOrganizationRole(Organization organization, OrganizationRole role)
        {
            User user = new User
            {
                Id = Guid.NewGuid().ToString()
            };

            user.OrganizationAssociations.Add(new OrganizationUser
            {
                User = user,
                UserId = user.Id,
                Organization = organization,
                OrganizationId = organization.Id,
                Role = role
            });

            var task = userManager.CreateAsync(user);
            while (!task.IsCompleted)
            {

            }
            return user;
        }
Ejemplo n.º 30
0
        public void PublishAssignments_FirstVersion_ShouldPublishAssignedSlots()
        {
            // Arrange
            #region ARRANGE

            // Basic parameters and objects

            User user = new User { Id = Guid.NewGuid().ToString() };
            DateTime paymentsDueDate = DateTime.Today.AddDays(14);
            Dictionary<Guid, Decimal> expectedBalances;



            // Create new draft version

            expectedBalances = CreateDraftVersion(user);


            #endregion

            // Act

            slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user);


            // Assert

            var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id);
            Assert.AreEqual(latestVersion.Status, VersionStatus.Public);

            foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id))
            {
                var assignment = slotAssignmentManager.GetSlotAssignment(tournament.Id, registration.OrganizationId);
                Assert.AreEqual(registration.AdjudicatorsGranted, assignment.AdjucatorsGranted);
                Assert.AreEqual(registration.TeamsGranted, assignment.TeamsGranted);
                Decimal expectedBalance;
                expectedBalances.TryGetValue(registration.OrganizationId, out expectedBalance);
                Decimal actualBalance = bookingManager.GetBalance(registration.OrganizationId, tournament.Id);
                Assert.AreEqual(expectedBalance, actualBalance);
            }

            #region ASSERT
            #endregion
        }