示例#1
0
        public void TestCreateGetParticipantExchangeVisitorDTOByIdQuery()
        {
            var project = new Project
            {
                ProjectId = 100
            };
            var participant = new Participant
            {
                ParticipantId = 2,
                ProjectId     = project.ProjectId,
                Project       = project
            };

            var visitor = new ParticipantExchangeVisitor
            {
                ParticipantId = participant.ParticipantId,
                Participant   = participant,
            };

            context.Projects.Add(project);
            context.Participants.Add(participant);
            context.ParticipantExchangeVisitors.Add(visitor);
            Action <ParticipantExchangeVisitorDTO> tester = (result) =>
            {
                Assert.IsNotNull(result);
                Assert.AreEqual(project.ProjectId, result.ProjectId);
                Assert.AreEqual(participant.ParticipantId, result.ParticipantId);
            };
            var queryResult = ParticipantExchangeVisitorQueries.CreateGetParticipantExchangeVisitorDTOByIdQuery(context, project.ProjectId, participant.ParticipantId).ToList();

            Assert.AreEqual(1, queryResult.Count());
            tester(queryResult.First());
        }
示例#2
0
        public void TestCreateGetParticipantExchangeVisitorDTOByIdQuery_InvalidProjectId()
        {
            var project = new Project
            {
                ProjectId = 100
            };
            var participant = new Participant
            {
                ParticipantId = 2,
                ProjectId     = project.ProjectId,
                Project       = project
            };

            var visitor = new ParticipantExchangeVisitor
            {
                ParticipantId = participant.ParticipantId,
                Participant   = participant,
            };

            context.Projects.Add(project);
            context.Participants.Add(participant);
            context.ParticipantExchangeVisitors.Add(visitor);
            var queryResult = ParticipantExchangeVisitorQueries.CreateGetParticipantExchangeVisitorDTOByIdQuery(context, project.ProjectId, participant.ParticipantId).ToList();

            Assert.AreEqual(1, queryResult.Count());

            queryResult = ParticipantExchangeVisitorQueries.CreateGetParticipantExchangeVisitorDTOByIdQuery(context, project.ProjectId + 1, participant.ParticipantId).ToList();
            Assert.AreEqual(0, queryResult.Count());
        }
