Inheritance: RevisableEntity
Exemplo n.º 1
0
 public void HasGetSet()
 {
     var value = new List<Affiliation> { new Affiliation() };
     var entity = new Establishment { Affiliates = value };
     entity.ShouldNotBeNull();
     entity.Affiliates.ShouldEqual(value);
 }
Exemplo n.º 2
0
        /* Deprecated */
        public bool IsAffiliatedWith(Establishment establishment)
        {
            if (Affiliations != null)
            {
                foreach (var affiliation in Affiliations)
                {
                    if (affiliation.EstablishmentId == establishment.RevisionId)
                    {
                        return true;
                    }

                    // check all parents of the establishment
                    if (establishment.Ancestors != null && establishment.Ancestors.Count > 0)
                    {
                        //foreach (var ancestor in establishment.Ancestors.Select(a => a.Ancestor))
                        //{
                        //    if (IsAffiliatedWith(ancestor)) return true;
                        //}
                        if (establishment.Ancestors.Select(a => a.Ancestor).Any(IsAffiliatedWith))
                            return true;
                    }
                }
            }
            return false;
        }
Exemplo n.º 3
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new RoleGrant { ForEstablishment = value };
     entity.ShouldNotBeNull();
     entity.ForEstablishment.ShouldEqual(value);
 }
Exemplo n.º 4
0
 public void HasGetSet()
 {
     var value = new EstablishmentContactInfo();
     var entity = new Establishment { PartnerContactInfo = value };
     entity.ShouldNotBeNull();
     entity.PartnerContactInfo.ShouldEqual(value);
 }
            public void IsValidWhen_MatchesEstablishment_WithAnyTypeCategory()
            {
                const int establishmentId = 6;
                var command = new CreateAffiliationCommand { EstablishmentId = establishmentId };
                var establishment = new Establishment
                {
                    RevisionId = command.EstablishmentId,
                    Type = new EstablishmentType
                    {
                        Category = new EstablishmentCategory
                        {
                            Code = EstablishmentCategoryCode.Govt,
                        },
                    },
                };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new Person[] { }.AsQueryable);
                var validator = new CreateAffiliationValidator(entities.Object);

                var results = validator.Validate(command);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "EstablishmentId");
                error.ShouldBeNull();
            }
            public void IsInvalidWhen_IsTrue_ButEstablishmentIsNotInstitution()
            {
                const bool isClaimingStudent = true;
                var establishment = new Establishment
                {
                    Type = new EstablishmentType
                    {
                        Category = new EstablishmentCategory
                        {
                            Code = "not an institution",
                        },
                    },
                };
                var command = new CreateAffiliationCommand
                {
                    IsClaimingStudent = isClaimingStudent
                };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new Person[] { }.AsQueryable);
                var validator = new CreateAffiliationValidator(entities.Object);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "IsClaimingStudent");
                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                    ValidateAffiliation.FailedBecauseIsClaimingStudentButEstablishmentIsNotInstitution,
                        command.EstablishmentId));
                // ReSharper restore PossibleNullReferenceException
            }
Exemplo n.º 7
0
        public Affiliation AffiliateWith(Establishment establishment)
        {
            var currentAffiliations = Affiliations.ToList();

            // affiliation may already exist
            var affiliation = currentAffiliations
                .SingleOrDefault(a => a.Establishment == establishment);
            if (affiliation != null) return affiliation;

            // create affiliation
            affiliation = new Affiliation
            {
                // if person does not already have a default affiliation, this is it
                IsDefault = !currentAffiliations.Any(a => a.IsDefault),
                Establishment = establishment, // affiliate with establishment
                Person = this,

                // for non-institutions, person should not be claiming student, faculty, etc
                IsClaimingEmployee = !establishment.IsInstitution,
            };

            // add & return affiliation
            Affiliations.Add(affiliation);
            return affiliation;
        }
