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);
			}
		}
        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 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_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>()
				;
		}
        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 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_create_audit_info_on_save_and_update_child_entities()
		{
			ResetCurrentUser();
			User user1 = CurrentUser;
			user1.Username = "******";
			PersistEntities(user1);

			var group = new UserGroup();
			var sponsor = new Sponsor();
			group.Add(sponsor);
			PersistEntitiesWithAuditing(user1, new DateTime(2009, 4, 5), group, sponsor);
			var group1 = GetAuditedSession(user1, new DateTime(2009, 4, 5)).Load<UserGroup>(group.Id);
			group1.ChangeAuditInfo.Created.ShouldEqual(new DateTime(2009, 4, 5));
			group1.ChangeAuditInfo.CreatedBy.ShouldEqual(user1.Username);
			group1.ChangeAuditInfo.Updated.ShouldEqual(new DateTime(2009, 4, 5));
			group1.ChangeAuditInfo.UpdatedBy.ShouldEqual(user1.Username);
			Sponsor sponsor1 = group.GetSponsors()[0];
			sponsor1.ChangeAuditInfo.Created.ShouldEqual(new DateTime(2009, 4, 5));
			sponsor1.ChangeAuditInfo.CreatedBy.ShouldEqual(user1.Username);
			sponsor1.ChangeAuditInfo.Updated.ShouldEqual(new DateTime(2009, 4, 5));
			sponsor1.ChangeAuditInfo.UpdatedBy.ShouldEqual(user1.Username);
		}
        private void LoadData()
        {
            var userGroup = new UserGroup
                                {
                                    Name = "Austin .Net Users Group",
                                    City = "Austin",
                                    Region = "Texas",
                                    Country = "USA",
                                    Key = "default",
                                    HomepageHTML = "Austin .Net Users Group",
                                };
            userGroup.Add(new Sponsor
                          	{
                          		Level = SponsorLevel.Platinum,
                          		Name = "Microsoft",
                          		Url = "http://microsoft.com/",
                          		BannerUrl = "http://www.microsoft.com/presspass/images/gallery/logos/web/net_v_web.jpg"
                          	});
            var conference = new Conference
                             	{
                             		Address = "123 Guadalupe Street",
                             		City = "Austin",
                             		Description = "Texas' Premier Software Community Event",
                             		EndDate = new DateTime(2009, 5, 10),
                             		StartDate = new DateTime(2009, 5, 9),
                             		Key = "austincodecamp",
                             		LocationName = "St. Edward's Professional Education Center",
                             		Name = "Austin Code Camp",
                             		PhoneNumber = "(512) 555-1212",
                             		PostalCode = "78787",
                             		Region = "Texas",
                             		UserGroup = userGroup,
                             		HtmlContent =
                             			@"
                                    <p>
            <script type=""text/javascript"" src=""http://feeds2.feedburner.com/AustinCodeCamp?format=sigpro""></script>
            </p>
            <noscript></noscript>
            <p><iframe marginwidth=""0"" marginheight=""0""
            src=""http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=9420+Research+Blvd,+Austin,+TX+78759+(St+Edward's+PEC)&amp;sll=30.384022,-97.743998&amp;sspn=0.006858,0.013626&amp;ie=UTF8&amp;ll=30.397013,-97.74004&amp;spn=0.025911,0.036478&amp;z=14&amp;iwloc=addr&amp;output=embed""
            frameborder=""0"" width=""425"" scrolling=""no"" height=""350""></iframe><br /><small>
            <a style=""color:#0000FF;text-align:left""
            href=""http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=9420+Research+Blvd,+Austin,+TX+78759+(St+Edward's+PEC)&amp;sll=30.384022,-97.743998&amp;sspn=0.006858,0.013626&amp;ie=UTF8&amp;ll=30.397013,-97.74004&amp;spn=0.025911,0.036478&amp;z=14&amp;iwloc=addr"">
            View Larger Map</a></small></p>"
                             	};

            var list = new List<PersistentObject>();
            User[] users = CreateUsers();
            list.AddRange(users);
            userGroup.Add(users[0]);
            list.Add(userGroup.GetSponsors()[0]);
            list.Add(userGroup);
            list.Add(conference);

            IEnumerable<Conference> conferences = CreateConferences(userGroup);
            IEnumerable<Meeting> meetings = CreateMeetings(userGroup);
            list.AddRange(conferences.ToArray());
            list.AddRange(meetings.ToArray());

            PersistEntities(list.ToArray());
        }