Inheritance: IRegistrationPopulator
        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
        }
        public void TestUpdateRegistrationPetitionIsAddedIfNoneExistAndNoParticipations1()
        {
            //Test expected fields get copied
            #region Arrange
            var collegeRepository = MockRepository.GenerateStub<IRepositoryWithTypedId<College, string>>();
            RegistrationPopulator = new RegistrationPopulator(SpecialNeedRepository, RegistrationPetitionRepository, ParticipationRepository, RegistrationRepository);

            var student = CreateValidEntities.Student(1);
            var student2 = CreateValidEntities.Student(2);
            ControllerRecordFakes.FakeCeremony(2, CeremonyRepository);
            ControllerRecordFakes.FakeCollege(2, collegeRepository);
            var registration1 = CreateValidEntities.Registration(1);
            registration1.Student = student;
            registration1.Address1 = "Address11";
            registration1.Address2 = "Address21";
            registration1.City = "City1";
            registration1.Email = "*****@*****.**";
            registration1.GradTrack = false;
            registration1.MailTickets = false;
            registration1.State = CreateValidEntities.State(1);
            registration1.TermCode = CreateValidEntities.TermCode(1);
            registration1.Zip = "1";

            var registration2 = CreateValidEntities.Registration(2);
            registration2.Email = string.Empty;

            var registrationPostModel = new RegistrationPostModel();
            registrationPostModel.Registration = registration2;

            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 = student2;
            //registrationParticipations[0].DateUpdated = DateTime.Now.AddDays(-10);
            //registrationParticipations[1].Ceremony = CeremonyRepository.GetNullableById(2);
            //registrationParticipations[1].Ceremony.RegistrationBegin = DateTime.Now.AddDays(2);
            //registrationParticipations[1].Registration = CreateValidEntities.Registration(2);
            //registrationParticipations[1].Registration.Student = student2;
            //registrationParticipations[1].DateUpdated = DateTime.Now.AddDays(-11);
            ControllerRecordFakes.FakeRegistrationParticipation(0, ParticipationRepository, registrationParticipations);

            var participations = new List<CeremonyParticipation>();
            for (int i = 0; i < 2; i++)
            {
                participations.Add(new CeremonyParticipation());
                participations[i].ParticipationId = null;
                participations[i].Participate = false;
                participations[i].Petition = true;
                participations[i].Ceremony = CeremonyRepository.GetNullableById(i + 1);
                participations[i].Major = CreateValidEntities.MajorCode(i + 1);
                participations[i].Major.College = collegeRepository.GetNullableById((i + 1).ToString());
            }
            registrationPostModel.CeremonyParticipations = participations;

            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 = student2;
            RegistrationPetitionRepository.Expect(a => a.Queryable)
                .Return(registrationPetitions.AsQueryable()).Repeat.Any();

            registration1.RegistrationParticipations = registrationParticipations;
            #endregion Arrange

            #region Act
            RegistrationPopulator.UpdateRegistration(registration1, registrationPostModel, null, Controller.ModelState);
            #endregion Act

            #region Assert
            Assert.IsTrue(Controller.ModelState.IsValid);
            Assert.AreEqual(2, registration1.RegistrationPetitions.Count);

            #endregion Assert
        }
        public void TestUpdateRegistration6()
        {
            //Test expected fields get copied
            #region Arrange
            var collegeRepository = MockRepository.GenerateStub<IRepositoryWithTypedId<College, string>>();
            RegistrationPopulator = new RegistrationPopulator(SpecialNeedRepository, RegistrationPetitionRepository, ParticipationRepository, RegistrationRepository);

            var student = CreateValidEntities.Student(1);
            var student2 = CreateValidEntities.Student(2);
            ControllerRecordFakes.FakeCeremony(2, CeremonyRepository);
            ControllerRecordFakes.FakeCollege(2, collegeRepository);
            var registration1 = CreateValidEntities.Registration(1);
            registration1.Student = student;
            registration1.Address1 = "Address11";
            registration1.Address2 = "Address21";
            registration1.City = "City1";
            registration1.Email = "*****@*****.**";
            registration1.GradTrack = false;
            registration1.MailTickets = false;
            registration1.State = CreateValidEntities.State(1);
            registration1.TermCode = CreateValidEntities.TermCode(1);
            registration1.Zip = "1";

            var registration2 = CreateValidEntities.Registration(2);
            registration2.Email = string.Empty;

            var registrationPostModel = new RegistrationPostModel();
            registrationPostModel.Registration = registration2;

            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 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 = student2;
            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 = student2;
            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
            RegistrationPopulator.UpdateRegistration(registration1, registrationPostModel, null, Controller.ModelState);
            #endregion Act

            #region Assert
            Assert.IsFalse(Controller.ModelState.IsValid);
            Controller.ModelState.AssertErrorsAre("You cannot register for two ceremonies within the same college.");
            #endregion Assert
        }
        public void TestUpdateRegistration1()
        {
            //Test expected fields get copied
            #region Arrange
            var collegeRepository = MockRepository.GenerateStub<IRepositoryWithTypedId<College, string>>();
            RegistrationPopulator = new RegistrationPopulator(SpecialNeedRepository, RegistrationPetitionRepository, ParticipationRepository, RegistrationRepository);

            var student = CreateValidEntities.Student(1);
            var student2 = CreateValidEntities.Student(2);
            ControllerRecordFakes.FakeCeremony(2, CeremonyRepository);
            ControllerRecordFakes.FakeCollege(2, collegeRepository);
            var registration1 = CreateValidEntities.Registration(1);
            registration1.Student = student;
            registration1.Address1 = "Address11";
            registration1.Address2 = "Address21";
            registration1.City = "City1";
            registration1.Email = "*****@*****.**";
            registration1.GradTrack = false;
            registration1.MailTickets = false;
            registration1.State = CreateValidEntities.State(1);
            registration1.TermCode = CreateValidEntities.TermCode(1);
            registration1.Zip = "1";

            var registration2 = CreateValidEntities.Registration(2);
            registration2.Student = student2; //this will be ignored.
            registration2.Address1 = "Address12";
            registration2.Address2 = "Address22";
            registration2.City = "City2";
            registration2.Email = "*****@*****.**";
            registration2.GradTrack = true; //ViewModel replaces this.
            registration2.MailTickets = true;
            registration2.State = CreateValidEntities.State(2);
            registration2.TermCode = CreateValidEntities.TermCode(2);
            registration2.Zip = "2";

            var registrationPostModel = new RegistrationPostModel();
            registrationPostModel.Registration = registration2;

            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(-1);
                participations[i].Ceremony.RegistrationDeadline = DateTime.Now.AddDays(15);
                participations[i].Major = CreateValidEntities.MajorCode(i + 1);
                participations[i].Major.College = collegeRepository.GetNullableById((i + 1).ToString());
            }
            registrationPostModel.CeremonyParticipations = participations;
            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 = student2;
            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 = student2;
            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
            RegistrationPopulator.UpdateRegistration(registration1, registrationPostModel, null, Controller.ModelState);
            #endregion Act

            #region Assert
            Assert.AreNotEqual(registration1.Student.Pidm, registration2.Student.Pidm);
            Assert.AreEqual("Address12", registration1.Address1);
            Assert.AreEqual("Address22", registration1.Address2);
            Assert.AreEqual("City2", registration1.City);
            Assert.AreEqual("*****@*****.**", registration1.Email);
            Assert.AreEqual("2", registration1.Zip);
            Assert.IsTrue(registration1.GradTrack);
            Assert.IsTrue(registration1.MailTickets);
            Assert.AreEqual(registration2.State.Name, registration1.State.Name);
            Assert.AreNotEqual(registration2.TermCode.Name, registration1.TermCode.Name);
            #endregion Assert
        }