示例#3
0
        public async Task TestGetParticipantExchangeVisitorById_ParticipantDoesNotExist()
        {
            var project = new Project
            {
                ProjectId = 100
            };
            var participant = new Participant
            {
                ParticipantId = 2,
                ProjectId     = project.ProjectId,
                Project       = project
            };

            var visitor = new ParticipantExchangeVisitor
            {
                ParticipantId = participant.ParticipantId,
                Participant   = participant,
            };

            context.Projects.Add(project);
            context.Participants.Add(participant);
            context.ParticipantExchangeVisitors.Add(visitor);
            var dto      = service.GetParticipantExchangeVisitorById(project.ProjectId, participant.ParticipantId);
            var dtoAsync = await service.GetParticipantExchangeVisitorByIdAsync(project.ProjectId, participant.ParticipantId);

            Assert.IsNotNull(dto);
            Assert.IsNotNull(dtoAsync);

            dto      = service.GetParticipantExchangeVisitorById(project.ProjectId, participant.ParticipantId + 1);
            dtoAsync = await service.GetParticipantExchangeVisitorByIdAsync(project.ProjectId, participant.ParticipantId + 1);

            Assert.IsNull(dto);
            Assert.IsNull(dtoAsync);
        }
 private void DoDelete(
     DeletedParticipant deletedParticipant,
     Project project,
     Participant participant,
     ParticipantPerson person,
     ParticipantExchangeVisitor exchangeVisitor,
     IEnumerable <ParticipantPersonSevisCommStatus> statii,
     IEnumerable <MoneyFlow> participantSourceMoneyFlows,
     IEnumerable <MoneyFlow> participantRecipientMoneyFlows)
 {
     Contract.Requires(participant != null, "The participant must not be null.");
     Contract.Requires(project != null, "The project must not be null.");
     Context.ParticipantPersonSevisCommStatuses.RemoveRange(statii);
     Context.MoneyFlows.RemoveRange(participantSourceMoneyFlows);
     Context.MoneyFlows.RemoveRange(participantRecipientMoneyFlows);
     if (exchangeVisitor != null)
     {
         Context.ParticipantExchangeVisitors.Remove(exchangeVisitor);
     }
     if (person != null)
     {
         Context.ParticipantPersons.Remove(person);
     }
     Context.Participants.Remove(participant);
     deletedParticipant.Audit.SetHistory(project);
 }
        private void DoUpdate(ParticipantExchangeVisitor participantExchangeVisitor, UpdatedParticipantExchangeVisitor updatedParticipantExchangeVisitor)
        {
            //participantPersonValidator.ValidateUpdate(GetUpdatedPersonParticipantValidationEntity(participantType));
            updatedParticipantExchangeVisitor.Audit.SetHistory(participantExchangeVisitor);

            participantExchangeVisitor.FieldOfStudyId       = updatedParticipantExchangeVisitor.FieldOfStudyId;
            participantExchangeVisitor.PositionId           = updatedParticipantExchangeVisitor.PositionId;
            participantExchangeVisitor.ProgramCategoryId    = updatedParticipantExchangeVisitor.ProgramCategoryId;
            participantExchangeVisitor.FundingSponsor       = updatedParticipantExchangeVisitor.FundingSponsor;
            participantExchangeVisitor.FundingPersonal      = updatedParticipantExchangeVisitor.FundingPersonal;
            participantExchangeVisitor.FundingVisGovt       = updatedParticipantExchangeVisitor.FundingVisGovt;
            participantExchangeVisitor.FundingVisBNC        = updatedParticipantExchangeVisitor.FundingVisBNC;
            participantExchangeVisitor.FundingGovtAgency1   = updatedParticipantExchangeVisitor.FundingGovtAgency1;
            participantExchangeVisitor.GovtAgency1Id        = updatedParticipantExchangeVisitor.GovtAgency1Id;
            participantExchangeVisitor.GovtAgency1OtherName = updatedParticipantExchangeVisitor.GovtAgency1OtherName;
            participantExchangeVisitor.FundingGovtAgency2   = updatedParticipantExchangeVisitor.FundingGovtAgency2;
            participantExchangeVisitor.GovtAgency2Id        = updatedParticipantExchangeVisitor.GovtAgency2Id;
            participantExchangeVisitor.GovtAgency2OtherName = updatedParticipantExchangeVisitor.GovtAgency2OtherName;
            participantExchangeVisitor.FundingIntlOrg1      = updatedParticipantExchangeVisitor.FundingIntlOrg1;
            participantExchangeVisitor.IntlOrg1Id           = updatedParticipantExchangeVisitor.IntlOrg1Id;
            participantExchangeVisitor.IntlOrg1OtherName    = updatedParticipantExchangeVisitor.IntlOrg1OtherName;
            participantExchangeVisitor.FundingIntlOrg2      = updatedParticipantExchangeVisitor.FundingIntlOrg2;
            participantExchangeVisitor.IntlOrg2Id           = updatedParticipantExchangeVisitor.IntlOrg2Id;
            participantExchangeVisitor.IntlOrg2OtherName    = updatedParticipantExchangeVisitor.IntlOrg2OtherName;
            participantExchangeVisitor.FundingOther         = updatedParticipantExchangeVisitor.FundingOther;
            participantExchangeVisitor.OtherName            = updatedParticipantExchangeVisitor.OtherName;
            participantExchangeVisitor.FundingTotal         = updatedParticipantExchangeVisitor.FundingTotal;
        }
