PopulateRegistration() public method

public PopulateRegistration ( RegistrationPostModel registrationPostModel, Student student, ModelStateDictionary modelState, bool adminUpdate = false ) : Registration
registrationPostModel RegistrationPostModel
student Student
modelState ModelStateDictionary
adminUpdate bool
return Registration
        public void TestPopulateRegistration1()
        {
            #region Arrange
            FakeTermCodeService.LoadTermCodes("201003", TermCodeRepository);
            RegistrationPopulator = new RegistrationPopulator(SpecialNeedRepository, RegistrationPetitionRepository,ParticipationRepository, RegistrationRepository);
            var student = CreateValidEntities.Student(1);
            var registrationPostModel = new RegistrationPostModel();
            var participations = new List<CeremonyParticipation>();
            for (int i = 0; i < 3; i++)
            {
                participations.Add(new CeremonyParticipation());
                participations[i].ParticipationId = i + 1;
            }
            registrationPostModel.CeremonyParticipations = participations;
            var registration = CreateValidEntities.Registration(7);
            registration.Address2 = string.Empty;
            registration.Email = string.Empty;
            registrationPostModel.Registration = registration;
            registrationPostModel.GradTrack = true;
            #endregion Arrange

            #region Act
            var result = RegistrationPopulator.PopulateRegistration(registrationPostModel, student,
                                                                    Controller.ModelState);

            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.IsNull(result.Address2);
            Assert.IsNull(result.Email);
            Assert.IsNotNull(result.SpecialNeeds);
            Assert.AreEqual(0, result.SpecialNeeds.Count);
            Assert.IsFalse(Controller.ModelState.IsValid);
            Controller.ModelState.AssertErrorsAre("You have to select one or more ceremonies to participate.");
            #endregion Assert
        }
        public void TestPopulateRegistration9()
        {
            //This one has 1 existing participations for student and ceremony and 1 existing petition
            #region Arrange
            var collegeRepository = MockRepository.GenerateStub<IRepositoryWithTypedId<College, string>>();

            FakeTermCodeService.LoadTermCodes("201003", TermCodeRepository);
            ControllerRecordFakes.FakeCeremony(2, CeremonyRepository);
            ControllerRecordFakes.FakeCollege(2, collegeRepository);
            RegistrationPopulator = new RegistrationPopulator(SpecialNeedRepository, RegistrationPetitionRepository, ParticipationRepository, RegistrationRepository);
            var student = CreateValidEntities.Student(1);
            var student2 = CreateValidEntities.Student(2);
            var registrationPostModel = new RegistrationPostModel();
            var participations = new List<CeremonyParticipation>();
            for (int i = 0; i < 2; i++)
            {
                participations.Add(new CeremonyParticipation());
                //participations[i].ParticipationId = i + 1;
                participations[i].Participate = false;
                participations[i].Petition = true;
                participations[i].Ceremony = CeremonyRepository.GetNullableById(i + 1);
                participations[i].Ceremony.RegistrationBegin = DateTime.Now.AddDays(-10);
                participations[i].Ceremony.RegistrationDeadline = DateTime.Now.AddDays(10);
                participations[i].Major = CreateValidEntities.MajorCode(i + 1);
                participations[i].Major.College = collegeRepository.GetNullableById((i + 1).ToString());
            }
            registrationPostModel.CeremonyParticipations = participations;
            var registration = CreateValidEntities.Registration(7);
            registration.Address2 = string.Empty;
            registration.Email = string.Empty;
            registrationPostModel.Registration = registration;
            registrationPostModel.GradTrack = true;

            var registrationPetitions = new List<RegistrationPetition>();
            registrationPetitions.Add(CreateValidEntities.RegistrationPetition(1));
            registrationPetitions.Add(CreateValidEntities.RegistrationPetition(2));
            registrationPetitions[0].Ceremony = CeremonyRepository.GetNullableById(1);
            registrationPetitions[0].Registration = CreateValidEntities.Registration(1);
            registrationPetitions[0].Registration.Student = student2;
            registrationPetitions[1].Ceremony = CeremonyRepository.GetNullableById(2);
            registrationPetitions[1].Registration = CreateValidEntities.Registration(2);
            registrationPetitions[1].Registration.Student = student;
            RegistrationPetitionRepository.Expect(a => a.Queryable)
                .Return(registrationPetitions.AsQueryable()).Repeat.Any();
            var registrationParticipations = new List<RegistrationParticipation>();
            registrationParticipations.Add(CreateValidEntities.RegistrationParticipation(1));
            registrationParticipations.Add(CreateValidEntities.RegistrationParticipation(2));
            registrationParticipations[0].Ceremony = CeremonyRepository.GetNullableById(1);
            registrationParticipations[0].Registration = CreateValidEntities.Registration(1);
            registrationParticipations[0].Registration.Student = student;
            registrationParticipations[1].Ceremony = CeremonyRepository.GetNullableById(2);
            registrationParticipations[1].Registration = CreateValidEntities.Registration(2);
            registrationParticipations[1].Registration.Student = student2;
            ParticipationRepository.Expect(a => a.Queryable)
                .Return(registrationParticipations.AsQueryable()).Repeat.Any();
            #endregion Arrange

            #region Act
            var result = RegistrationPopulator.PopulateRegistration(registrationPostModel, student,
                                                                    Controller.ModelState);

            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Controller.ModelState.IsValid);
            Assert.AreEqual(0, result.RegistrationParticipations.Count);
            Assert.AreEqual(0, result.RegistrationPetitions.Count);
            #endregion Assert
        }
        public void TestPopulateRegistration6()
        {
            #region Arrange

            var collegeRepository = MockRepository.GenerateStub<IRepositoryWithTypedId<College, string>>();

            ControllerRecordFakes.FakeSpecialNeeds(3, SpecialNeedRepository);

            FakeTermCodeService.LoadTermCodes("201003", TermCodeRepository);
            ControllerRecordFakes.FakeCeremony(2, CeremonyRepository);
            ControllerRecordFakes.FakeCollege(2, collegeRepository);
            RegistrationPopulator = new RegistrationPopulator(SpecialNeedRepository, RegistrationPetitionRepository, ParticipationRepository, RegistrationRepository);
            var student = CreateValidEntities.Student(1);
            var registrationPostModel = new RegistrationPostModel();
            var participations = new List<CeremonyParticipation>();
            for (int i = 0; i < 2; i++)
            {
                participations.Add(new CeremonyParticipation());
                participations[i].ParticipationId = i + 1;
                participations[i].Participate = true;
                participations[i].Petition = false;
                participations[i].Ceremony = CeremonyRepository.GetNullableById(i + 1);
                participations[i].Ceremony.RegistrationBegin = DateTime.Now.AddDays(-10);
                participations[i].Ceremony.RegistrationDeadline = DateTime.Now.AddDays(10);
                participations[i].Major = CreateValidEntities.MajorCode(i + 1);
                participations[i].Major.College = collegeRepository.GetNullableById((i + 1).ToString());
            }
            registrationPostModel.CeremonyParticipations = participations;
            var registration = CreateValidEntities.Registration(7);
            registration.Address2 = string.Empty;
            registration.Email = string.Empty;
            registrationPostModel.Registration = registration;
            registrationPostModel.GradTrack = false;
            registrationPostModel.SpecialNeeds = new List<string>{"1", "3"};
            #endregion Arrange

            #region Act
            var result = RegistrationPopulator.PopulateRegistration(registrationPostModel, student,
                                                                    Controller.ModelState);

            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.SpecialNeeds.Count);
            Assert.AreEqual("Name1", result.SpecialNeeds[0].Name);
            Assert.AreEqual("Name3", result.SpecialNeeds[1].Name);
            #endregion Assert
        }
        public void TestPopulateRegistration3()
        {
            #region Arrange

            var collegeRepository = MockRepository.GenerateStub<IRepositoryWithTypedId<College, string>>();

            FakeTermCodeService.LoadTermCodes("201003", TermCodeRepository);
            ControllerRecordFakes.FakeCeremony(2, CeremonyRepository);
            ControllerRecordFakes.FakeCollege(2, collegeRepository);
            RegistrationPopulator = new RegistrationPopulator(SpecialNeedRepository, RegistrationPetitionRepository, ParticipationRepository, RegistrationRepository);
            var student = CreateValidEntities.Student(1);
            var registrationPostModel = new RegistrationPostModel();
            var participations = new List<CeremonyParticipation>();
            for (int i = 0; i < 2; i++)
            {
                participations.Add(new CeremonyParticipation());
                participations[i].ParticipationId = i + 1;
                participations[i].Participate = true;
                participations[i].Petition = false;
                participations[i].Ceremony = CeremonyRepository.GetNullableById(i+1);
                participations[i].Major = CreateValidEntities.MajorCode(i + 1);
                participations[i].Major.College = collegeRepository.GetNullableById("1"); //Same college so error
            }
            registrationPostModel.CeremonyParticipations = participations;
            var registration = CreateValidEntities.Registration(7);
            registration.Address2 = string.Empty;
            registration.Email = string.Empty;
            registrationPostModel.Registration = registration;
            registrationPostModel.GradTrack = true;
            #endregion Arrange

            #region Act
            var result = RegistrationPopulator.PopulateRegistration(registrationPostModel, student,
                                                                    Controller.ModelState);

            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.IsFalse(Controller.ModelState.IsValid);
            Controller.ModelState.AssertErrorsAre("You cannot register for two ceremonies within the same college.");
            #endregion Assert
        }