Inheritance: RevisableEntity
コード例 #1
0
 public void HasGetSet()
 {
     var value = new List<Affiliation> { new Affiliation() };
     var entity = new Establishment { Affiliates = value };
     entity.ShouldNotBeNull();
     entity.Affiliates.ShouldEqual(value);
 }
コード例 #2
0
ファイル: Person.cs プロジェクト: ucosmic/UCosmicAlpha
        /* 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;
        }
コード例 #3
0
ファイル: RoleGrantFacts.cs プロジェクト: danludwig/UCosmic
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new RoleGrant { ForEstablishment = value };
     entity.ShouldNotBeNull();
     entity.ForEstablishment.ShouldEqual(value);
 }
コード例 #4
0
 public void HasGetSet()
 {
     var value = new EstablishmentContactInfo();
     var entity = new Establishment { PartnerContactInfo = value };
     entity.ShouldNotBeNull();
     entity.PartnerContactInfo.ShouldEqual(value);
 }
コード例 #5
0
            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();
            }
コード例 #6
0
            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
            }
コード例 #7
0
ファイル: Person.cs プロジェクト: saibalghosh/UCosmic
        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;
        }
コード例 #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;
        }
コード例 #9
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new InstitutionalAgreementParticipant { Establishment = value };
     entity.ShouldNotBeNull();
     entity.Establishment.ShouldEqual(value);
 }
コード例 #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;
        }
コード例 #11
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new EstablishmentNode { Offspring = value };
     entity.ShouldNotBeNull();
     entity.Offspring.ShouldEqual(value);
 }
コード例 #12
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new EstablishmentNode { Ancestor = value };
     entity.ShouldNotBeNull();
     entity.Ancestor.ShouldEqual(value);
 }
コード例 #13
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new EstablishmentEmailDomain { Establishment = value };
     entity.ShouldNotBeNull();
     entity.Establishment.ShouldEqual(value);
 }
コード例 #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;
        }
コード例 #15
0
ファイル: PersonFacts.cs プロジェクト: saibalghosh/UCosmic
            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);
            }
コード例 #16
0
            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();
            }
コード例 #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;
 }
コード例 #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;
        }
コード例 #19
0
            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);
            }
コード例 #20
0
 public static bool IdMatchesEntity(int id, IQueryEntities entities, out Establishment entity)
 {
     return IdMatchesEntity(id, entities, null, out entity);
 }
コード例 #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);
 }
コード例 #22
0
            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();
            }
コード例 #23
0
            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();
            }
コード例 #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));
        }
コード例 #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
 }
コード例 #26
0
 public void ReturnsNull_WhenNoNamesExist()
 {
     var establishment = new Establishment { Names = new List<EstablishmentName>() };
     var translatedName = establishment.TranslateNameTo("en");
     translatedName.ShouldBeNull();
 }
コード例 #27
0
ファイル: SignOnController.cs プロジェクト: danludwig/UCosmic
        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
            );
        }
コード例 #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();
 }
コード例 #29
0
 public static bool EmailMatchesEntity(string email, IQueryEntities entities, out Establishment entity)
 {
     return EmailMatchesEntity(email, entities, null, out entity);
 }
コード例 #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);
        }
コード例 #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;
        }