示例#6
0
        public async Task TestGetParticipantExchangeVisitorById()
        {
            var project = new Project
            {
                ProjectId = 100
            };
            var participant = new Participant
            {
                ParticipantId = 2,
                ProjectId     = project.ProjectId,
                Project       = project
            };

            var visitor = new ParticipantExchangeVisitor
            {
                ParticipantId = participant.ParticipantId,
                Participant   = participant,
            };

            context.Projects.Add(project);
            context.Participants.Add(participant);
            context.ParticipantExchangeVisitors.Add(visitor);
            Action <ParticipantExchangeVisitorDTO> tester = (result) =>
            {
                Assert.IsNotNull(result);
                Assert.AreEqual(project.ProjectId, result.ProjectId);
                Assert.AreEqual(participant.ParticipantId, result.ParticipantId);
            };
            var dto      = service.GetParticipantExchangeVisitorById(project.ProjectId, participant.ParticipantId);
            var dtoAsync = await service.GetParticipantExchangeVisitorByIdAsync(project.ProjectId, participant.ParticipantId);

            tester(dto);
            tester(dtoAsync);
        }
        /// <summary>
        /// Returns the financial info of the participant.
        /// </summary>
        /// <param name="participantExchangeVisitor">The participant.</param>
        /// <returns>The financial info for the exchange visitor.</returns>
        public FinancialInfo GetFinancialInfo(ParticipantExchangeVisitor participantExchangeVisitor)
        {
            Contract.Requires(participantExchangeVisitor != null, "The participant exchange visitor must not be null.");
            var internationFundingDTO = ExchangeVisitorQueries.CreateGetInternationalFundingQuery(this.Context, participantExchangeVisitor.ParticipantId).FirstOrDefault();
            var usFundingDTO          = ExchangeVisitorQueries.CreateGetUSFundingQuery(this.Context, participantExchangeVisitor.ParticipantId).FirstOrDefault();

            return(GetFinancialInfo(participantExchangeVisitor, internationFundingDTO, usFundingDTO));
        }
        private void DoCreateParticipantExchangeVistor(int participantId, User creator)
        {
            var newParticipantExchangeVisitor = new NewParticipantExchangeVisitor(creator, participantId);
            var participantExchangeVisitor    = new ParticipantExchangeVisitor();

            participantExchangeVisitor.ParticipantId = participantId;
            newParticipantExchangeVisitor.Audit.SetHistory(participantExchangeVisitor);
            Context.ParticipantExchangeVisitors.Add(participantExchangeVisitor);
        }
        /// <summary>
        /// Returns sevis participant financial information.
        /// </summary>
        /// <param name="participantExchangeVisitor">The exchange visitor.</param>
        /// <param name="orgFunding">The international organization funding.</param>
        /// <param name="usFunding">The US government funding for the participant.</param>
        /// <returns>The financial info object.</returns>
        public FinancialInfo GetFinancialInfo(ParticipantExchangeVisitor participantExchangeVisitor, ExchangeVisitorFundingDTO orgFunding, ExchangeVisitorFundingDTO usFunding)
        {
            Contract.Requires(participantExchangeVisitor != null, "The participant exchange visitor must not be null.");
            Func <decimal?, string> getFundingAsWholeDollarString = (value) =>
            {
                if (value.HasValue && value.Value > 0.0m)
                {
                    return(((int)value.Value).ToString());
                }
                else
                {
                    return(null);
                }
            };

            var receivedUsGovtFunds = false;

            if ((participantExchangeVisitor.FundingGovtAgency1.HasValue && participantExchangeVisitor.FundingGovtAgency1.Value > 0.0m) ||
                (participantExchangeVisitor.FundingGovtAgency2.HasValue && participantExchangeVisitor.FundingGovtAgency2.Value > 0.0m))
            {
                receivedUsGovtFunds = true;
            }
            var   programSponsorFunds = getFundingAsWholeDollarString(participantExchangeVisitor.FundingSponsor);
            Other other = null;

            if (participantExchangeVisitor.FundingOther.HasValue && participantExchangeVisitor.FundingOther.Value > 0.0m)
            {
                other = new Other(
                    name: participantExchangeVisitor.OtherName,
                    amount: getFundingAsWholeDollarString(participantExchangeVisitor.FundingOther));
            }

            var otherFunds = new OtherFunds(
                exchangeVisitorGovernment: getFundingAsWholeDollarString(participantExchangeVisitor.FundingVisGovt),
                binationalCommission: getFundingAsWholeDollarString(participantExchangeVisitor.FundingVisBNC),
                personal: getFundingAsWholeDollarString(participantExchangeVisitor.FundingPersonal),
                usGovernmentFunding: usFunding != null && !usFunding.IsEmpty() ? usFunding.GetUSGovt() : null,
                internationalFunding: orgFunding != null && !orgFunding.IsEmpty() ? orgFunding.GetInternational() : null,
                other: other);

            var financialInfo = new FinancialInfo(
                printForm: true,
                receivedUSGovtFunds: receivedUsGovtFunds,
                programSponsorFunds: programSponsorFunds,
                otherFunds: otherFunds);

            return(financialInfo);
        }
        /// <summary>
        /// Returns the person model for an exchange visitor.
        /// </summary>
        /// <param name="biography">The biography of the participant.</param>
        /// <param name="participantExchangeVisitor">The participant exchange visitor record.  This record should have the program category and position pre-loaded.</param>
        /// <param name="subjectFieldDTO">The field of study of the participant.</param>
        /// <param name="siteOfActivityAddress">the site of activity of the exchange visitor, i.e. C Street state dept.</param>
        /// <returns>The person model for the exchange visitor.</returns>
        public ECA.Business.Validation.Sevis.Bio.Person GetPerson(
            BiographicalDTO biography,
            ParticipantExchangeVisitor participantExchangeVisitor,
            SubjectFieldDTO subjectFieldDTO,
            AddressDTO siteOfActivityAddress)
        {
            Contract.Requires(biography != null, "The biography should not be null.");
            Contract.Requires(participantExchangeVisitor != null, "The participant exchange visitor must not be null.");
            Contract.Requires(siteOfActivityAddress != null, "The site of activity address must not be null.");
            SubjectField subjectField = null;
            FullName     fullName     = null;

            if (subjectFieldDTO != null)
            {
                subjectField = subjectFieldDTO.GetSubjectField();
            }
            if (biography.FullName != null)
            {
                fullName = biography.FullName.GetFullName();
            }
            var instance = new ECA.Business.Validation.Sevis.Bio.Person(
                fullName: fullName,
                birthCity: biography.BirthCity,
                birthCountryCode: biography.BirthCountryCode,
                birthDate: biography.BirthDate,
                citizenshipCountryCode: biography.CitizenshipCountryCode,
                emailAddress: biography.EmailAddress,
                gender: biography.Gender,
                permanentResidenceCountryCode: biography.PermanentResidenceCountryCode,
                phoneNumber: biography.PhoneNumber,
                remarks: null,
                positionCode: participantExchangeVisitor.Position != null ? participantExchangeVisitor.Position.PositionCode : null,
                programCategoryCode: participantExchangeVisitor.ProgramCategory != null ? participantExchangeVisitor.ProgramCategory.ProgramCategoryCode : null,
                mailAddress: biography.MailAddress,
                participantId: participantExchangeVisitor.ParticipantId,
                usAddress: siteOfActivityAddress,
                personId: biography.PersonId,
                printForm: true,
                subjectField: subjectField
                );

            return(instance);
        }
