예제 #1
0
        public ActionResult List(UserGroup userGroup)
        {
            var result = AutoMappedView<UpdateSponsorInput[]>(userGroup.GetSponsors());
            result.ViewName = "HomePageWidget";

            return result;
        }
        public void Can_persist()
        {
            var userGroup = new UserGroup {Name = "user group"};
            var meeting = new Meeting
                          	{
                          		Name = "sdf",
                          		Description = "description",
                          		StartDate = new DateTime(2008, 12, 2),
                          		EndDate = new DateTime(2008, 12, 3),
                          		LocationName = "St Edwards Professional Education Center",
                          		Address = "12343 Research Blvd",
                          		City = "Austin",
                          		Region = "Tx",
                          		PostalCode = "78234",
                                                TimeZone = "CST",
                                                UserGroup = userGroup,
                          		LocationUrl = "http://foobar",
                          		Topic = "topic",
                          		Summary = "summary",
                          		SpeakerName = "speakername",
                          		SpeakerBio = "bio",
                          		SpeakerUrl = "http://google.com"
                          	};

            AssertObjectCanBePersisted(userGroup);
            AssertObjectCanBePersisted(meeting);
        }
예제 #3
0
        public ActionResult Index(UserGroup usergroup)
        {
            UserGroup group = _repository.GetById(usergroup.Id);
            AutoMappedViewResult view = AutoMappedView<UpdateSponsorInput[]>(group.GetSponsors());

            return view;
        }
예제 #4
0
 public ActionResult Edit(UpdateSponsorInput sponsorInput, UserGroup userGroup)
 {
     sponsorInput.UserGroup = userGroup;
     return Command<UpdateSponsorInput, Sponsor>(sponsorInput,
                                           r => new RedirectToReturnUrlResult(),
                                           input => View(sponsorInput));
 }
		public void UpdateUserGroupFromInput(UserGroup model, UserGroupInput input)
		{
			model.DomainName = input.DomainName;
			model.Key = input.Key;
			model.Id = input.Id;
			model.Name = input.Name;
			model.HomepageHTML = input.HomepageHTML;
			model.City = input.City;
			model.Region = input.Region;
			model.Country = input.Country;
			model.GoogleAnalysticsCode = input.GoogleAnalysticsCode;
			var existingUsers = model.GetUsers();

			var usersToRemove = existingUsers.Where(user => !input.Users.Any(uf => uf.Id == user.Id));

			foreach (var user in usersToRemove)
			{
				model.Remove(user);
			}

			var userFormToAdd =
				input.Users.Where(userForm => !existingUsers.Any(user => user.Id == userForm.Id));
			var users = _userRepository.GetAll();

			foreach (var userForm in userFormToAdd)
			{
				var user = users.FirstOrDefault(user1 => user1.Id == userForm.Id);
				model.Add(user);
			}
		}
예제 #6
0
 private static IEnumerable<Meeting> CreateMeetings(UserGroup userGroup)
 {
     DateTime startDate = DateTime.Now.AddDays(-7*5);
     for (int i = 0; i < 6; i++)
     {
         DateTime meetingDate = startDate.AddDays(7*i);
         yield return new Meeting
                      	{
                      		Address = "123 Guadalupe Street",
                      		City = "Austin",
                      		Description = "Regular meeting.  Don't forget CodeCamp planning next month!",
                      		EndDate = meetingDate.AddDays(1),
                      		StartDate = meetingDate,
                      		Key = meetingDate.Month.ToString().ToLower() + meetingDate.Day + "meeting",
                      		LocationName = "St. Edward's Professional Education Center",
                      		Name = meetingDate.ToString("MMMM") + " meeting",
                      		PostalCode = "78787",
                      		Region = "Texas",
                      		UserGroup = userGroup,
                      		Topic = "ASP.NET MVC in Action",
                      		Summary =
                      			"With the new version of ASP.NET, developers can easily leverage the Model-View-Controller pattern in ASP.NET applications. Pulling logic away from the UI and the views has been difficult for a long time. The Model-View-Presenter pattern helps a little bit, but the fact that the view has to delegate to the presenter makes the UI pattern difficult to work with. This session is a detailed overview of the ASP.NET MVC Framework.  It is meant for developers already building systems with ASP.NET 3.5 SP1.",
                      		LocationUrl = "http://maps.google.com",
                      		TimeZone = "CST",
                      		SpeakerName = "Jeffrey Palermo",
                      		SpeakerBio =
                      			@"Jeffrey Palermo is the CTO of Headspring Systems. Jeffrey specializes in Agile management coaching and helps companies double the productivity of software teams. He is instrumental in the Austin software community as a member of AgileAustin and a director of the Austin .Net User Group. Jeffrey has been recognized by Microsoft as a ""Microsoft Most Valuable Professional"" (MVP) for technical and community leadership. He is also certified as a MCSD.Net and ScrumMaster. Jeffrey has spoken and facilitated at industry conferences such as VSLive, DevTeach, and Microsoft Tech Ed. He also speaks to user groups around the country as part of the INETA Speakers' Bureau. His web sites are headspringsystems.com and jeffreypalermo.com. He is a graduate from Texas A&amp;M University, an Eagle Scout, and an Iraq war veteran.  Jeffrey is the founder of the CodeCampServer open-source project and a co-founder of the MvcContrib project.",
                      		SpeakerUrl = "http://jeffreypalermo.com"
                      	};
     }
 }
        public void Can_persist()
        {
            var userGroup = new UserGroup
                                {Name = "user group"};
            var conference = new Conference
                             	{
                             		Name = "sdf",
                             		Description = "description",
                             		StartDate = new DateTime(2008, 12, 2),
                             		EndDate = new DateTime(2008, 12, 3),
                             		TimeZone = "CST",
                             		LocationName = "St Edwards Professional Education Center",
                             		Address = "12343 Research Blvd",
                             		City = "Austin",
                             		Region = "Tx",
                             		PostalCode = "78234",
                             		PhoneNumber = "512-555-1234",
                             		HtmlContent = "<h1>This is some markup about sponsors.</h1>",
                             		UserGroup = userGroup,
                             		HasRegistration = true,
                             		LocationUrl = "http://foobar"
                             	};

            AssertObjectCanBePersisted(userGroup);
            AssertObjectCanBePersisted(conference);
        }
