// GET: Organization/Register public ActionResult Register(Guid? organizationId = null, String returnUrl = "") { // Get organization from repository Organization organization = null; if (organizationId != null) { organization = organizationManager.GetOrganization((Guid)organizationId); // if user is not a delegate of organization, return to home if (organization != null && !userManager.HasOrganizationRole(HttpContext.User.Identity.GetUserId(), (Guid)organizationId, OrganizationRole.Delegate)) { return RedirectToAction("Index", "Home"); } } if (organization == null) { organization = new Organization { Address = new Address() }; } ViewBag.returnUrl = returnUrl; return View(organization); }
public void Init() { var debRegDataMocks = new DebRegDataMocks(); organization = new Organization { Id = Guid.NewGuid() }; unitOfWork = debRegDataMocks.UnitOfWork; userManager = debRegDataMocks.UserManager; tournamentManager = new TournamentManager(unitOfWork, userManager); }
public void GetOrganization_WithInValidId_ShouldReturnNull() { // Arrange Guid id = Guid.NewGuid(); var organization = new Organization(); organization.Id = id; unitOfWork.GetRepository<Organization>().Insert(organization); unitOfWork.Save(); // Act var savedOrganization = organizationManager.GetOrganization(Guid.NewGuid()); // Assert Assert.IsNull(savedOrganization); }
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); }
private TournamentOrganizationRegistration CreateTournamentOrganizationRegistration() { Organization organization = new Organization { Id = Guid.NewGuid(), }; Organization linkedOrganization = new Organization { Id = Guid.NewGuid(), LinkedOrganization = organization, LinkedOrganizationId = organization.Id }; organization.LinkedOrganizations.Add(linkedOrganization); TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration { OrganizationId = organization.Id, Organization = organization, TournamentId = Guid.NewGuid(), }; tournamentRegistrationsManager.SetBookingCode(registration); return registration; }
public void Register_WithExistingOrganizationAndInvalidUser_ShouldReturnRedirect() { // Arrange User user = CreateUserInRepository(); Organization organization = new Organization { Id = Guid.NewGuid() }; var organizationCreateTask = organizationManager.CreateOrganizationAsync(organization, user); if (!organizationCreateTask.IsCompleted) { organizationCreateTask.Wait(); } var organizationId = organization.Id; organization = CreateOrganizationObject(); organization.Id = organizationId; String linkedOrganizationName = "University 1"; organization.LinkedOrganizations.Add(new Organization { Name = linkedOrganizationName }); httpMocks.UserId = Guid.NewGuid().ToString(); httpMocks.UserName = "******"; // Act var task = organizationController.Register(organization); if (!task.IsCompleted) { task.Wait(); } var actionResult = task.Result; // Assert Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult)); }
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; } }
public void DeleteOrganization_WithInvalidUser_ShouldThrowException() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; Organization organization = new Organization { Id = Guid.NewGuid(), }; unitOfWork.GetRepository<Organization>().Insert(organization); unitOfWork.Save(); var organizationId = organization.Id; user = new User { Id = Guid.NewGuid().ToString() }; // Act try { var task = organizationManager.DeleteOrganizationAsync(organizationId, user); if (!task.IsCompleted) { task.Wait(); } } // Assert catch (UnauthorizedAccessException e) { Assert.AreEqual(OrganizationManager.UserNotAuthorizedMessage, e.Message); } }
public void UpdateOrganizationAsync_WithNonExistingOrganization_ShouldThrowException() { // Arrange var user = new User { Id = Guid.NewGuid().ToString() }; Organization organization = new Organization { Id = Guid.NewGuid() }; // Act try { var task = organizationManager.UpdateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } } // Assert catch (ArgumentException e) { Assert.AreEqual(OrganizationManager.OrganizationNotFoundMessage, e.Message); } }
public void UpdateOrganizationAsync_WithCorrectOrganizationAndUser_ShouldUpdateOrganization() { // Arrange var user = new User { Id = Guid.NewGuid().ToString() }; Organization organization = new Organization(); var task = organizationManager.CreateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } var result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); organization = organizationManager.GetOrganization(organization.Id); String name = " Organization "; organization.Name = name; // Act task = organizationManager.UpdateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } // Assert result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); organization = organizationManager.GetOrganization(organization.Id); Assert.AreEqual(name.Trim(), organization.Name); }
private CreateOrUpdateOrganizationResult CheckForDuplicates(Organization organization) { // Check linked organizations foreach (var linkedOrganization in organization.LinkedOrganizations) { var duplicateResult = CheckForDuplicates(linkedOrganization); if (duplicateResult == CreateOrUpdateOrganizationResult.DuplicateName) { duplicateResult = CreateOrUpdateOrganizationResult.DuplicateNameOnLinkedOrganization; } //if (duplicateResult == CreateOrUpdateOrganizationResult.DuplicateAbbreviation) //{ // duplicateResult = CreateOrUpdateOrganizationResult.DuplicateAbbreviationOnLinkedOrganization; //} //if (duplicateResult != CreateOrUpdateOrganizationResult.Success) //{ // return duplicateResult; //} } // Check organization itself var organizationRepository = unitOfWork.GetRepository<Organization>(); if (organizationRepository.Get(o => o.Name.Trim().ToLower() == organization.Name.ToLower() && o.Id != organization.Id && !o.Deleted) .Count > 0) { return CreateOrUpdateOrganizationResult.DuplicateName; } if (organization.LinkedOrganizationId == null && organization.LinkedOrganization == null) { if (organizationRepository.Get(o => o.Abbreviation.Trim().ToLower() == organization.Abbreviation.ToLower() && o.Id != organization.Id && !o.Deleted) .Count > 0) { return CreateOrUpdateOrganizationResult.DuplicateAbbreviation; } } return CreateOrUpdateOrganizationResult.Success; }
private void RemoveWhiteSpaceFromStrings(Organization organization) { organization.Name = TrimIfNotNull(organization.Name); organization.Abbreviation = TrimIfNotNull(organization.Abbreviation); if (organization.Address != null) { organization.Address.City = TrimIfNotNull(organization.Address.City); organization.Address.Country = TrimIfNotNull(organization.Address.Country); organization.Address.PostalCode = TrimIfNotNull(organization.Address.PostalCode); organization.Address.Region = TrimIfNotNull(organization.Address.Region); organization.Address.StreetAddress1 = TrimIfNotNull(organization.Address.StreetAddress1); organization.Address.StreetAddress2 = TrimIfNotNull(organization.Address.StreetAddress2); } organization.VatId = TrimIfNotNull(organization.VatId); }
public async Task<CreateOrUpdateOrganizationResult> UpdateOrganizationAsync(Organization organization, User user) { // get saved organization var savedOrganization = GetOrganization(organization.Id); // Check permissions if (savedOrganization.LinkedOrganization == null && !userManager.HasOrganizationRole(user.Id, organization.Id, OrganizationRole.Delegate)) { throw new UnauthorizedAccessException(UserNotAuthorizedMessage); } if (savedOrganization.LinkedOrganization != null && ! userManager.HasOrganizationRole(user.Id, (Guid) savedOrganization.LinkedOrganizationId, OrganizationRole.Delegate)) { throw new UnauthorizedAccessException(UserNotAuthorizedMessage); } // Clean strings RemoveWhiteSpaceFromStrings(organization); // Check for duplicates var duplicateResult = CheckForDuplicates(organization); if (duplicateResult != CreateOrUpdateOrganizationResult.Success) { return duplicateResult; } // Save linked organizations foreach (var linkedOrganization in organization.LinkedOrganizations) { // Is this a new linkedOrganization? var savedLinkedOrganization = GetOrganization(linkedOrganization.Id); CreateOrUpdateOrganizationResult result; if (savedLinkedOrganization == null) { linkedOrganization.LinkedOrganization = savedOrganization; linkedOrganization.LinkedOrganizationId = savedOrganization.Id; result = await CreateOrganizationAsync(linkedOrganization, user); savedLinkedOrganization = GetOrganization(linkedOrganization.Id); } else { result = await UpdateOrganizationAsync(linkedOrganization, user); } if (result != CreateOrUpdateOrganizationResult.Success) { return result; } if (!savedOrganization.LinkedOrganizations.Any(o => o.Id == linkedOrganization.Id)) { savedOrganization.LinkedOrganizations.Add(savedLinkedOrganization); } } // remove linked organizations, if necessary for (int i = savedOrganization.LinkedOrganizations.Count - 1; i > -1; i--) { if (!organization.LinkedOrganizations.Any(o => o.Id == savedOrganization.LinkedOrganizations[i].Id)) { var linkedOrganization = savedOrganization.LinkedOrganizations[i]; savedOrganization.LinkedOrganizations.RemoveAt(i); await DeleteOrganizationAsync(linkedOrganization.Id, user); } } // Save updates if (organization.Address != null) { if (savedOrganization.Address == null) { savedOrganization.Address = new Address(); } organization.Address.CopyProperties(savedOrganization.Address); organization.AddressId = savedOrganization.AddressId; } if (organization.SMTPHostConfiguration != null) { if (savedOrganization.SMTPHostConfiguration == null) { savedOrganization.SMTPHostConfiguration = new SMTPHostConfiguration(); } organization.SMTPHostConfiguration.CopyProperties(savedOrganization.SMTPHostConfiguration); } organization.CopyProperties(savedOrganization); unitOfWork.GetRepository<Organization>().Update(savedOrganization); await unitOfWork.SaveAsync(); organization.Id = savedOrganization.Id; return CreateOrUpdateOrganizationResult.Success; }
private void SetOrganizationDefaults(Organization organization) { foreach (var linkedOrganization in organization.LinkedOrganizations) { SetOrganizationDefaults(linkedOrganization); } // Remove linked objects organization.UserAssociations.Clear(); organization.TournamentRegistrations.Clear(); // Set status organization.Status = OrganizationStatus.Unknown; }
public TournamentOrganizationRegistration FindRegistrationByOrganization(Guid tournamentId, Organization organization) { TournamentOrganizationRegistration registration = unitOfWork.GetRepository<TournamentOrganizationRegistration>().GetById(tournamentId, organization.Id); // If no registration was found, find registration for linked organization if (registration == null) { registration = unitOfWork.GetRepository<TournamentOrganizationRegistration>().GetById(tournamentId, organization.LinkedOrganizationId); // If still no registration was found, find first registration for all linked organizations if (registration == null) { foreach (var linkedOrganization in organization.LinkedOrganizations) { registration = unitOfWork.GetRepository<TournamentOrganizationRegistration>().GetById(tournamentId, linkedOrganization.Id); if (registration != null) { break; } } } } return registration; }
private Organization CreateOrganizationObject() { String abbreviation = " Org "; String city = " City "; String country = " Country "; String postalCode = " PostalCode "; String region = " Region "; String streetAddress1 = " Street Address 1 "; String streetAddress2 = " Street Address 2 "; String name = " Organization Name "; Boolean university = false; String vatId = " ATU12345678 "; SMTPHostConfiguration smtpHostConfiguration = new SMTPHostConfiguration(); Organization organization = new Organization { Abbreviation = abbreviation, Address = new Address { City = city, Country = country, PostalCode = postalCode, Region = region, StreetAddress1 = streetAddress1, StreetAddress2 = streetAddress2, }, Name = name, SMTPHostConfiguration = smtpHostConfiguration, Status = OrganizationStatus.Approved, University = university, VatId = vatId }; return organization; }
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); }
private async Task AddUserAsDelegateForOrganization(Organization organization, User user) { OrganizationUser orgUser = new OrganizationUser { OrganizationId = organization.Id, Organization = organization, UserId = user.Id, User = user, Role = OrganizationRole.Delegate }; orgUser.UpdateTrackingData(user); unitOfWork.GetRepository<OrganizationUser>().Insert(orgUser); await unitOfWork.SaveAsync(); }
public void CreateOrganizationAsync_WithDuplicateOrganizationName_ShouldReturnDuplicateName() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; String name = " Organization "; Organization organization = new Organization { Name = name }; var task = organizationManager.CreateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } var result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); organization = new Organization { Name = name }; // Act task = organizationManager.CreateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } result = task.Result; // Assert Assert.AreEqual(CreateOrUpdateOrganizationResult.DuplicateName, result); }
private void GenerateIds(Organization organization) { foreach (var linkedOrganization in organization.LinkedOrganizations) { GenerateIds(linkedOrganization); } organization.Id = Guid.NewGuid(); if (organization.Address != null) { organization.Address.Id = Guid.NewGuid(); organization.AddressId = organization.Address.Id; } if (organization.SMTPHostConfiguration != null) { organization.SMTPHostConfiguration.Id = Guid.NewGuid(); } }
public void UpdateOrganizationAsync_WithUnauthorizedUserForLinkedOrganization_ShouldThrowException() { // Arrange var user = new User { Id = Guid.NewGuid().ToString() }; Organization organization = new Organization(); var task = organizationManager.CreateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } var result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); Organization linkedOrganization = new Organization(); linkedOrganization.Name = "Organization"; linkedOrganization.Abbreviation = "Org"; task = organizationManager.CreateOrganizationAsync(linkedOrganization, new User { Id = Guid.NewGuid().ToString() }); if (!task.IsCompleted) { task.Wait(); } result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); organization = organizationManager.GetOrganization(organization.Id); organization.LinkedOrganization = linkedOrganization; // Act try { task = organizationManager.UpdateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } } // Assert catch (UnauthorizedAccessException e) { Assert.AreEqual(OrganizationManager.UserNotAuthorizedMessage, e.Message); } }
public async Task<CreateOrUpdateOrganizationResult> CreateOrganizationAsync(Organization organization, User user) { var organizationRepository = unitOfWork.GetRepository<Organization>(); RemoveWhiteSpaceFromStrings(organization); // Create id GenerateIds(organization); //// Check for permissions on LinkedOrganization //CheckLinkedOrganizationPermissions(organization, user); // Check for duplicates var duplicateResult = CheckForDuplicates(organization); if (duplicateResult != CreateOrUpdateOrganizationResult.Success) { return duplicateResult; } foreach (var linkedOrganization in organization.LinkedOrganizations) { RemoveWhiteSpaceFromStrings(linkedOrganization); linkedOrganization.LinkedOrganization = organization; var linkedOrganizationDuplicateResult = CheckForDuplicates(linkedOrganization); switch (linkedOrganizationDuplicateResult) { case CreateOrUpdateOrganizationResult.Success: break; case CreateOrUpdateOrganizationResult.DuplicateName: return CreateOrUpdateOrganizationResult.DuplicateNameOnLinkedOrganization; default: return linkedOrganizationDuplicateResult; } if (linkedOrganization.Name.ToLower() == organization.Name.ToLower()) { return CreateOrUpdateOrganizationResult.DuplicateNameOnLinkedOrganization; } } SetOrganizationDefaults(organization); // Add organization organization.UpdateTrackingData(user); organizationRepository.Insert(organization); await unitOfWork.SaveAsync(); // Make user delegate of the organization and all linked Organizations await AddUserAsDelegateForOrganization(organization, user); foreach (var linkedOrganization in organization.LinkedOrganizations) { await AddUserAsDelegateForOrganization(linkedOrganization, user); } //// Make organization the current organization of the user //if (organization.LinkedOrganization == null && organization.LinkedOrganizationId == null) //{ // await securityManager.SetCurrentOrganizationAsync(user, organization.Id, userManager); //} return CreateOrUpdateOrganizationResult.Success; }
public void UpdateOrganizationAsync_WithDuplicateAbbreviation_ShouldReturnDuplicateAbbreviationResult() { // Arrange var user = new User { Id = Guid.NewGuid().ToString() }; String name = " Organization "; String abbreviation = " Org "; Organization organization = new Organization { Name = name, Abbreviation = abbreviation }; var task = organizationManager.CreateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } var result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); name = " Organization2 "; abbreviation = " Org2 "; Organization organization2 = new Organization { Name = name, Abbreviation = abbreviation }; task = organizationManager.CreateOrganizationAsync(organization2, user); if (!task.IsCompleted) { task.Wait(); } result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); organization2 = organizationManager.GetOrganization(organization2.Id); name = "Organization2a"; abbreviation = "Org"; organization2.Name = name; organization2.Abbreviation = abbreviation; // Act task = organizationManager.UpdateOrganizationAsync(organization2, user); if (!task.IsCompleted) { task.Wait(); } // Assert result = task.Result; Assert.AreEqual(CreateOrUpdateOrganizationResult.DuplicateAbbreviation, result); }
public bool IsUniversity(Organization organization) { if (organization.University) { return true; } var linkedUniversitities = from o in organization.LinkedOrganizations where o.University select o; return linkedUniversitities.Count() > 0; }
public void DeleteOrganization_WithValidUser_ShouldDeleteOrganizationAndLinkedOrganizations() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; Organization organization = new Organization { Id = Guid.NewGuid(), LinkedOrganizations = new List<Organization> { new Organization { Id = Guid.NewGuid() } } }; unitOfWork.GetRepository<Organization>().Insert(organization); unitOfWork.Save(); unitOfWork.GetRepository<OrganizationUser>().Insert(new OrganizationUser { UserId = user.Id, OrganizationId = organization.Id, Role = OrganizationRole.Delegate }); unitOfWork.Save(); foreach (var linkedOrganization in organization.LinkedOrganizations) { unitOfWork.GetRepository<OrganizationUser>().Insert(new OrganizationUser { UserId = user.Id, OrganizationId = linkedOrganization.Id, Role = OrganizationRole.Delegate }); unitOfWork.Save(); } var linkedOrganizations = organization.LinkedOrganizations; var organizationId = organization.Id; // Act var task = organizationManager.DeleteOrganizationAsync(organizationId, user); if (!task.IsCompleted) { task.Wait(); } // Assert var savedOrganization = organizationManager.GetOrganization(organizationId); Assert.IsTrue(savedOrganization.Deleted); foreach (var linkedOrganization in linkedOrganizations) { Assert.IsTrue(linkedOrganization.Deleted); Assert.IsNull(linkedOrganization.LinkedOrganization); } }
public void Register_WithDuplicateOrganizationAbbreviation_ShouldReturnModelError() { // Arrange User user = new User { Id = Guid.NewGuid().ToString(), UserName = "******" }; var userCreateTask = userManager.CreateAsync(user); if (!userCreateTask.IsCompleted) { userCreateTask.Wait(); } httpMocks.UserName = user.UserName; httpMocks.UserId = user.Id; Organization organization = new Organization { Id = Guid.NewGuid(), Name = "Organization", Abbreviation = "Org" }; var orgCreateTask = organizationManager.CreateOrganizationAsync(organization, user); if (!orgCreateTask.IsCompleted) { orgCreateTask.Wait(); } organization = new Organization { Id = Guid.NewGuid(), Name = "Organization2", Abbreviation = "Org" }; // Act var organizationRegisterTask = organizationController.Register(organization); if (!organizationRegisterTask.IsCompleted) { organizationRegisterTask.Wait(); } var result = organizationRegisterTask.Result; // Assert var view = result as ViewResult; var errorValues = view.ViewData.ModelState.Values .Where(v => v.Errors.Count >= 1); Assert.AreEqual(1, errorValues.Count()); var errorValue = errorValues.FirstOrDefault(); Assert.AreEqual(1, errorValue.Errors.Count); Assert.AreEqual(Resources.Organization.Strings.ErrorDuplicateOrganizationAbbreviation, errorValue.Errors[0].ErrorMessage); }
public void CreateOrganizationAsync_WithValidOrganization_ShouldCreateOrganization() { #region Arrange // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; String abbreviation = " Org "; String city = " City "; String country = " Country "; String postalCode = " PostalCode "; String region = " Region "; String streetAddress1 = " Street Address 1 "; String streetAddress2 = " Street Address 2 "; List<Organization> linkedOrganizations = new List<Organization>(); linkedOrganizations.Add(new Organization()); List<OrganizationUser> userAssociations = new List<OrganizationUser>(); userAssociations.Add(new OrganizationUser()); List<TournamentOrganizationRegistration> tournamentRegistrations = new List<TournamentOrganizationRegistration>(); tournamentRegistrations.Add(new TournamentOrganizationRegistration()); String name = " Organization Name "; Boolean university = false; String vatId = " ATU12345678 "; SMTPHostConfiguration smtpHostConfiguration = new SMTPHostConfiguration(); Organization organization = new Organization { Abbreviation = abbreviation, Address = new Address { City = city, Country = country, PostalCode = postalCode, Region = region, StreetAddress1 = streetAddress1, StreetAddress2 = streetAddress2, }, LinkedOrganizations = linkedOrganizations, UserAssociations = userAssociations, TournamentRegistrations = tournamentRegistrations, Name = name, SMTPHostConfiguration = smtpHostConfiguration, Status = OrganizationStatus.Approved, University = university, VatId = vatId }; #endregion // Act var task = organizationManager.CreateOrganizationAsync(organization, user); if (!task.IsCompleted) { task.Wait(); } var result = task.Result; #region Assert // Assert Assert.AreEqual(CreateOrUpdateOrganizationResult.Success, result); var savedOrganization = organizationManager.GetOrganization(organization.Id); Assert.AreEqual(abbreviation.Trim(), savedOrganization.Abbreviation); Assert.AreNotEqual(Guid.Empty, savedOrganization.Address.Id); Assert.AreEqual(city.Trim(), savedOrganization.Address.City); Assert.AreEqual(country.Trim(), savedOrganization.Address.Country); Assert.AreEqual(postalCode.Trim(), savedOrganization.Address.PostalCode); Assert.AreEqual(region.Trim(), savedOrganization.Address.Region); Assert.AreEqual(streetAddress1.Trim(), savedOrganization.Address.StreetAddress1); Assert.AreEqual(streetAddress2.Trim(), savedOrganization.Address.StreetAddress2); Assert.AreEqual(0, savedOrganization.UserAssociations.Count); var organizationUser = unitOfWork.GetRepository<OrganizationUser>().GetById(organization.Id, user.Id, OrganizationRole.Delegate); Assert.IsNotNull(organizationUser); Assert.AreEqual(0, savedOrganization.TournamentRegistrations.Count); Assert.AreEqual(name.Trim(), savedOrganization.Name); Assert.AreNotEqual(Guid.Empty, savedOrganization.SMTPHostConfiguration.Id); Assert.AreEqual(OrganizationStatus.Unknown, savedOrganization.Status); Assert.AreEqual(university, savedOrganization.University); Assert.AreEqual(vatId.Trim(), savedOrganization.VatId); Assert.IsNotNull(savedOrganization.ModifiedBy); Assert.IsNotNull(savedOrganization.Modified); Assert.IsNotNull(savedOrganization.CreatedBy); Assert.IsNotNull(savedOrganization.Created); #endregion }
private void AddRegistrationWithOrganizationToRepository(Guid organizationId, Guid tournamentId, String abbreviation) { Organization organization = new Organization { Id = organizationId, Abbreviation = abbreviation }; TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration { TournamentId = tournamentId, OrganizationId = organizationId, Organization = organization }; unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration); unitOfWork.Save(); }
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; }
public void Register_WithExistingOrganization_ShouldSaveOrganization() { #region Arrange // Arrange Organization organization; Organization linkedOrganization; Guid organizationId; String linkedOrganizationName; { User user = CreateUserInRepository(); // Create organization with one linked organization organization = new Organization { Id = Guid.NewGuid(), Name = "Organization A" }; linkedOrganization = new Organization { Id = Guid.NewGuid(), Name = "University A" }; organization.LinkedOrganizations.Add(linkedOrganization); var organizationCreateTask = organizationManager.CreateOrganizationAsync(organization, user); if (!organizationCreateTask.IsCompleted) { organizationCreateTask.Wait(); } organizationId = organization.Id; var linkedOrganizationId = linkedOrganization.LinkedOrganizationId; // Create a new organization object with same id and a new linked Organization to update the existing one organization = CreateOrganizationObject(); organization.Id = organizationId; linkedOrganizationName = "University 1"; organization.LinkedOrganizations.Add(new Organization { Id = Guid.NewGuid(), Name = linkedOrganizationName }); httpMocks.UserId = user.Id; httpMocks.UserName = user.UserName; } #endregion // Act var task = organizationController.Register(organization); if (!task.IsCompleted) { task.Wait(); } var actionResult = task.Result; // Assert var savedOrganization = unitOfWork.GetRepository<Organization>().GetById(organizationId); Assert.IsNotNull(savedOrganization); Assert.AreEqual(organization.Abbreviation, savedOrganization.Abbreviation); Assert.AreEqual(organization.Address.City, savedOrganization.Address.City); Assert.AreEqual(organization.Address.Country, savedOrganization.Address.Country); Assert.AreEqual(organization.Address.PostalCode, savedOrganization.Address.PostalCode); Assert.AreEqual(organization.Address.Region, savedOrganization.Address.Region); Assert.AreEqual(organization.Address.StreetAddress1, savedOrganization.Address.StreetAddress1); Assert.AreEqual(organization.Address.StreetAddress2, savedOrganization.Address.StreetAddress2); Assert.AreEqual(organization.Name, savedOrganization.Name); Assert.AreEqual(organization.University, savedOrganization.University); Assert.AreEqual(organization.VatId, savedOrganization.VatId); Assert.AreEqual(1, savedOrganization.LinkedOrganizations.Count); Assert.AreEqual(linkedOrganizationName, savedOrganization.LinkedOrganizations.FirstOrDefault().Name); }