示例#11
0
 private void CreateParticipantExchangeVisitors(List <Participant> participants)
 {
     foreach (var participant in participants)
     {
         if (participant.ParticipantPerson == null)
         {
             var participantPerson = new ParticipantPerson
             {
                 Participant = participant
             };
             Context.ParticipantPersons.Add(participantPerson);
         }
         var participantExchangeVisitor = new ParticipantExchangeVisitor
         {
             Participant       = participant,
             ParticipantPerson = participant.ParticipantPerson
         };
         Context.ParticipantExchangeVisitors.Add(participantExchangeVisitor);
     }
 }
示例#12
0
        private void CreateParticipantExchangeVisitor(Participant participant, Project project, DefaultExchangeVisitorFunding defaultExchangeVisitorFunding)
        {
            if (project.VisitorTypeId == VisitorType.ExchangeVisitor.Id)
            {
                var participantExchangeVisitor = new ParticipantExchangeVisitor
                {
                    Participant = participant
                };

                if (defaultExchangeVisitorFunding != null)
                {
                    participantExchangeVisitor.FundingSponsor       = defaultExchangeVisitorFunding.FundingSponsor;
                    participantExchangeVisitor.FundingPersonal      = defaultExchangeVisitorFunding.FundingPersonal;
                    participantExchangeVisitor.FundingVisGovt       = defaultExchangeVisitorFunding.FundingVisGovt;
                    participantExchangeVisitor.FundingVisBNC        = defaultExchangeVisitorFunding.FundingVisBNC;
                    participantExchangeVisitor.FundingGovtAgency1   = defaultExchangeVisitorFunding.FundingGovtAgency1;
                    participantExchangeVisitor.GovtAgency1Id        = defaultExchangeVisitorFunding.GovtAgency1Id;
                    participantExchangeVisitor.GovtAgency1OtherName = defaultExchangeVisitorFunding.GovtAgency1OtherName;
                    participantExchangeVisitor.FundingGovtAgency2   = defaultExchangeVisitorFunding.FundingGovtAgency2;
                    participantExchangeVisitor.GovtAgency2Id        = defaultExchangeVisitorFunding.GovtAgency2Id;
                    participantExchangeVisitor.GovtAgency2OtherName = defaultExchangeVisitorFunding.GovtAgency2OtherName;
                    participantExchangeVisitor.FundingIntlOrg1      = defaultExchangeVisitorFunding.FundingIntlOrg1;
                    participantExchangeVisitor.IntlOrg1Id           = defaultExchangeVisitorFunding.IntlOrg1Id;
                    participantExchangeVisitor.IntlOrg1OtherName    = defaultExchangeVisitorFunding.IntlOrg1OtherName;
                    participantExchangeVisitor.FundingIntlOrg2      = defaultExchangeVisitorFunding.FundingIntlOrg2;
                    participantExchangeVisitor.IntlOrg2Id           = defaultExchangeVisitorFunding.IntlOrg2Id;
                    participantExchangeVisitor.IntlOrg2OtherName    = defaultExchangeVisitorFunding.IntlOrg2OtherName;
                    participantExchangeVisitor.FundingOther         = defaultExchangeVisitorFunding.FundingOther;
                    participantExchangeVisitor.OtherName            = defaultExchangeVisitorFunding.OtherName;
                    participantExchangeVisitor.FundingTotal         = defaultExchangeVisitorFunding.FundingTotal;
                }

                participant.ParticipantExchangeVisitor = participantExchangeVisitor;
                this.Context.ParticipantExchangeVisitors.Add(participantExchangeVisitor);
            }
        }