예제 #8
0
 public ActionResult Delete(DeleteMeetingInput message, UserGroup userGroup)
 {
     if (!_securityContext.HasPermissionsFor(userGroup))
     {
         return NotAuthorizedView;
     }
     return Command(message, r => RedirectToAction<HomeController>(c => c.Index(userGroup)));
 }
예제 #9
0
		public void Should_add_and_remove_users()
		{
			var @group = new UserGroup();
			var child = new User();
			group.Add(child);
			group.GetUsers().ShouldEqual(new []{child});
			group.Remove(child);
			group.GetUsers().Length.ShouldEqual(0);
		}
예제 #10
0
		public ViewResult Index(UserGroup userGroup)
		{
			ViewResult result = AutoMappedView<UserGroupInput>(userGroup);
			if (userGroup == null || userGroup.IsDefault())
			{
				result.ViewName = "defaultIndex";
			}
			return result;
		}
        public void The_binder_should_find_a_usergroup_by_its_key2()
        {
            var userGroupRepository = S<IUserGroupRepository>();
            var userGroup1 = new UserGroup();
            userGroupRepository.Stub(repository => repository.GetByKey("foo")).Return(userGroup1);

            var modelBinder = new UserGroupModelBinder(userGroupRepository);
            var usergroup = (UserGroup) modelBinder.BindModel(new ControllerContext(), CreateBindingContext("usergroupkey", "foo")).Value;
            usergroup.ShouldEqual(userGroup1);
        }
예제 #12
0
        public virtual bool HasPermissionsFor(UserGroup usergroup)
        {
            User user = _session.GetCurrentUser();

            if (usergroup != null && usergroup.GetUsers().Any(user1 => user1.Username == user.Username))
            {
                return true;
            }
            return IsAdmin();
        }
        public void Should_save_the_UserGroup()
        {
            var form = new UserGroupInput();
            var UserGroup = new UserGroup();

            //			var mapper = S<IUserGroupMapper>();
            //			mapper.Stub(m => m.Map(form)).Return(UserGroup);

            var controller = new UserGroupController(null, PermisiveSecurityContext());
            var result = (CommandResult) controller.Edit(form);
        }
예제 #14
0
        public void About_should_go_to_about_view()
        {
            var userGroup = new UserGroup();

            var home = new HomeController();

            ViewResult result = home.About(userGroup);
            result.ViewName.ShouldEqual("");
            result.ViewData.Model.ShouldEqual(userGroup);
            ((AutoMappedViewResult) result).ViewModelType.ShouldBe(typeof (UserGroupInput));
        }
