Esempio n. 1
0
        public void TestUniqueVerifiedParent()
        {
            // Should not be possible to create verified organisations with the same name and same parent.

            var adminId = Guid.NewGuid();
            var parent  = new VerifiedOrganisation {
                Name = "Parent", AccountManagerId = adminId, VerifiedById = adminId
            };

            _organisationsCommand.CreateOrganisation(parent);

            var verified1 = new VerifiedOrganisation {
                Name = VerifiedName, AccountManagerId = adminId, VerifiedById = adminId
            };

            verified1.SetParent(parent);
            _organisationsCommand.CreateOrganisation(verified1);
            var verified2 = new VerifiedOrganisation {
                Name = VerifiedName, AccountManagerId = adminId, VerifiedById = adminId
            };

            verified2.SetParent(parent);

            try
            {
                _organisationsCommand.CreateOrganisation(verified2);
                Assert.Fail("Expected an exception");
            }
            catch (ValidationErrorsException ex)
            {
                Assert.AreEqual(1, ex.Errors.Count);
                Assert.IsInstanceOfType(ex.Errors[0], typeof(DuplicateValidationError));
            }
        }
Esempio n. 2
0
 private static void MapTo(this OrganisationEntity entity, VerifiedOrganisation organisation, string parentFullName)
 {
     organisation.AccountManagerId = entity.OrganisationalUnitEntity.accountManagerId;
     organisation.VerifiedById     = entity.OrganisationalUnitEntity.verifiedById;
     organisation.ContactDetails   = entity.OrganisationalUnitEntity.Map();
     organisation.SetParent(entity.OrganisationalUnitEntity.parentId, parentFullName);
 }
Esempio n. 3
0
        public void TestVerifiedSameNameDifferentParents()
        {
            // Should be possible to create verified organisations with the same name but different parents.

            var adminId = Guid.NewGuid();
            var parent1 = new VerifiedOrganisation {
                Name = "Parent1", AccountManagerId = adminId, VerifiedById = adminId
            };

            _organisationsCommand.CreateOrganisation(parent1);
            var parent2 = new VerifiedOrganisation {
                Name = "Parent2", AccountManagerId = adminId, VerifiedById = adminId
            };

            _organisationsCommand.CreateOrganisation(parent2);

            var verified1 = new VerifiedOrganisation {
                Name = VerifiedName, AccountManagerId = adminId, VerifiedById = adminId
            };

            verified1.SetParent(parent1);
            _organisationsCommand.CreateOrganisation(verified1);

            var verified2 = new VerifiedOrganisation {
                Name = VerifiedName, AccountManagerId = adminId, VerifiedById = adminId
            };

            verified2.SetParent(parent2);
            _organisationsCommand.CreateOrganisation(verified2);

            Assert.AreNotEqual(Guid.Empty, verified1.Id);
            Assert.AreNotEqual(Guid.Empty, verified2.Id);
            Assert.AreNotEqual(verified1.Id, verified2.Id);
        }
Esempio n. 4
0
        public void TestNameErrors()
        {
            var administrator = _administratorAccountsCommand.CreateTestAdministrator(1);

            LogIn(administrator);
            var url = GetNewOrganisationUrl();

            Get(url);

            // No name.

            _createButton.Click();
            AssertErrorMessage("The name is required.");

            // Bad name.

            _nameTextBox.Text = "%$^&$#(^";
            _createButton.Click();
            AssertErrorMessage("The name must be between 1 and 100 characters in length and not have any invalid characters.");

            // Hierarchy name.

            var parent = new VerifiedOrganisation {
                Name = "Parent"
            };
            var child = new VerifiedOrganisation {
                Name = "Child"
            };

            child.SetParent(parent);

            _nameTextBox.Text = child.FullName;
            _createButton.Click();
            AssertErrorMessage("The name must be between 1 and 100 characters in length and not have any invalid characters.");
        }
Esempio n. 5
0
        public static VerifiedOrganisation CreateTestVerifiedOrganisation(this IOrganisationsCommand organisationsCommand, string name, Organisation parentOrganisation, Guid accountManagerId, Guid verifiedById)
        {
            var organisation = new VerifiedOrganisation
            {
                Name             = name,
                VerifiedById     = verifiedById,
                AccountManagerId = accountManagerId,
            };

            organisation.SetParent(parentOrganisation);
            organisationsCommand.CreateOrganisation(organisation);
            return(organisation);
        }
