public void IncrementsChangeCount_WhenIsClaimingStaff_IsDifferent() { Affiliation outAffiliation = null; const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var command = new UpdateMyAffiliationCommand { Principal = principal, EstablishmentId = 4, IsClaimingStaff = true, }; var affiliation = new Affiliation { IsClaimingStaff = false, IsAcknowledged = true, EstablishmentId = command.EstablishmentId, Person = new Person { User = new User { Name = principal.Identity.Name } }, }; var affiliationBasedOnCommand = AffiliationBasedOn(command); var entities = new Mock <ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get <Affiliation>()).Returns(new[] { affiliation }.AsQueryable); entities.Setup(m => m.Update(It.Is(affiliationBasedOnCommand))) .Callback((Entity entity) => outAffiliation = (Affiliation)entity); var handler = new UpdateMyAffiliationHandler(entities.Object); handler.Handle(command); command.ChangeCount.ShouldEqual(1); outAffiliation.IsClaimingStaff.ShouldEqual(command.IsClaimingStaff); }
public void UpdatesAffiliation_WhenFieldsHaveChanged() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var command = new UpdateMyAffiliationCommand { Principal = principal, EstablishmentId = 4, }; var affiliation = new Affiliation { EstablishmentId = command.EstablishmentId, Person = new Person { User = new User { Name = principal.Identity.Name } }, }; var entities = new Mock <ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get <Affiliation>()).Returns(new[] { affiliation }.AsQueryable); entities.Setup(m => m.Update(It.Is(AffiliationBasedOn(command)))); var handler = new UpdateMyAffiliationHandler(entities.Object); handler.Handle(command); entities.Verify(m => m.Update(It.Is(AffiliationBasedOn(command))), Times.Once()); }
public void CreatesAffiliation_WithEstablishmentId() { Affiliation outEntity = null; const int personId = 13; const int establishmentId = 13; var person = new Person { RevisionId = personId, }; var command = new CreateAffiliationCommand { PersonId = personId, EstablishmentId = establishmentId, }; var entities = new Mock <ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get <Person>()).Returns(new[] { person }.AsQueryable); entities.Setup(m => m.Create(It.Is(AffiliationBasedOn(command)))) .Callback((Entity entity) => outEntity = (Affiliation)entity); var handler = new CreateAffiliationHandler(entities.Object); handler.Handle(command); outEntity.ShouldNotBeNull(); outEntity.EstablishmentId.ShouldEqual(command.EstablishmentId); }
public void CreatesAffiliation_WithNotIsDefault_WhenPersonAlreadyHasDefaultAffiliation() { Affiliation outEntity = null; const int personId = 13; var person = new Person { RevisionId = personId, Affiliations = new Collection <Affiliation> { new Affiliation { IsDefault = true, } } }; var command = new CreateAffiliationCommand { PersonId = personId, }; var entities = new Mock <ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get <Person>()).Returns(new[] { person }.AsQueryable); entities.Setup(m => m.Create(It.Is(AffiliationBasedOn(command)))) .Callback((Entity entity) => outEntity = (Affiliation)entity); var handler = new CreateAffiliationHandler(entities.Object); handler.Handle(command); outEntity.ShouldNotBeNull(); outEntity.IsDefault.ShouldBeFalse(); }
public void ExecutesQuery_ToGetAffiliation_FromPrincipalAndEstablishmentId() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var command = new UpdateMyAffiliationCommand { Principal = principal, }; var affiliation = new Affiliation { EstablishmentId = command.EstablishmentId, Person = new Person { User = new User { Name = principal.Identity.Name } }, }; var entities = new Mock <ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get <Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new UpdateMyAffiliationHandler(entities.Object); NullReferenceException exception = null; try { handler.Handle(command); } catch (NullReferenceException ex) { exception = ex; } entities.Verify(m => m.Get <Affiliation>(), Times.Once()); exception.ShouldNotBeNull(); }
public void HasGetSet() { const string value = "text"; var entity = new Affiliation { JobTitles = value }; entity.ShouldNotBeNull(); entity.JobTitles.ShouldEqual(value); }
public void Handle(CreateAffiliationCommand command) { if (command == null) { throw new ArgumentNullException("command"); } // get the person var person = _entities.Get <Person>() .EagerLoad(_entities, new Expression <Func <Person, object> >[] { p => p.Affiliations, }) .By(command.PersonId); // construct the affiliation var affiliation = new Affiliation { EstablishmentId = command.EstablishmentId, IsClaimingStudent = command.IsClaimingStudent, IsClaimingEmployee = command.IsClaimingEmployee, IsDefault = !person.Affiliations.Any(a => a.IsDefault), }; person.Affiliations.Add(affiliation); // store _entities.Create(affiliation); }
public void ReturnsNull_WhenQueryForUser_ReturnsNull() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var query = new GetMyAffiliationByEstablishmentIdQuery { Principal = principal, }; var affiliation = new Affiliation { Person = new Person { User = new User { Name = "something else" } }, }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new GetMyAffiliationByEstablishmentIdHandler(entities.Object); var result = handler.Handle(query); result.ShouldBeNull(); }
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); }
public void Handle(CreateAffiliation command) { if (command == null) { throw new ArgumentNullException("command"); } var personId = !command.PersonId.HasValue ? _queryProcessor.Execute(new MyPerson(command.Principal)).RevisionId : command.PersonId.Value; var entity = new Affiliation { PersonId = personId, EstablishmentId = command.EstablishmentId, FacultyRankId = command.FacultyRankId, JobTitles = command.JobTitles, }; _entities.Create(entity); if (command.NoCommit) { command.Created = entity; return; } _entities.SaveChanges(); command.Created = _queryProcessor.Execute(new AffiliationByPrimaryKey(entity.PersonId, entity.EstablishmentId)); }
public void ExecutesQuery_ToGetAffiliation_FromPrincipalAndEstablishmentId() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var command = new UpdateMyAffiliationCommand { Principal = principal, }; var affiliation = new Affiliation { EstablishmentId = command.EstablishmentId, Person = new Person { User = new User { Name = principal.Identity.Name } }, }; var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get<Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new UpdateMyAffiliationHandler(entities.Object); NullReferenceException exception = null; try { handler.Handle(command); } catch (NullReferenceException ex) { exception = ex; } entities.Verify(m => m.Get<Affiliation>(), Times.Once()); exception.ShouldNotBeNull(); }
public void ExecutesQuery_ToGetUserByName() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var query = new GetMyAffiliationByEstablishmentIdQuery { Principal = principal, }; var affiliation = new Affiliation { Person = new Person { User = new User { Name = principal.Identity.Name } } }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new GetMyAffiliationByEstablishmentIdHandler(entities.Object); handler.Handle(query); entities.Verify(m => m.Query <Affiliation>(), Times.Once()); }
public void HasGetSet() { const int value = 6; var entity = new Affiliation { EstablishmentId = value }; entity.ShouldNotBeNull(); entity.EstablishmentId.ShouldEqual(value); }
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; }
public void HasGetSet() { const int value = 14; var entity = new Affiliation { PersonId = value }; entity.ShouldNotBeNull(); entity.PersonId.ShouldEqual(value); }
public void HasGetSet() { const bool value = true; var entity = new Affiliation { IsAcknowledged = value }; entity.ShouldNotBeNull(); entity.IsAcknowledged.ShouldEqual(value); }
public void HasGetSet() { const bool value = true; var entity = new Affiliation { IsClaimingStudent = value }; entity.ShouldNotBeNull(); entity.IsClaimingStudent.ShouldEqual(value); }
public void HasGetSet() { const int value = 14; var entity = new Affiliation { PersonId = value }; entity.ShouldNotBeNull(); entity.PersonId.ShouldEqual(value); }
public void HasGetSet() { const bool value = true; var entity = new Affiliation { IsClaimingInternationalOffice = value }; entity.ShouldNotBeNull(); entity.IsClaimingInternationalOffice.ShouldEqual(value); }
public void HasGetSet() { const int value = 6; var entity = new Affiliation { EstablishmentId = value }; entity.ShouldNotBeNull(); entity.EstablishmentId.ShouldEqual(value); }
public void HasGetSet() { const string value = "text"; var entity = new Affiliation { JobTitles = value }; entity.ShouldNotBeNull(); entity.JobTitles.ShouldEqual(value); }
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 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 ReturnsFriendlyInfo() { var entity = new Affiliation { Person = new Person { DisplayName = "display name", }, Establishment = new Establishment { OfficialName = "official name", }, }; var result = entity.ToString(); result.ShouldEqual(string.Format("{0} - {1}", entity.Person.DisplayName, entity.Establishment.OfficialName)); }
public void MapsEmployeeOrStudentAffiliation_ToNull_WhenInstitutionalAffiliationIsNotAcknowledged() { var entity = new Affiliation { Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, }, }, }, }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.EmployeeOrStudentAffiliation.ShouldBeNull(); }
public void ExecutesQuery_ToGetUserByName() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var query = new GetMyAffiliationByEstablishmentIdQuery { Principal = principal, }; var affiliation = new Affiliation { Person = new Person { User = new User { Name = principal.Identity.Name } } }; var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query<Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new GetMyAffiliationByEstablishmentIdHandler(entities.Object); handler.Handle(query); entities.Verify(m => m.Query<Affiliation>(), Times.Once()); }
public void ReturnsNull_WhenQueryForUser_ReturnsNull() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var query = new GetMyAffiliationByEstablishmentIdQuery { Principal = principal, }; var affiliation = new Affiliation { Person = new Person { User = new User { Name = "something else" } }, }; var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query<Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new GetMyAffiliationByEstablishmentIdHandler(entities.Object); var result = handler.Handle(query); result.ShouldBeNull(); }
public void MapsEmployeeOrStudentAffiliation_ToEmployeeOnly_WhenInstitutionalAffiliationIsAcknowledged_AndIsClaimingEmployee_AndIsNotClaimingStudent() { var entity = new Affiliation { IsAcknowledged = true, IsClaimingEmployee = true, IsClaimingStudent = false, Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, }, }, }, }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.EmployeeOrStudentAffiliation.ShouldEqual(EmployeeOrStudentAffiliate.EmployeeOnly); }
public void MapsEmployeeOrStudentAffiliation_ToEmployeeOnly_WhenEstablishmentIsNotInstitution() { var entity = new Affiliation { IsAcknowledged = true, IsClaimingEmployee = false, IsClaimingStudent = true, Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = "not an institution" } } } }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.EmployeeOrStudentAffiliation.ShouldEqual(EmployeeOrStudentAffiliate.EmployeeOnly); }
public void UpdatesAffiliation_WhenFieldsHaveChanged() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var command = new UpdateMyAffiliationCommand { Principal = principal, EstablishmentId = 4, }; var affiliation = new Affiliation { EstablishmentId = command.EstablishmentId, Person = new Person { User = new User { Name = principal.Identity.Name } }, }; var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get<Affiliation>()).Returns(new[] { affiliation }.AsQueryable); entities.Setup(m => m.Update(It.Is(AffiliationBasedOn(command)))); var handler = new UpdateMyAffiliationHandler(entities.Object); handler.Handle(command); entities.Verify(m => m.Update(It.Is(AffiliationBasedOn(command))), Times.Once()); }
public void HasGetSet() { const bool value = true; var entity = new Affiliation { IsClaimingStudent = value }; entity.ShouldNotBeNull(); entity.IsClaimingStudent.ShouldEqual(value); }
public void ReturnsFriendlyInfo() { var entity = new Affiliation { Person = new Person { DisplayName = "display name", }, Establishment = new Establishment { OfficialName = "official name", }, }; var result = entity.ToString(); result.ShouldEqual(string.Format("{0} - {1}", entity.Person.DisplayName, entity.Establishment.OfficialName)); }
public void HasGetSet() { const bool value = true; var entity = new Affiliation { IsClaimingInternationalOffice = value }; entity.ShouldNotBeNull(); entity.IsClaimingInternationalOffice.ShouldEqual(value); }
public void IncrementsChangeCount_WhenIsClaimingStaff_IsDifferent() { Affiliation outAffiliation = null; const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var command = new UpdateMyAffiliationCommand { Principal = principal, EstablishmentId = 4, IsClaimingStaff = true, }; var affiliation = new Affiliation { IsClaimingStaff = false, IsAcknowledged = true, EstablishmentId = command.EstablishmentId, Person = new Person { User = new User { Name = principal.Identity.Name } }, }; var affiliationBasedOnCommand = AffiliationBasedOn(command); var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Get<Affiliation>()).Returns(new[] { affiliation }.AsQueryable); entities.Setup(m => m.Update(It.Is(affiliationBasedOnCommand))) .Callback((Entity entity) => outAffiliation = (Affiliation)entity); var handler = new UpdateMyAffiliationHandler(entities.Object); handler.Handle(command); command.ChangeCount.ShouldEqual(1); outAffiliation.IsClaimingStaff.ShouldEqual(command.IsClaimingStaff); }
public void HasGetSet() { const bool value = true; var entity = new Affiliation { IsAcknowledged = value }; entity.ShouldNotBeNull(); entity.IsAcknowledged.ShouldEqual(value); }
public void MapsEstablishmentIsInsitution() { var entity = new Affiliation { Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, }, }, }, }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.EstablishmentIsInstitution.ShouldBeTrue(); }
public void MapsIsClaimingStaff() { var entity = new Affiliation { IsClaimingStaff = true, Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, }, }, }, }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.IsClaimingStaff.ShouldEqual(entity.IsClaimingStaff); }
public void MapsEstablishmentId() { const int establishmentId = 92; var entity = new Affiliation { EstablishmentId = establishmentId, Establishment = new Establishment { RevisionId = establishmentId, Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, } } } }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.EstablishmentId.ShouldEqual(entity.EstablishmentId); }
public void IgnoresReturnUrl() { var entity = new Affiliation { Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, } } } }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.ShouldNotBeNull(); model.ReturnUrl.ShouldBeNull(); }
public void MapsJobTitles() { var entity = new Affiliation { JobTitles = "test", Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, } } } }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.JobTitles.ShouldEqual(entity.JobTitles); }
public void MapsEstablishmentOfficialName() { var entity = new Affiliation { Establishment = new Establishment { OfficialName = "test", Type = new EstablishmentType { Category = new EstablishmentCategory { Code = "not a real value", }, }, }, }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.EstablishmentOfficialName.ShouldEqual(entity.Establishment.OfficialName); }
public void MapsIsAcknowledged() { var entity = new Affiliation { IsAcknowledged = true, Establishment = new Establishment { Type = new EstablishmentType { Category = new EstablishmentCategory { Code = EstablishmentCategoryCode.Inst, }, }, }, }; var model = Mapper.Map<UpdateAffiliationForm>(entity); model.IsAcknowledged.ShouldEqual(entity.IsAcknowledged); }