예제 #15
0
        public void The_index_should_retrieve_the_user_group_by_its_domain_name()
        {
            var userGroup = new UserGroup();
            userGroup.Key = "adnug";

            var home = new HomeController();

            ViewResult result = home.Index(userGroup);
            result.ForView("");
            result.WithViewData<UserGroup>().ShouldNotBeNull();
            ((AutoMappedViewResult) result).ViewModelType.ShouldBe(typeof (UserGroupInput));
        }
        public void Should_save_a_new_sponsor_in_the_Save_action()
        {
            var userGroup = new UserGroup();

            var input = new UpdateSponsorInput();

            var controller = new SponsorController(null, PermisiveSecurityContext());

            var result = (CommandResult) controller.Edit(input, null);

            result.Success.AssertResultIs<RedirectToReturnUrlResult>();
        }
		public void Should_list_all_events_for_usergroup()
		{
			var repository = S<IEventRepository>();
			var usergroup = new UserGroup();
			var meeting = new Meeting {Key = "meeting1"};
			var conference = new Conference {Key = "conference1"};
			repository.Stub(s => s.GetAllForUserGroup(usergroup)).Return(new Event[] {meeting, conference});

			var controller = new EventController(repository);
			ViewResult result = controller.List(usergroup);
			result.ViewName.ShouldEqual("list");
			result.ViewData.Model.ShouldEqual(new[] {"meeting1", "conference1"});
		}
		public void Should_delete_a_sponsor_from_the_delete_action()
		{
			var repository = S<IUserGroupRepository>();
			var controller = new SponsorController(repository, PermisiveSecurityContext());

			var userGroup = new UserGroup();

			controller.Delete(userGroup, new Sponsor())
				.AssertActionRedirect()
				.ToAction<SponsorController>(c => c.Index(null));

			repository.AssertWasCalled(x => x.Save(userGroup));
		}
		public void Should_edit_an_existing_sponsor()
		{
			var controller = new SponsorController(S<IUserGroupRepository>(), PermisiveSecurityContext());

			var userGroup = new UserGroup();
			userGroup.Add(new Sponsor {Id = default(int)});

			controller.Edit(userGroup, new Sponsor())
				.AssertViewRendered()
				.ForView(ViewNames.Default)
				.ModelShouldBe<Sponsor>()
				.AutoMappedModelShouldBe<UpdateSponsorInput>()
				;
		}
예제 #20
0
        public ViewResult Edit(UserGroup userGroup, Sponsor sponsor)
        {
            if (!_securityContext.IsAdmin())
            {
                return NotAuthorizedView;
            }

            if (sponsor != null)
            {
                sponsor.UserGroup=userGroup;
            }

            return AutoMappedView<UpdateSponsorInput>(sponsor??new Sponsor(){UserGroup=userGroup});
        }
        public void The_security_context_should_find_a_user_has_permissions()
        {
            var session = S<IUserSession>();
            var user = new User();
            session.Stub(userSession => userSession.GetCurrentUser()).Return(user);

            var usergroup = new UserGroup();
            usergroup.Add(user);

            ISecurityContext context = new SecurityContext(session, null);

            bool hasPermission = context.HasPermissionsFor(usergroup);
            hasPermission.ShouldBeTrue();
        }
        public void Should_map_a_sponsor()
        {
            var userGroup = new UserGroup();
            var sponsor = new Sponsor
                          	{
                          		Name = "FooBar",
                                Level =SponsorLevel.Gold,
                                Url = "http://thisistheurl.com/",
                                                                UserGroup = userGroup
                          	};

            PersistEntities(userGroup);

            AssertObjectCanBePersisted(sponsor);
        }
        public void The_security_context_should_find_a_user_does_not_have_permissions()
        {
            var session = S<IUserSession>();
            var user = new User();
            session.Stub(userSession => userSession.GetCurrentUser()).Return(user);

            var usergroup = new UserGroup();

            var userGroupRepo = S<IUserGroupRepository>();
            userGroupRepo.Stub(repository => repository.GetDefaultUserGroup()).Return(new UserGroup());

            ISecurityContext context = new SecurityContext(session, userGroupRepo);

            bool hasPermission = context.HasPermissionsFor(usergroup);
            hasPermission.ShouldBeFalse();
        }
        public void The_security_context_should_allow_a_system_admin_to_access_a_group()
        {
            var session = S<IUserSession>();
            var user = new User();
            session.Stub(userSession => userSession.GetCurrentUser()).Return(user);

            var userGroupRepo = S<IUserGroupRepository>();
            var defaultUserGroup = new UserGroup();
            defaultUserGroup.Add(user);
            userGroupRepo.Stub(repository => repository.GetDefaultUserGroup()).Return(defaultUserGroup);

            ISecurityContext context = new SecurityContext(session, userGroupRepo);

            bool hasPermission = context.IsAdmin();
            hasPermission.ShouldBeTrue();
        }
        public void Should_retrieve_all_upcoming_events()
        {
            SystemClockFactory.Default = () => new Clock(new DateTime(2009, 5, 5));
            var usergroup = new UserGroup();
            var usergroup1 = new UserGroup();
            var event1 = new Conference
                              	{
                              		UserGroup = usergroup1,
                              		StartDate = new DateTime(2000, 1, 2),
                              		EndDate = new DateTime(2009, 4, 6)
                              	};
            var event4 = new Meeting
                              	{
                              		UserGroup = usergroup,
                              		StartDate = new DateTime(2000, 1, 3),
                              		EndDate = new DateTime(2009, 5, 4, 20, 0, 0)
                              	};
            var event2 = new Conference
                              	{
                              		UserGroup = usergroup1,
                              		StartDate = new DateTime(2000, 1, 4),
                              		EndDate = new DateTime(2009, 5, 5, 20, 0, 0)
                              	};
            var event3 = new Meeting
                              	{
                              		UserGroup = usergroup,
                              		StartDate = new DateTime(2000, 1, 5),
                              		EndDate = new DateTime(2009, 5, 7)
                              	};

            using (ISession session = GetSession())
            {
                session.SaveOrUpdate(usergroup);
                session.SaveOrUpdate(usergroup1);
                session.SaveOrUpdate(event1);
                session.SaveOrUpdate(event2);
                session.SaveOrUpdate(event3);
                session.SaveOrUpdate(event4);
                session.Flush();
            }

            IEventRepository repository = GetInstance<EventRepository>();
            Event[] events = repository.GetAllFutureEvents();

            events.Length.ShouldEqual(2);
            events[0].ShouldEqual(event2);
        }