Esempio n. 6
0
        public ActionResult New([Bind(Include = "ParentFullName")] string parentFullName, [Bind(Include = "Name")] string name, [Bind(Include = "Location")] string location, [Bind(Include = "AccountManagerId")] Guid accountManagerId, [Bind(Include = "FirstName,LastName,EmailAddress")] ContactDetails contactDetails, [Bind(Include = "CommunityId")] Guid?communityId)
        {
            // Can only create a verified organisation.

            contactDetails.ParseEmailAddresses(contactDetails.EmailAddress);
            var organisation = new VerifiedOrganisation
            {
                Name             = name,
                Address          = GetAddress(location),
                AccountManagerId = accountManagerId,
                VerifiedById     = CurrentAdministrator.Id,
                ContactDetails   = contactDetails,
                AffiliateId      = communityId,
            };

            try
            {
                organisation.SetParent(GetParentOrganisation(parentFullName));

                // Create the organisation itself.

                _organisationsCommand.CreateOrganisation(organisation);

                return(RedirectToRouteWithConfirmation(OrganisationsRoutes.Edit, new { organisation.Id }, HttpUtility.HtmlEncode("The '" + organisation.FullName + "' organisation has been created.")));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            // Show the errors.

            var accountManagers = GetAccountManagers(organisation);

            return(View(new OrganisationModel
            {
                Organisation = organisation,
                AccountManagers = accountManagers,
                VerifiedByAccountManager = GetVerifiedByAccountManager(organisation, accountManagers),
                Communities = _communitiesQuery.GetCommunities(),
            }));
        }
Esempio n. 7
0
        public void TestVerifiedFullNames()
        {
            var verifiedName = VerifiedName;

            var adminId  = Guid.NewGuid();
            var verified = new VerifiedOrganisation {
                Name = verifiedName, VerifiedById = adminId, AccountManagerId = adminId
            };

            _organisationsCommand.CreateOrganisation(verified);

            Assert.AreEqual(verifiedName, verified.Name);
            Assert.AreEqual(verifiedName, verified.FullName);

            // Set up parent and child organisations.

            var parentName = "Parent Company";
            var childName  = "Child Company";

            var parent = new VerifiedOrganisation {
                Name = parentName, VerifiedById = adminId, AccountManagerId = adminId
            };

            _organisationsCommand.CreateOrganisation(parent);
            var child = new VerifiedOrganisation {
                Name = childName, VerifiedById = adminId, AccountManagerId = adminId
            };

            _organisationsCommand.CreateOrganisation(child);

            // Parent => Verified => Child.

            verified.SetParent(parent);
            _organisationsCommand.UpdateOrganisation(verified);

            child.SetParent(verified);
            _organisationsCommand.UpdateOrganisation(child);

            // Test the full names.

            Assert.AreEqual(parentName, parent.Name);
            Assert.AreEqual(parentName, parent.FullName);

            Assert.AreEqual(verifiedName, verified.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName, verified.FullName);

            Assert.AreEqual(childName, child.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName + Organisation.FullNameSeparator + childName, child.FullName);

            // Re-read and make sure they still work.

            parent   = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(parent.Id);
            verified = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(verified.Id);
            child    = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(child.Id);

            Assert.AreEqual(parentName, parent.Name);
            Assert.AreEqual(parentName, parent.FullName);

            Assert.AreEqual(verifiedName, verified.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName, verified.FullName);

            Assert.AreEqual(childName, child.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName + Organisation.FullNameSeparator + childName, child.FullName);

            // Change some names

            childName  = "Child Changed";
            child.Name = childName;
            Assert.AreEqual(childName, child.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName + Organisation.FullNameSeparator + childName, child.FullName);

            verifiedName  = "Verified Changed";
            verified.Name = verifiedName;
            Assert.AreEqual(verifiedName, verified.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName, verified.FullName);

            parentName  = "Parent Changed";
            parent.Name = parentName;
            Assert.AreEqual(parentName, parent.Name);
            Assert.AreEqual(parentName, parent.FullName);

            // Update.

            _organisationsCommand.UpdateOrganisation(parent);
            _organisationsCommand.UpdateOrganisation(verified);
            _organisationsCommand.UpdateOrganisation(child);
            parent   = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(parent.Id);
            verified = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(verified.Id);
            child    = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(child.Id);

            Assert.AreEqual(parentName, parent.Name);
            Assert.AreEqual(parentName, parent.FullName);

            Assert.AreEqual(verifiedName, verified.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName, verified.FullName);

            Assert.AreEqual(childName, child.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName + Organisation.FullNameSeparator + childName, child.FullName);

            // Change the parent to another company

            child.SetParent(parent);
            Assert.AreEqual(childName, child.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + childName, child.FullName);

            _organisationsCommand.UpdateOrganisation(child);
            parent   = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(parent.Id);
            verified = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(verified.Id);
            child    = (VerifiedOrganisation)_organisationsQuery.GetOrganisation(child.Id);

            Assert.AreEqual(parentName, parent.Name);
            Assert.AreEqual(parentName, parent.FullName);

            Assert.AreEqual(verifiedName, verified.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + verifiedName, verified.FullName);

            Assert.AreEqual(childName, child.Name);
            Assert.AreEqual(parentName + Organisation.FullNameSeparator + childName, child.FullName);
        }