示例#13
0
        public void TestCreateGetParticipantExchangeVisitorsDTOQuery_CheckProperties()
        {
            var project = new Project
            {
                ProjectId = 100
            };
            var participant = new Participant
            {
                ParticipantId = 2,
                ProjectId     = project.ProjectId,
                Project       = project
            };
            var fieldOfStudy = new FieldOfStudy
            {
                FieldOfStudyId = 3,
                Description    = "field of study",
            };
            var programCategory = new ProgramCategory
            {
                ProgramCategoryId   = 3,
                Description         = "program category",
                ProgramCategoryCode = "pccode"
            };
            var position = new Position
            {
                PositionId   = 4,
                Description  = "position",
                PositionCode = "positioncode"
            };
            var usGovAgency1 = new USGovernmentAgency
            {
                AgencyCode  = "usgovcode1",
                AgencyId    = 5,
                Description = "us gov agency1",
            };
            var usGovAgency2 = new USGovernmentAgency
            {
                AgencyCode  = "usgovcode2",
                AgencyId    = 6,
                Description = "us gov agency2",
            };

            var internationalOrg1 = new InternationalOrganization
            {
                Description      = "int org 1",
                OrganizationCode = "int org 1 code",
                OrganizationId   = 7,
            };
            var internationalOrg2 = new InternationalOrganization
            {
                Description      = "int org 2",
                OrganizationCode = "int org 2 code",
                OrganizationId   = 8,
            };
            var visitor = new ParticipantExchangeVisitor
            {
                ParticipantId        = participant.ParticipantId,
                Participant          = participant,
                FieldOfStudy         = fieldOfStudy,
                FieldOfStudyId       = fieldOfStudy.FieldOfStudyId,
                FundingGovtAgency1   = 2.0m,
                FundingGovtAgency2   = 3.0m,
                FundingIntlOrg1      = 4.0m,
                FundingIntlOrg2      = 5.0m,
                FundingOther         = 6.0m,
                FundingPersonal      = 7.0m,
                FundingSponsor       = 8.0m,
                FundingTotal         = 9.0m,
                FundingVisBNC        = 10.0m,
                FundingVisGovt       = 11.0m,
                GovtAgency1          = usGovAgency1,
                GovtAgency1Id        = usGovAgency1.AgencyId,
                GovtAgency1OtherName = "other name",
                GovtAgency2          = usGovAgency2,
                GovtAgency2Id        = usGovAgency2.AgencyId,
                GovtAgency2OtherName = "other other name",
                IntlOrg1             = internationalOrg1,
                IntlOrg1Id           = internationalOrg1.OrganizationId,
                IntlOrg1OtherName    = "other other other name",
                IntlOrg2             = internationalOrg2,
                IntlOrg2Id           = internationalOrg2.OrganizationId,
                IntlOrg2OtherName    = "other name 2",
                OtherName            = "other name again",
                ProgramCategory      = programCategory,
                ProgramCategoryId    = programCategory.ProgramCategoryId,
                Position             = position,
                PositionId           = position.PositionId
            };

            context.Projects.Add(project);
            context.Participants.Add(participant);
            context.FieldOfStudies.Add(fieldOfStudy);
            context.ProgramCategories.Add(programCategory);
            context.Positions.Add(position);
            context.ParticipantExchangeVisitors.Add(visitor);
            context.USGovernmentAgencies.Add(usGovAgency1);
            context.USGovernmentAgencies.Add(usGovAgency2);
            context.InternationalOrganizations.Add(internationalOrg1);
            context.InternationalOrganizations.Add(internationalOrg2);

            Action <ParticipantExchangeVisitorDTO> tester = (result) =>
            {
                Assert.AreEqual(project.ProjectId, result.ProjectId);
                Assert.AreEqual(participant.ParticipantId, result.ParticipantId);
                Assert.AreEqual(visitor.FundingGovtAgency1, result.FundingGovtAgency1);
                Assert.AreEqual(visitor.FundingGovtAgency2, result.FundingGovtAgency2);
                Assert.AreEqual(visitor.FundingIntlOrg1, result.FundingIntlOrg1);
                Assert.AreEqual(visitor.FundingIntlOrg2, result.FundingIntlOrg2);
                Assert.AreEqual(visitor.FundingOther, result.FundingOther);
                Assert.AreEqual(visitor.FundingPersonal, result.FundingPersonal);
                Assert.AreEqual(visitor.FundingSponsor, result.FundingSponsor);
                Assert.AreEqual(visitor.FundingTotal, result.FundingTotal);
                Assert.AreEqual(visitor.FundingVisBNC, result.FundingVisBNC);
                Assert.AreEqual(visitor.FundingVisGovt, result.FundingVisGovt);
                Assert.AreEqual(visitor.GovtAgency1OtherName, result.GovtAgency1OtherName);
                Assert.AreEqual(visitor.GovtAgency2OtherName, result.GovtAgency2OtherName);
                Assert.AreEqual(visitor.IntlOrg1OtherName, result.IntlOrg1OtherName);
                Assert.AreEqual(visitor.IntlOrg2OtherName, result.IntlOrg2OtherName);
                Assert.AreEqual(visitor.OtherName, result.OtherName);

                Assert.AreEqual(visitor.FieldOfStudyId, result.FieldOfStudyId);
                Assert.AreEqual(fieldOfStudy.Description, result.FieldOfStudy);

                Assert.AreEqual(visitor.GovtAgency1Id, result.GovtAgency1Id);
                Assert.AreEqual(usGovAgency1.Description, result.GovtAgency1Name);

                Assert.AreEqual(visitor.GovtAgency2Id, result.GovtAgency2Id);
                Assert.AreEqual(usGovAgency2.Description, result.GovtAgency2Name);

                Assert.AreEqual(visitor.ProgramCategoryId, result.ProgramCategoryId);
                Assert.AreEqual(programCategory.Description, result.ProgramCategory);
                Assert.AreEqual(programCategory.ProgramCategoryCode, result.ProgramCategoryCode);

                Assert.AreEqual(visitor.IntlOrg1Id, result.IntlOrg1Id);
                Assert.AreEqual(internationalOrg1.Description, result.IntlOrg1Name);

                Assert.AreEqual(visitor.IntlOrg2Id, result.IntlOrg2Id);
                Assert.AreEqual(internationalOrg2.Description, result.IntlOrg2Name);

                Assert.AreEqual(visitor.PositionId, result.PositionId);
                Assert.AreEqual(visitor.Position.Description, result.Position);
                Assert.AreEqual(position.PositionCode, result.PositionCode);
            };

            var queryResult = ParticipantExchangeVisitorQueries.CreateGetParticipantExchangeVisitorsDTOQuery(context).ToList();

            Assert.AreEqual(1, queryResult.Count());
            tester(queryResult.First());
        }