예제 #26
0
 public ActionResult Edit(Guid? entityToEdit)
 {
     UserGroup model;
     if (!entityToEdit.HasValue || entityToEdit == Guid.Empty)
     {
         model = new UserGroup();
     }
     else
     {
         model = _repository.GetById(entityToEdit.Value);
         if (!CurrentUserHasPermissionToEditUserGroup(model))
         {
             return View(ViewPages.NotAuthorized);
         }
     }
     return AutoMappedView<UserGroupInput>(model);
 }
        public void The_security_context_should_allow_admins_to_create_new_users_groups()
        {
            var session = S<IUserSession>();
            var user = new User();
            session.Stub(userSession => userSession.GetCurrentUser()).Return(user);

            var userGroupRepo = S<IUserGroupRepository>();
            var userGroup = new UserGroup();
            userGroup.Add(user);

            userGroupRepo.Stub(repository => repository.GetDefaultUserGroup()).Return(userGroup);

            ISecurityContext context = new SecurityContext(session, userGroupRepo);

            bool hasPermission = context.HasPermissionsFor(null);

            hasPermission.ShouldBeTrue();
        }
        public void Should_map_user_group()
        {
            var usergroup = new UserGroup();
            usergroup.Name = "this group";
            usergroup.Key = "AustinDotNetUsersGroup";
            usergroup.City = "city";
            usergroup.Region = "Stete";
            usergroup.Country = "USA";
            usergroup.HomepageHTML = "<H1>Hello World</H1>";
            usergroup.GoogleAnalysticsCode = "foo";
            usergroup.DomainName = "foo/bar";
            usergroup.Add(new User {EmailAddress = "foo", Name = "bar"});
            usergroup.Add(new Sponsor {Level = SponsorLevel.Platinum, Name = "the sponsor"});

            AssertObjectCanBePersisted(usergroup.GetSponsors()[0]);
            AssertObjectCanBePersisted(usergroup.GetUsers()[0]);
            AssertObjectCanBePersisted(usergroup);
        }
		public void Should_list_all_future_events()
		{
			var repository = S<IEventRepository>();
			var userGroup1 = new UserGroup {Name = "foo", DomainName = "bar"};
			var meeting = new Meeting
			              	{
			              		Key = "meeting1",
			              		Name = "monthly meeting",
			              		Topic = "Visual Studio Tips and Tricks",
			              		UserGroup = userGroup1
			              	};
			var conference = new Conference {Key = "conference1", Name = "Austin Code Camp", UserGroup = userGroup1};
			repository.Stub(s => s.GetAllFutureEvents()).Return(new Event[] {meeting, conference});

			var controller = new EventController(repository);
			ViewResult result = controller.AllUpcomingEvents();
			result.ViewName.ShouldEqual("");
			result.ViewData.Model.ShouldBeInstanceOf<EventList[]>();
		}
        public void should_retrieve_events_for_a_usergroup()
        {
            var usergroup = new UserGroup();
            var conference1 = new Conference {UserGroup = usergroup};
            var meeting1 = new Meeting {UserGroup = usergroup};
            var meeting2 = new Meeting();

            using (ISession session = GetSession())
            {
                session.SaveOrUpdate(usergroup);
                session.SaveOrUpdate(conference1);
                session.SaveOrUpdate(meeting1);
                session.SaveOrUpdate(meeting2);
                session.Flush();
            }

            IEventRepository repository = GetInstance<EventRepository>();
            Event[] events = repository.GetAllForUserGroup(usergroup);

            events.Length.ShouldEqual(2);
        }