Ejemplo n.º 1
0
        public void Should_be_able_to_get_MemberTypeCodes()
        {
            ContextTestUtils.CreateMockHttpContext();
            var b = CodeValueModel.MemberTypeCodes();

            b.Count().ShouldBe(16);
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        public void Should_be_able_to_get_BundleStatusTypes()
        {
            ContextTestUtils.CreateMockHttpContext();
            var b = CodeValueModel.BundleStatusTypes();

            b.Count().ShouldBe(2);
        }
Ejemplo n.º 4
0
 public FakeRequestManager()
 {
     CurrentHttpContext   = ContextTestUtils.CreateMockHttpContext().Object;
     CurrentDatabase      = CMSDataContext.Create(DatabaseFixture.Host);
     CurrentImageDatabase = CMSImageDataContext.Create(DatabaseFixture.Host);
     CurrentUser          = CurrentHttpContext.User;
     RequestId            = Guid.NewGuid();
 }
Ejemplo n.º 5
0
 public FakeRequestManager(bool isAuthenticated)
 {
     CurrentHttpContext   = ContextTestUtils.CreateMockHttpContext(isAuthenticated).Object;
     CurrentDatabase      = CMSDataContext.Create(DatabaseFixture.Host);
     CurrentImageDatabase = CMSImageDataContext.Create(DatabaseFixture.Host);
     CurrentUser          = CurrentHttpContext.User;
     RequestId            = Guid.NewGuid();
     SessionProvider      = new CmsSessionProvider(CurrentDatabase);
 }
Ejemplo n.º 6
0
        public void Should_Run_FulfillmentList()
        {
            ContextTestUtils.CreateMockHttpContext();
            var m = new RegistrationsModel();

            m.PeopleId = 1;
            var fulfillmentlist = m.FulfillmentList();

            fulfillmentlist.ShouldNotBeNull();
        }
Ejemplo n.º 7
0
 public void Should_be_able_to_get_ContactReasonCodes()
 {
     ContextTestUtils.CreateMockHttpContext();
     using (var db = CMSDataContext.Create(DatabaseFixture.Host))
     {
         var cv = new CodeValueModel(db);
         var b  = cv.ContactReasonCodes();
         b.Count().ShouldBe(8);
     }
 }
Ejemplo n.º 8
0
        public void Should_Run_FulfillmentList()
        {
            using (var db = CMSDataContext.Create(Util.Host))
            {
                ContextTestUtils.CreateMockHttpContext();
                var m = new RegistrationsModel(db);
                m.PeopleId = 1;
                var fulfillmentlist = m.FulfillmentList();

                fulfillmentlist.ShouldNotBeNull();
            }
        }
Ejemplo n.º 9
0
 public void FetchPeople_ApostropheSearch_Test(string name)
 {
     using (var db = CMSDataContext.Create(DatabaseFixture.Host))
     {
         ContextTestUtils.CreateMockHttpContext();
         var m = new PeopleSearchModel(db);
         var p = MockPeople.CreateSavePerson(db, lastName: name);
         m.m.name = name.Replace("'", string.Empty);
         var people = m.FetchPeople().Any();
         people.ShouldBeTrue();
     }
 }
        public void OnEnrollTest()
        {
            var context = ContextTestUtils.CreateMockHttpContext();
            var org     = CreateOrganization();
            var person  = CreatePerson();
            var om      = OrganizationMember.AddOrgMember(db, org.OrganizationId, person.PeopleId, MemberTypeCode.Member, DateTime.Now, org.OrganizationName);

            org.UpdateRegSetting(new Settings
            {
                AskItems = new List <Ask>(new Ask[] {
                    new AskText {
                        Name = "ImportantQuestion"
                    },
                    new AskCheckboxes {
                        Name = "Options",
                        list = new List <AskCheckboxes.CheckboxItem>(new[] {
                            new AskCheckboxes.CheckboxItem {
                                Name = "Item 1"
                            }
                        })
                    }
                })
            });
            db.SubmitChanges();
            var notify = db.StaffPeopleForOrg(om.OrganizationId).First();

            var personModel = new OnlineRegModel(db)
            {
                Orgid        = om.OrganizationId,
                UserPeopleId = om.PeopleId,
            };
            var model = new OnlineRegPersonModel(db)
            {
                orgid       = om.OrganizationId,
                Parent      = personModel,
                PeopleId    = om.PeopleId,
                FirstName   = om.Person.FirstName,
                LastName    = om.Person.LastName,
                Checkbox    = new List <string>(new[] { "Item 1" }),
                QuestionsOK = true,
                Text        = new List <Dictionary <string, string> >(new[] { new Dictionary <string, string>() })
            };

            model.Text.First()["ImportantQuestion"] = "ImportantAnswer";
            var script = "OnEnrollTest";

            db.WriteContentPython(script, @"print(Data)");
            model.setting.OnEnrollScript = script;
            model.OnEnroll(om);
            model.ScriptResults.Trim().ShouldBe($@"{{
  ""PeopleId"": {om.PeopleId},
  ""OrganizationId"": {om.OrganizationId},
  ""OnlineNotifyId"": {notify.PeopleId},
  ""OnlineNotifyEmail"": ""{notify.EmailAddress}"",
  ""OnlineNotifyName"": ""{notify.Name}"",
  ""LoggedIn"": true,
  ""FirstName"": ""{person.FirstName}"",
  ""LastName"": ""{person.LastName}"",
  ""TextQuestion"": {{
    ""ImportantQuestion"": ""ImportantAnswer""
  }},
  ""Checkbox"": {{
    ""Item 1"": true
  }}
}}".Replace("\r", ""));
        }