Exemplo n.º 8
0
        private IEnumerable<SelectListItem> GetHierarchySelectList(Establishment establishment)
        {
            var rootEstablishment = establishment.Parent == null
                ? establishment
                : establishment.Ancestors.Single(e => e.Ancestor.Parent == null).Ancestor;

            var childEstablishments =
                _queryProcessor.Execute(
                    new FindInstitutionalAgreementsOwnedByEstablishmentQuery(rootEstablishment.EntityId)
                    {
                        EagerLoad = new Expression<Func<InstitutionalAgreement, object>>[]
                        {
                            a => a.Participants.Select(p => p.Establishment.Ancestors),
                        }
                    }
                )
                .SelectMany(a => a.Participants.Where(p => p.IsOwner)).Select(p => p.Establishment)
                .Distinct(new RevisableEntityEqualityComparer()).Cast<Establishment>()
                .OrderBy(e => e.Ancestors.Count).ThenBy(e => e.OfficialName);

            var selectList = childEstablishments.Select(e => new SelectListItem
            {
                Text = e.OfficialName,
                Value = e.WebsiteUrl,
            });

            return selectList;
        }
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new InstitutionalAgreementParticipant { Establishment = value };
     entity.ShouldNotBeNull();
     entity.Establishment.ShouldEqual(value);
 }
Exemplo n.º 10
0
        public EstablishmentView(Establishment entity)
        {
            Id = entity.RevisionId;

            OfficialName = entity.Names.Single(e => e.IsOfficialName).Text;

            var officialUrl = entity.Urls.SingleOrDefault(e => e.IsOfficialUrl);
            WebsiteUrl = officialUrl != null ? officialUrl.Value : string.Empty;

            var country = GetCountry(entity);
            CountryCode = country != null ? country.GeoPlanetPlace.Country.Code : string.Empty;
            CountryName = country != null ? country.OfficialName : string.Empty;

            CeebCode = entity.CollegeBoardDesignatedIndicator ?? "";
            UCosmicCode = entity.UCosmicCode ?? "";

            var names = new List<EstablishmentNameView>();
            foreach (var name in entity.Names)
                names.Add(new EstablishmentNameView(name));
            Names = names;

            var urls = new List<EstablishmentUrlView>();
            foreach (var url in entity.Urls)
                urls.Add(new EstablishmentUrlView(url));
            Urls = urls;
        }
Exemplo n.º 11
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new EstablishmentNode { Offspring = value };
     entity.ShouldNotBeNull();
     entity.Offspring.ShouldEqual(value);
 }
Exemplo n.º 12
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new EstablishmentNode { Ancestor = value };
     entity.ShouldNotBeNull();
     entity.Ancestor.ShouldEqual(value);
 }
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new EstablishmentEmailDomain { Establishment = value };
     entity.ShouldNotBeNull();
     entity.Establishment.ShouldEqual(value);
 }
Exemplo n.º 14
0
        public static bool EmailMatchesEntity(string email, IQueryEntities entities,
            IEnumerable<Expression<Func<Establishment, object>>> eagerLoad, out Establishment entity)
        {
            entity = entities.Query<Establishment>().EagerLoad(entities, eagerLoad).ByEmail(email);

            // return true (valid) if there is an entity
            return entity != null;
        }
Exemplo n.º 15
0
            public void ReturnsExistingAffiliation_WhenAlreadyAffiliated()
            {
                var establishment = new Establishment();
                var affiliation = new Affiliation { Establishment = establishment };
                var person = new Person
                {
                    Affiliations = new List<Affiliation> { affiliation }
                };

                var result = person.AffiliateWith(establishment);

                result.ShouldEqual(affiliation);
            }
            public void ReturnsNull_WhenIdCannotBeMatched()
            {
                const int id = 9;
                var query = new GetEstablishmentByIdQuery(id);
                var establishments = new Establishment[] {}.AsQueryable();
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict);
                entities.Setup(p => p.Query<Establishment>()).Returns(establishments);
                var handler = new GetEstablishmentByIdHandler(entities.Object);

                var result = handler.Handle(query);

                result.ShouldBeNull();
            }
