public void GetTest(string extraRole, bool valid) { var username = RandomString(); var password = RandomString(); var membershipProvider = new MockCMSMembershipProvider { ValidUser = true }; var roleProvider = new MockCMSRoleProvider(); var db = DatabaseFixture.NewDbContext(); var context = ContextTestUtils.CreateMockHttpContext(); roleProvider.UserRoles.AddRange(new[] { "APIOnly", extraRole }); db.WriteContentSql("GetTest", "--API\r\nSELECT TOP 10 * FROM dbo.People"); CreateUser(username, password, roles: new[] { "Access" }); context.Headers["Authorization"] = BasicAuthenticationString(username, password); CMSMembershipProvider.SetCurrentProvider(membershipProvider); CMSRoleProvider.SetCurrentProvider(roleProvider); var authenticated = AuthHelper.AuthenticateDeveloper(HttpContextFactory.Current, additionalRole: "APIOnly").IsAuthenticated; authenticated.ShouldBe(valid); if (valid) { var controller = new CustomController(new Lifecycle.RequestManager()) { Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/CustomAPI/GetTest") }; var results = controller.Get("GetTest"); results.Count().ShouldBeGreaterThan(0); (results.First().PeopleId as int?).ShouldNotBeNull(); } }
public void Should_Generate_Options_Settings() { var db = DatabaseFixture.NewDbContext(); User user = db.Users.Where(u => u.Username == "admin").FirstOrDefault(); db.CurrentUser = user; OrgSearchModel m = new OrgSearchModel(db); var result = m.RegOptionsList(); result.ShouldNotBeNull(); }
public void Should_Move_PushPay_EVs_when_Reassigning_Contribution() { var PushPayKey = "PushPayKey"; var KeyValue = RandomString(); var db = DatabaseFixture.NewDbContext(); User user = db.Users.Where(u => u.Username == "admin").FirstOrDefault(); db.CurrentUser = user; SearchAddModel m = new SearchAddModel(db); Person from = db.People.OrderByDescending(p => p.PeopleId).FirstOrDefault(); var existing = from.PeopleExtras.SingleOrDefault(ev => ev.Field == PushPayKey); if (existing != null) { db.PeopleExtras.DeleteOnSubmit(existing); db.SubmitChanges(); } db.AddExtraValueDataIfNotExist(from.PeopleId, PushPayKey, null, null, KeyValue, null, null); Contribution c = new Contribution { PeopleId = from.PeopleId, ContributionDate = DateTime.Now, ContributionAmount = 1, ContributionTypeId = ContributionTypeCode.Online, ContributionStatusId = ContributionStatusCode.Recorded, Origin = ContributionOriginCode.PushPay, CreatedDate = DateTime.Now, FundId = 1, MetaInfo = "unit test" }; db.Contributions.InsertOnSubmit(c); Person to = new Person { Family = db.Families.FirstOrDefault(), FirstName = RandomString(), LastName = RandomString(), EmailAddress = RandomString() + "@example.com", MemberStatusId = MemberStatusCode.Member, PositionInFamilyId = PositionInFamily.PrimaryAdult, }; db.People.InsertOnSubmit(to); db.SubmitChanges(); var pp = new PendingPersonModel(db); pp.CopyPropertiesFrom(to); pp.LoadAddress(); m.PendingList.Add(pp); m.AddContributor(c.ContributionId, OriginCode.Contribution); // person contribution moved from should not have the ev db = db.Copy(); var extraValue = db.PeopleExtras.SingleOrDefault(p => p.PeopleId == from.PeopleId && p.Field == PushPayKey && p.Data == KeyValue); extraValue.ShouldBe(null); // person contribution moved to should have the ev extraValue = db.PeopleExtras.SingleOrDefault(p => p.PeopleId == to.PeopleId && p.Field == PushPayKey && p.Data == KeyValue); extraValue.ShouldNotBe(null); // clean up db.PeopleExtras.DeleteOnSubmit(extraValue); db.Contributions.DeleteOnSubmit(db.Contributions.First(mm => mm.ContributionId == c.ContributionId)); db.SubmitChanges(); }
public void TestOrgGroupsMethods() { var controller = new OrgGroupsController(FakeRequestManager.Create()); var routeDataValues = new Dictionary <string, string>(); controller.ControllerContext = ControllerTestUtils.FakeControllerContext(controller, routeDataValues); var db = DatabaseFixture.NewDbContext(); var groupNames = new [] { "Test Group", "Another Name", "Yet Another" }; var memtags = db.OrgMemMemTags.Where(nn => groupNames.Contains(nn.MemberTag.Name)); db.OrgMemMemTags.DeleteAllOnSubmit(memtags); var groups = db.MemberTags.Where(nn => groupNames.Contains(nn.Name)); db.MemberTags.DeleteAllOnSubmit(groups); var org = db.LoadOrganizationByName("App Testing Org"); var m = new OrgGroupsModel(db, org.OrganizationId); // MakeNewGroup m.GroupName = groupNames[0]; var r = controller.MakeNewGroup(m); r.ShouldBeOfType <RedirectResult>(); var g = db.MemberTags.SingleOrDefault(gg => gg.Name == groupNames[0]); g.ShouldNotBeNull(); // MakeLeaderOfTargetGroup const int pid = 2; // David Carroll m.List.Add(pid); r = controller.MakeLeaderOfTargetGroup(m); r.ShouldBeOfType <ViewResult>(); var mt = db.OrgMemMemTags.SingleOrDefault(gg => gg.OrgId == org.OrganizationId && gg.PeopleId == pid); mt.ShouldNotBeNull(); // RemoveAsLeaderOfTargetGroup db = DatabaseFixture.NewDbContext(); r = controller.RemoveAsLeaderOfTargetGroup(m); r.ShouldBeOfType <ViewResult>(); mt = db.OrgMemMemTags.SingleOrDefault(gg => gg.OrgId == org.OrganizationId && gg.PeopleId == pid); Assert.NotNull(mt); mt.IsLeader.ShouldBe(false); // RemoveSelectedFromTargetGroup r = controller.RemoveSelectedFromTargetGroup(m); r.ShouldBeOfType <ViewResult>(); mt = db.OrgMemMemTags.SingleOrDefault(gg => gg.OrgId == org.OrganizationId && gg.PeopleId == pid); mt.ShouldBeNull(); // RenameGroup m.GroupName = groupNames[1]; r = controller.RenameGroup(m); r.ShouldBeOfType <RedirectResult>(); g = db.MemberTags.SingleOrDefault(gg => gg.OrgId == org.OrganizationId && gg.Name == groupNames[1]); Assert.NotNull(g); g.Name.ShouldBe(groupNames[1]); // EditGroup m.GroupName = groupNames[2]; m.CheckInCapacityDefault = 10; r = controller.EditGroup(m); r.ShouldBeOfType <RedirectResult>(); db = DatabaseFixture.NewDbContext(); g = db.MemberTags.SingleOrDefault(gg => gg.OrgId == org.OrganizationId && gg.Name == groupNames[2]); Assert.NotNull(g); g.Name.ShouldBe(groupNames[2]); g.CheckInCapacityDefault.ShouldBe(10); // DeleteGroup m.GroupName = groupNames[2]; r = controller.DeleteGroup(m); r.ShouldBeOfType <RedirectResult>(); g = db.MemberTags.SingleOrDefault(gg => gg.OrgId == org.OrganizationId && gg.Name == groupNames[2]); g.ShouldBeNull(); // todo: to complete the remaining methods // DeleteGroups // UpdateScore // UploadScores // SwapPlayers // CreateTeams // AssignSelectedToTargetGroup // ToggleCheckin }