public void TestAddedEditorDefaultValue()
        {
            #region Arrange
            var ceremony = new Ceremony();
            #endregion Arrange

            #region Act
            ceremony.AddEditor(CreateValidEntities.vUser(1), true);
            ceremony.AddEditor(CreateValidEntities.vUser(2), false);
            ceremony.AddEditor(CreateValidEntities.vUser(3)); //Defaulted
            ceremony.AddEditor(CreateValidEntities.vUser(4), true);
            #endregion Act

            #region Assert
            Assert.AreEqual(4, ceremony.Editors.Count);
            Assert.IsTrue(ceremony.Editors[0].Owner);
            Assert.IsFalse(ceremony.Editors[1].Owner);
            Assert.IsFalse(ceremony.Editors[2].Owner);
            Assert.IsTrue(ceremony.Editors[3].Owner);
            #endregion Assert
        }
Exemplo n.º 2
0
        public ActionResult Create(CeremonyEditModel ceremonyEditModel)
        {
            ModelState.Clear();

            if (string.IsNullOrEmpty(ceremonyEditModel.Term))
            {
                ModelState.AddModelError("Term Code", "Term code must be selected.");
            }

            var termCode = _termRepository.GetNullableById(ceremonyEditModel.Term);

            if (termCode == null && !string.IsNullOrEmpty(ceremonyEditModel.Term))
            {
                // term code doesn't exist, create a new one
                var vTermCode = _vTermRepository.GetNullableById(ceremonyEditModel.Term);

                termCode = new TermCode(vTermCode);
            }

            Ceremony ceremony = new Ceremony();
            CopyCeremony(ceremony, ceremonyEditModel.Ceremony, ceremonyEditModel.CeremonyMajors, ceremonyEditModel.Colleges, ceremonyEditModel.TicketDistributionMethods);
            ceremony.TermCode = termCode;
            ceremony.AddEditor(_userService.GetCurrentUser(User), true);

            // fix the time on the end dates, so it ends on

            ceremony.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                // save
                _termRepository.EnsurePersistent(termCode, true);
                Repository.OfType<Ceremony>().EnsurePersistent(ceremony);
                TermService.UpdateCurrent(termCode);    // update the cache.

                // null out the current list of ceremonies the user has access to
                _ceremonyService.ResetUserCeremonies();

                // display a message
                Message = "Ceremony has been created.";

                // redirect to the list
                return this.RedirectToAction(a => a.Edit(ceremony.Id));
            }

            // redirect back to the page
            var viewModel = CeremonyViewModel.Create(Repository, User, _majorService, ceremony);
            viewModel.Ceremony = ceremony;

            return View(viewModel);
        }
        public void TestCanCorrectlyMapCeremony1()
        {
            #region Arrange
            var id = CeremonyRepository.Queryable.Max(x => x.Id) + 1;
            var session = NHibernateSessionManager.Instance.GetSession();
            var compareDate1 = new DateTime(2010, 01, 01);
            var compareDate2 = new DateTime(2010, 01, 02);
            var compareDate3 = new DateTime(2010, 01, 03);
            var compareDate4 = new DateTime(2010, 01, 04);
            LoadColleges(3);
            var colleges = Repository.OfType<College>().GetAll();
            //LoadCeremonyEditors(2);
            LoadUsers(3);
            var ceremony = new Ceremony();
            ceremony.SetIdTo(id);
            ceremony.AddEditor(Repository.OfType<vUser>().GetById(1), true);
            ceremony.AddEditor(Repository.OfType<vUser>().GetById(2), false);
            //LoadMajorCode(3);
            var majors = Repository.OfType<MajorCode>().GetAll();
            LoadRegistrationPetitions(3);
            var registrationPetitions = Repository.OfType<RegistrationPetition>().GetAll();
            foreach (var registrationPetition in registrationPetitions)
            {
                registrationPetition.Ceremony = ceremony; //This would be set when the student creates the RegistrationPetition
            }

            LoadTemplateType(1);
            LoadTemplate(3);
            var templates = Repository.OfType<Template>().GetAll();
            foreach (var template in templates)
            {
                template.Ceremony = ceremony;
            }
            //LoadTermCode(1);
            var termCode = Repository.OfType<TermCode>().Queryable.First();
            LoadRegistrationParticipations(3,3);
            var registrationParticipations = Repository.OfType<RegistrationParticipation>().GetAll();
            foreach (var registrationParticipation in registrationParticipations)
            {
                registrationParticipation.Ceremony = ceremony;
            }

            #endregion Arrange

            #region Act/Assert
            new PersistenceSpecification<Ceremony>(session, new CeremonyEqualityComparer())
                .CheckProperty(c => c.Id, id)
                .CheckProperty(c => c.Colleges, colleges)
                .CheckProperty(c => c.DateTime, compareDate1)
                .CheckProperty(c => c.Editors, ceremony.Editors)
                .CheckProperty(c => c.ExtraTicketDeadline, compareDate2)
                .CheckProperty(c => c.ExtraTicketPerStudent, 5)
                .CheckProperty(c => c.Location, "Location")
                .CheckProperty(c => c.Majors, majors)
                .CheckProperty(c => c.PrintingDeadline, compareDate3)
                .CheckProperty(c => c.RegistrationDeadline, compareDate4)
                .CheckProperty(c => c.RegistrationPetitions, registrationPetitions)
                .CheckProperty(c => c.Templates, templates)
                .CheckProperty(c => c.TermCode, termCode)
                .CheckProperty(c => c.TicketsPerStudent, 6)
                .CheckProperty(c => c.TotalTickets, 1000)
                .CheckProperty(c => c.RegistrationParticipations, registrationParticipations)
                .VerifyTheMappings();
            #endregion Act/Assert
        }