Exemplo n.º 17
0
 private Place GetCountry(Establishment establishment)
 {
     var country = establishment.Location.Places.FirstOrDefault(e => e.IsCountry);
     if (country == null)
     {
         var parent = establishment.Parent;
         while (parent != null)
         {
             country = parent.Location.Places.FirstOrDefault(e => e.IsCountry);
             if (country != null) break;
             parent = parent.Parent;
         }
     }
     return country;
 }
Exemplo n.º 18
0
        public static bool IdMatchesEntity(int id, IQueryEntities entities,
            IEnumerable<Expression<Func<Establishment, object>>> eagerLoad, out Establishment entity)
        {
            if (id < 0)
            {
                entity = null;
                return false;
            }

            entity = entities.Query<Establishment>()
                .EagerLoad(entities, eagerLoad).By(id);

            // return true (valid) if there is an entity
            return entity != null;
        }
            public void ReturnsEstablishment_WhenIdCanBeMatched()
            {
                const int id = 6;
                var query = new GetEstablishmentByIdQuery(id);
                var establishment = new Establishment
                {
                    RevisionId = id,
                };
                var establishments = new[]
                {
                    establishment,
                }.AsQueryable();
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict);
                entities.Setup(p => p.Query<Establishment>()).Returns(establishments);
                var handler = new GetEstablishmentByIdHandler(entities.Object);

                var result = handler.Handle(query);

                result.ShouldNotBeNull();
                result.RevisionId.ShouldEqual(id);
            }
Exemplo n.º 20
0
 public static bool IdMatchesEntity(int id, IQueryEntities entities, out Establishment entity)
 {
     return IdMatchesEntity(id, entities, null, out entity);
 }
Exemplo n.º 21
0
 public static bool EstablishmentIsInstitutionWhenIsClaimingStudent(bool isClaimingStudent, Establishment establishment)
 {
     // return false when user is claiming student but establishment is not an academic institution
     return establishment != null && (establishment.IsInstitution || isClaimingStudent == false);
 }
            public void IsValidWhen_MatchesPerson_WithNonSamlLocalUser_AndConfirmedEmailAddress()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var person = new Person
                {
                    User = new User
                    {
                        Name = "*****@*****.**",
                    },
                    Emails = new[]
                    {
                        new EmailAddress
                        {
                            Value = validated.EmailAddress,
                            IsConfirmed = true,
                        },
                    },
                };
                var establishment = new Establishment
                {
                    IsMember = true,
                    EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld" }, },
                };
                var passwords = new Mock<IStorePasswords>(MockBehavior.Strict);
                passwords.Setup(m => m
                    .Exists(It.Is(IsSignedUpBasedOn(person))))
                    .Returns(true);
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new[] { person }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, passwords.Object);

                var results = validator.Validate(validated);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
                error.ShouldBeNull();
            }
            public void ValidWhen_IsTrue_AndEstablishmentIsInstitution()
            {
                const bool isClaimingStudent = true;
                var command = new CreateAffiliationCommand
                {
                    IsClaimingStudent = isClaimingStudent
                };
                var establishment = new Establishment
                {
                    Type = new EstablishmentType
                    {
                        Category = new EstablishmentCategory
                        {
                            Code = EstablishmentCategoryCode.Inst,
                        },
                    },
                };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new Person[] { }.AsQueryable);
                var validator = new CreateAffiliationValidator(entities.Object);

                var results = validator.Validate(command);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "IsClaimingStudent");
                error.ShouldBeNull();
            }
Exemplo n.º 24
0
        private static bool HasDefaultAffiliate(Establishment establishment, IPrincipal principal)
        {
            if (establishment == null) throw new ArgumentNullException("establishment");
            if (principal == null) throw new ArgumentNullException("principal");

            Func<Affiliation, bool> defaultAffiliation = a =>
                a.IsDefault && a.Person.User != null
                && a.Person.User.Name.Equals(principal.Identity.Name, StringComparison.OrdinalIgnoreCase);
            return establishment.Affiliates.Any(defaultAffiliation)
                || establishment.Ancestors.Any(n => n.Ancestor.Affiliates.Any(defaultAffiliation));
        }