示例#14
0
        public void TestCreateGetParticipantExchangeVisitorsDTOQuery_AllValuesNull()
        {
            var project = new Project
            {
                ProjectId = 100
            };
            var participant = new Participant
            {
                ParticipantId = 2,
                ProjectId     = project.ProjectId,
                Project       = project
            };

            var visitor = new ParticipantExchangeVisitor
            {
                ParticipantId = participant.ParticipantId,
                Participant   = participant,
            };

            context.Projects.Add(project);
            context.Participants.Add(participant);
            context.ParticipantExchangeVisitors.Add(visitor);
            Action <ParticipantExchangeVisitorDTO> tester = (result) =>
            {
                Assert.AreEqual(project.ProjectId, result.ProjectId);
                Assert.AreEqual(participant.ParticipantId, result.ParticipantId);
                Assert.AreEqual(0, result.FundingGovtAgency1);
                Assert.AreEqual(0, result.FundingGovtAgency2);
                Assert.AreEqual(0, result.FundingIntlOrg1);
                Assert.AreEqual(0, result.FundingIntlOrg2);
                Assert.AreEqual(0, result.FundingOther);
                Assert.AreEqual(0, result.FundingPersonal);
                Assert.AreEqual(0, result.FundingSponsor);
                Assert.AreEqual(0, result.FundingTotal);
                Assert.AreEqual(0, result.FundingVisBNC);
                Assert.AreEqual(0, result.FundingVisGovt);
                Assert.AreEqual(string.Empty, result.GovtAgency1OtherName);
                Assert.AreEqual(string.Empty, result.GovtAgency2OtherName);
                Assert.AreEqual(string.Empty, result.IntlOrg1OtherName);
                Assert.AreEqual(string.Empty, result.IntlOrg2OtherName);
                Assert.AreEqual(string.Empty, result.OtherName);

                Assert.AreEqual(visitor.FieldOfStudyId, result.FieldOfStudyId);

                Assert.AreEqual(0, result.GovtAgency1Id);
                Assert.AreEqual(string.Empty, result.GovtAgency1Name);

                Assert.AreEqual(0, result.GovtAgency2Id);
                Assert.AreEqual(string.Empty, result.GovtAgency2Name);

                Assert.IsFalse(result.ProgramCategoryId.HasValue);
                Assert.AreEqual(string.Empty, result.ProgramCategory);
                Assert.AreEqual(string.Empty, result.ProgramCategoryCode);

                Assert.AreEqual(0, result.IntlOrg1Id);
                Assert.AreEqual(string.Empty, result.IntlOrg1Name);

                Assert.AreEqual(0, result.IntlOrg2Id);
                Assert.AreEqual(string.Empty, result.IntlOrg2Name);

                Assert.IsFalse(result.PositionId.HasValue);
                Assert.AreEqual(string.Empty, result.Position);
                Assert.AreEqual(string.Empty, result.PositionCode);
            };
            var queryResult = ParticipantExchangeVisitorQueries.CreateGetParticipantExchangeVisitorsDTOQuery(context).ToList();

            Assert.AreEqual(1, queryResult.Count());
            tester(queryResult.First());
        }