Exemplo n.º 25
0
 public void IsInvalidWhen_MatchingEstablishment_IsNotMember()
 {
     const string emailAddress = "*****@*****.**";
     var establishment = new Establishment
     {
         IsMember = false,
         EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld", } }
     };
     var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
     entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
     var validator = new SignOnValidator(entities.Object);
     var model = new SignOnForm { EmailAddress = emailAddress };
     var results = validator.Validate(model);
     results.IsValid.ShouldBeFalse();
     results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
     var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
     error.ShouldNotBeNull();
     // ReSharper disable PossibleNullReferenceException
     error.ErrorMessage.ShouldEqual(string.Format(
         SignOnValidator.FailedBecauseEstablishmentIsNotEligible, emailAddress));
     // ReSharper restore PossibleNullReferenceException
 }
Exemplo n.º 26
0
 public void ReturnsNull_WhenNoNamesExist()
 {
     var establishment = new Establishment { Names = new List<EstablishmentName>() };
     var translatedName = establishment.TranslateNameTo("en");
     translatedName.ShouldBeNull();
 }
Exemplo n.º 27
0
        private void PushToSamlSso(Establishment establishment, string returnUrl)
        {
            if (establishment == null) return;

            // update the provider metadata
            _services.CommandHandler.Handle(
                new UpdateSamlSignOnMetadataCommand
                {
                    EstablishmentId = establishment.RevisionId,
                }
            );

            // clear the email from temp data
            TempData.SigningEmailAddress(null);

            // send the authn request
            _services.SamlServiceProvider.SendAuthnRequest(
                establishment.SamlSignOn.SsoLocation,
                establishment.SamlSignOn.SsoBinding.AsSaml2SsoBinding(),
                _services.ConfigurationManager.SamlRealServiceProviderEntityId,
                returnUrl ?? Url.Action(MVC.Identity.MyHome.Get()),
                HttpContext
            );
        }
Exemplo n.º 28
0
 public void IsValidWhen_IsValidEmailAddress_AndBelongsToMemberEstablishment()
 {
     var establishment = new Establishment
     {
         IsMember = true,
         EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld", } }
     };
     var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
     entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
     var validator = new SignOnValidator(entities.Object);
     var model = new SignOnForm { EmailAddress = "*****@*****.**" };
     var results = validator.Validate(model);
     var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
     error.ShouldBeNull();
 }
Exemplo n.º 29
0
 public static bool EmailMatchesEntity(string email, IQueryEntities entities, out Establishment entity)
 {
     return EmailMatchesEntity(email, entities, null, out entity);
 }