示例#15
0
        public async Task TestUpdate_ParticipantDoesNotBelongToProject()
        {
            var     user                 = new User(1);
            int     projectId            = 1;
            int     participantId        = 2;
            int?    fieldOfStudyId       = null;
            int?    positionId           = null;
            int?    programCategoryId    = null;
            decimal?fundingSponsor       = null;
            decimal?fundingPersonal      = null;
            decimal?fundingVisGovt       = null;
            decimal?fundingVisBNC        = null;
            decimal?fundingGovtAgency1   = null;
            int?    govtAgency1Id        = null;
            string  govtAgency1OtherName = null;
            decimal?fundingGovtAgency2   = null;
            int?    govtAgency2Id        = null;
            string  govtAgency2OtherName = null;
            decimal?fundingIntlOrg1      = null;
            int?    intlOrg1Id           = null;
            string  intlOrg1OtherName    = null;
            decimal?fundingIntlOrg2      = null;
            int?    intlOrg2Id           = null;
            string  intlOrg2OtherName    = null;
            decimal?fundingOther         = null;
            string  otherName            = null;
            decimal?fundingTotal         = null;

            Participant participant = new Participant
            {
                ParticipantId = participantId
            };
            ParticipantExchangeVisitor visitor = new ParticipantExchangeVisitor
            {
                ParticipantId = participantId,
                Participant   = participant
            };
            Project otherProject = new Project
            {
                ProjectId = projectId + 1
            };

            context.Participants.Add(participant);
            context.ParticipantExchangeVisitors.Add(visitor);
            context.Projects.Add(otherProject);
            var model = new UpdatedParticipantExchangeVisitor(
                updater: user,
                projectId: projectId,
                participantId: participantId,
                fieldOfStudyId: fieldOfStudyId,
                positionId: positionId,
                programCategoryId: programCategoryId,
                fundingSponsor: fundingSponsor,
                fundingPersonal: fundingPersonal,
                fundingVisGovt: fundingVisGovt,
                fundingVisBNC: fundingVisBNC,
                fundingGovtAgency1: fundingGovtAgency1,
                govtAgency1Id: govtAgency1Id,
                govtAgency1OtherName: govtAgency1OtherName,
                fundingGovtAgency2: fundingGovtAgency2,
                govtAgency2Id: govtAgency2Id,
                govtAgency2OtherName: govtAgency2OtherName,
                fundingIntlOrg1: fundingIntlOrg1,
                intlOrg1Id: intlOrg1Id,
                intlOrg1OtherName: intlOrg1OtherName,
                fundingIntlOrg2: fundingIntlOrg2,
                intlOrg2Id: intlOrg2Id,
                intlOrg2OtherName: intlOrg2OtherName,
                fundingOther: fundingOther,
                otherName: otherName,
                fundingTotal: fundingTotal
                );

            var message = String.Format("The user with id [{0}] attempted to delete a participant with id [{1}] and project id [{2}] but should have been denied access.",
                                        user.Id,
                                        participant.ParticipantId,
                                        projectId);

            Action      a = () => service.Update(model);
            Func <Task> f = async() => await service.UpdateAsync(model);

            a.ShouldThrow <BusinessSecurityException>().WithMessage(message);
            f.ShouldThrow <BusinessSecurityException>().WithMessage(message);
        }