Exemplo n.º 30
0
        private ActionResult PushToSamlSsoExternal(Establishment establishment, string returnUrl)
        {
            if (establishment != null)
            {
                // update the provider metadata
                _updateSamlMetadata.Handle(
                    new UpdateSamlSignOnMetadata
                    {
                        EstablishmentId = establishment.RevisionId,
                    }
                );

                var callbackUrl = returnUrl ?? Url.Action(MVC.MyProfile.Index());
                callbackUrl = MakeAbsoluteUrl(callbackUrl);

                var redirectUrl = "https://develop.ucosmic.com";
                if (_configurationManager.SamlRealServiceProviderEntityId.StartsWith("https://preview.ucosmic.com"))
                {
                    redirectUrl = "https://preview.ucosmic.com";
                }

                redirectUrl = string.Format("{0}/sign-on/alpha-proxy/{1}/?returnUrl={2}", redirectUrl,
                    establishment.RevisionId, Server.UrlEncode(callbackUrl));
                return Redirect(redirectUrl);
            }

            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
Exemplo n.º 31
0
        public void Handle(CreateEstablishment command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var parent = command.ParentId.HasValue
                ? _entities.FindByPrimaryKey <Establishment>(command.ParentId.Value)
                : null;

            var type = _entities.FindByPrimaryKey <EstablishmentType>(command.TypeId);

            var entity = new Establishment
            {
                OfficialName = command.OfficialName,
                Parent       = parent,
                WebsiteUrl   = command.OfficialWebsiteUrl,
                IsMember     = command.IsMember,
                Type         = type,
                Location     = new EstablishmentLocation(),
            };

            // add official name to list
            entity.Names.Add(new EstablishmentName
            {
                Text           = command.OfficialName,
                IsOfficialName = true,
            });

            // add non-official names
            if (command.NonOfficialNames != null && command.NonOfficialNames.Any())
            {
                foreach (var nonOfficialName in command.NonOfficialNames)
                {
                    entity.Names.Add(new EstablishmentName
                    {
                        Text                  = nonOfficialName.Text,
                        IsFormerName          = nonOfficialName.IsDefunct,
                        TranslationToLanguage = nonOfficialName.TranslationToLanguageId.HasValue
                            ? _entities.FindByPrimaryKey <Language>(nonOfficialName.TranslationToLanguageId.Value)
                            : null,
                    });
                }
            }

            // add official url to list
            if (!string.IsNullOrWhiteSpace(command.OfficialWebsiteUrl))
            {
                entity.Urls.Add(new EstablishmentUrl
                {
                    Value         = command.OfficialWebsiteUrl,
                    IsOfficialUrl = true,
                });
            }

            // add non-official URL's
            if (command.NonOfficialUrls != null && command.NonOfficialUrls.Any())
            {
                foreach (var nonOfficialUrl in command.NonOfficialUrls)
                {
                    entity.Urls.Add(new EstablishmentUrl
                    {
                        Value       = nonOfficialUrl.Value,
                        IsFormerUrl = nonOfficialUrl.IsDefunct,
                    });
                }
            }

            // add email domains
            if (command.EmailDomains != null && command.EmailDomains.Any())
            {
                foreach (var emailDomain in command.EmailDomains)
                {
                    entity.EmailDomains.Add(new EstablishmentEmailDomain
                    {
                        Value = emailDomain,
                    });
                }
            }

            // apply coordinates
            if (command.FindPlacesByCoordinates &&
                command.CenterLatitude.HasValue && command.CenterLongitude.HasValue)
            {
                var woeId = _queryProcessor.Execute(new WoeIdByCoordinates(
                                                        command.CenterLatitude.Value, command.CenterLongitude.Value));
                var place = _queryProcessor.Execute(
                    new GetPlaceByWoeIdQuery {
                    WoeId = woeId
                });
                var places = place.Ancestors.OrderByDescending(n => n.Separation)
                             .Select(a => a.Ancestor).ToList();
                places.Add(place);
                entity.Location.Center      = new Coordinates(command.CenterLatitude, command.CenterLongitude);
                entity.Location.BoundingBox = place.BoundingBox;
                entity.Location.Places      = places;
            }

            // apply addresses
            if (command.Addresses != null && command.Addresses.Any())
            {
                foreach (var address in command.Addresses)
                {
                    entity.Location.Addresses.Add(new EstablishmentAddress
                    {
                        Text = address.Text,
                        TranslationToLanguage = _entities.FindByPrimaryKey <Language>(address.TranslationToLanguageId),
                    });
                }
            }

            // apply contact info
            if (command.PublicContactInfo != null)
            {
                entity.PublicContactInfo = new EstablishmentContactInfo
                {
                    Email = command.PublicContactInfo.Email,
                    Phone = command.PublicContactInfo.Phone,
                    Fax   = command.PublicContactInfo.Fax,
                };
            }

            // apply CEEB / UCosmic code
            if (!string.IsNullOrWhiteSpace(command.UCosmicCode))
            {
                entity.UCosmicCode = command.UCosmicCode;
            }

            _entities.Create(entity);
            _hierarchy.Handle(new UpdateEstablishmentHierarchyCommand(entity));
            command.CreatedEstablishment = entity;
        }