public void Test1_CheckPromptSetUserNameNotVisibleOnSiteWithSiteOptionNotSet()
        {
            // Create a mocked input context for the test
            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            // Create a profileAPI for the test
            int userID = GetNextUserID;
            IDnaIdentityWebServiceProxy mockedProfileAPI = DnaMockery.CreateMockedProfileConnection(context, userID, "testUser", "BBCUID-Testing", "[email protected]", userID.ToString() + "123456789012345678901234567890abcdefghijklmnopqrstuvwxyz", true);

            // Create a mocked site
            ISite mockedSite = DnaMockery.CreateMockedSite(context, 1, "h2g2", "h2g2", true, "comment");

            // Create the site options for the new mocked site
            SiteOptionList siteOptionList = new SiteOptionList();
            siteOptionList.CreateFromDatabase(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default);
            siteOptionList.SetValueBool(1, "Moderation", "SetNewUsersNickNames", false, DnaMockery.CreateDatabaseReaderCreator(),null);
            siteOptionList.SetValueBool(1, "General", "CheckUserNameSet", false, DnaMockery.CreateDatabaseReaderCreator(), null);

            // Stub the call to the siteoption
            Stub.On(context).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Create the user
            User testUser = new User(context);
            testUser.CreateUser();

            // Check the XML
            XmlNode userXml = testUser.RootElement.SelectSingleNode("//USER");
            Assert.AreEqual(null, userXml.SelectSingleNode("PROMPTSETUSERNAME"), "The prompt set username should not be pressent in the user xml");
            Assert.AreEqual("U" + testUser.UserID.ToString(), userXml.SelectSingleNode("USERNAME").InnerText, "The username should be set to U" + userID.ToString() + " in the user xml");
        }
예제 #2
0
        public void TestBannedEmailIsHandledCorrectlyUsingMockedObjects()
        {
            Console.WriteLine("Before TestBannedEmailIsHandledCorrectlyUsingMockedOnbjects");
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            DnaCookie testCookie = new DnaCookie();
            testCookie.Value = TestUserAccounts.GetNormalUserAccount.Cookie; //"6042002|DotNetNormalUser|DotNetNormalUser|1273497514775|0|bf78fdd57a1f70faee630c07ba31674eab181a3f6c6f";
            testCookie.Name = "IDENTITY";
             
            DnaCookie testCookie2 = new DnaCookie();
            testCookie2.Value = TestUserAccounts.GetNormalUserAccount.SecureCookie; //"1eda650cb28e56156217427336049d0b8e164765";
            testCookie2.Name = "IDENTITY-HTTPS";
           
            //DnaCookie testCookie = new DnaCookie();
            //testCookie.Value = "THIS-IS-A-TEST-COOKIE-THAT-IS-LONGER-THAN-SIXTYFOUR-CHARACTURES-LONG";
            //testCookie.Name = "SSO2-UID";

            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY").Will(Return.Value(testCookie));
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY-HTTPS").Will(Return.Value(testCookie2));
            Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            CreateMockedProfileConnection(mockery, mockedInput, 1063883681, "Fink", "TEST-TEST-TEST", "*****@*****.**", true);

            SetDefaultDiagnostics(mockery, mockedInput);

            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");
            // CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            CreateMockedReaderForUserNotInDataBase(mockery, mockedInput);

            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 1, true);
            
            // Ok, create the user object and try to create the user.
            User testUser = new User(mockedInput);
            testUser.CreateUser();

            // The expect Once call on the IsEmailInBannedList procedure should indicate that the second call to the create method is using the
            // cookie banned list functionality.
            User testUser2 = new User(mockedInput);
            testUser2.CreateUser();

            // This will fail if the create user call got to check the data base more than once!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("After TestBannedEmailIsHandledCorrectlyUsingMockedObjects");
        }
예제 #3
0
        public void Test6CheckUserNameChange()
        {
            Console.WriteLine("Before Test6CheckUserNameChange");
            string originalUserName = _testUser.UserName;

            //change to new user name
            string newUserName = originalUserName + "new";
            _testUser.BeginUpdateDetails();
            _testUser.SetUsername(newUserName);
            _testUser.UpdateDetails();

            using (FullInputContext fullinputcontext = new FullInputContext(TestUserAccounts.GetProfileAPITestUserAccount.UserName))
            {
                fullinputcontext.SetCurrentSite("h2g2");
                fullinputcontext.InitUserFromCookie(TestUserAccounts.GetProfileAPITestUserAccount.Cookie, TestUserAccounts.GetProfileAPITestUserAccount.SecureCookie);
                User tempUser = new User(fullinputcontext);
                tempUser.CreateUser(_testUser.UserID);
                Assert.AreEqual(tempUser.UserName, newUserName);
            }

            //change back to old user name
            _testUser.BeginUpdateDetails();
            _testUser.SetUsername(originalUserName);
            _testUser.UpdateDetails();

            using (FullInputContext fullinputcontext = new FullInputContext(TestUserAccounts.GetProfileAPITestUserAccount.UserName))
            {
                fullinputcontext.SetCurrentSite("h2g2");
                fullinputcontext.InitUserFromCookie(TestUserAccounts.GetProfileAPITestUserAccount.Cookie, TestUserAccounts.GetProfileAPITestUserAccount.SecureCookie);
                User tempUser = new User(fullinputcontext);
                tempUser.CreateUser(_testUser.UserID);
                Assert.AreEqual(tempUser.UserName, originalUserName);
            }
            

            Console.WriteLine("After Test6CheckUserNameChange");
        }
예제 #4
0
        /// <summary>
        /// Initialises a new default user from a sso uid
        /// </summary>
        public void InitUserFromCookie(string identity, string identityHttps)
        {
            if (_identityCookie == null)
            {
                _identityCookie = new DnaCookie(new System.Web.HttpCookie("IDENTITY"));
                _identitySecureCookie = new DnaCookie(new System.Web.HttpCookie("IDENTITY-HTTPS"));
            }
            _identityCookie.Value = identity;
            _identitySecureCookie.Value = identityHttps;

            _viewingUser = new BBC.Dna.User(this);
            _viewingUser.CreateUser();
        }
예제 #5
0
        public void TestServiceWithNoEmailAttributeCreatesUsers()
        {
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");

            // Create the input context to run the requests in
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            // Create the invalid cookie. Invalid cookies are less or equal to 64 chars long
            DnaCookie cookie = new DnaCookie();
            cookie.Name = "SSO2-UID";
            cookie.Value = "VALID-COOKIE-ABCDEFGHIJKLMNOPQRRSTUVWXYZ-SSO-NORMAL-USER-ACCOUNT";

            // Stub the cookie to the context
			Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            // Now add the mocked profile connection
            CreateMockedProfileConnection(mockery, mockedInput, 106663681, "Fink", "TEST-TEST-TEST-NOEMAIL-ATTRIBUTE", "", false);

            SetDefaultDiagnostics(mockery, mockedInput);

            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            IDnaDataReader mockedNormalUserReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedNormalUserReader).Method("AddParameter").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Execute").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Dispose").Will(Return.Value(null));
            Stub.On(mockedNormalUserReader).Method("Read").Will(Return.Value(false));

            // Create an action list for the HasRows property
            IAction mockReaderResults = new MockedReaderResults(new bool[] { false, true, true });
            Stub.On(mockedNormalUserReader).GetProperty("HasRows").Will(mockReaderResults);

            // These both need to return the same results, so use the same mocked reader for both requests
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("fetchusersgroups").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("finduserfromid").Will(Return.Value(mockedNormalUserReader));
            //Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromSSOUserID").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromIdentityUserID").Will(Return.Value(mockedNormalUserReader));
            
            // Create the mocked data reader for the createnewuserfromuserid call
            CreateMockedCreateUserDataReader(mockery, mockedInput, 106663681);

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Ok, create the user object and try to create the user.
            User testUser = new User(mockedInput);
            testUser.CreateUser();

            // This will fail if the create user call got to check the data base more than twice!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");
        }
예제 #6
0
        public void TestBannedUserCaughtEvenWithinvalidCookie()
        {
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");

            // Create the input context to run the requests in
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            // Create the invalid cookie. Invalid cookies are less or equal to 64 chars long
            DnaCookie cookie = new DnaCookie();
            cookie.Name = "SSO2-UID";
            cookie.Value = "INVALID-COOKIE";

            // Stub the cookie to the context
			Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            // Now add the mocked profile connection
            CreateMockedProfileConnection(mockery, mockedInput, 106663681, "BadFink", "TEST-TEST-TEST-BANNED-USER", "*****@*****.**", true);

            // Set the diagnostics for the context
            SetDefaultDiagnostics(mockery, mockedInput);

            // Add the site for the context
            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            CreateMockedReaderForUserNotInDataBase(mockery, mockedInput);

            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 2, true);

            // Now create the banned user for the first time.
            User bannedUser = new User(mockedInput);
            bannedUser.CreateUser();

            // Now call the create method again. This should also check the database
            bannedUser.CreateUser();

            // This will fail if the create user call got to check the data base more than twice!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");
        }
예제 #7
0
        public void TestNonBannedUserWithInvalidCookieGetsCreatedOk()
        {
            Console.WriteLine("Before TestNonBannedUserWithInvalidCookieGetsCreatedOk");
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            DnaCookie testCookie = new DnaCookie();
            testCookie.Value = "THIS-IS-A-TEST-COOKIE-THAT-IS-NOT-VALID";
            testCookie.Name = "SSO2-UID";
			Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(testCookie));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            CreateMockedProfileConnection(mockery, mockedInput, 1063883681, "Fink", "TEST-TEST-TEST", "*****@*****.**", true);

            SetDefaultDiagnostics(mockery, mockedInput);

            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            IDnaDataReader mockedNormalUserReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedNormalUserReader).Method("AddParameter").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Execute").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Dispose").Will(Return.Value(null));
            Stub.On(mockedNormalUserReader).Method("Read").Will(Return.Value(false));

            // Create an action list for the HasRows property
            IAction mockReaderResults = new MockedReaderResults(new bool[] { false, true, true });
            Stub.On(mockedNormalUserReader).GetProperty("HasRows").Will(mockReaderResults);

            // These both need to return the same results, so use the same mocked reader for both requests
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("fetchusersgroups").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("finduserfromid").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromSSOUserID").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromIdentityUserID").Will(Return.Value(mockedNormalUserReader));

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Create the mocked data reader for the createnewuserfromuserid call
            CreateMockedCreateUserDataReader(mockery, mockedInput, 106663681);

            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 1, false);

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Ok, create the user object and try to create the user.
            User testUser = new User(mockedInput);
            testUser.CreateUser();

            // This will fail if the create user call got to check the data base more than once!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("After TestNonBannedUserWithInvalidCookieGetsCreatedOk");
        }
예제 #8
0
        //See above - work with Mark H to understand what the test is for.
        public void TestNormalUserCanBeCreatedAfterABannedUserIsCaught()
        {
            Console.WriteLine("Before TestNormalUserCanBeCreatedAfterABannedUserIsCaught");
            
            // Start by creating two contexts. One for each request
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();
            IInputContext mockedInput2 = mockery.NewMock<IInputContext>();

            DnaCookie testBannedCookie = new DnaCookie();
            testBannedCookie.Value = TestUserAccounts.GetBannedUserAccount.Cookie; //"6042004|DotNetUserBanned|DotNetUserBanned|1273497847257|0|9d9ee980c4b831e419915b452b050f327862bba748ff";
            testBannedCookie.Name = "IDENTITY";

            DnaCookie testBannedCookie2 = new DnaCookie();
            testBannedCookie2.Value = TestUserAccounts.GetBannedUserAccount.SecureCookie; //"a684c1a5736f052c4acc1b35908f8dbad2e2ea0b";
            testBannedCookie2.Name = "IDENTITY-HTTPS";

            DnaCookie testNormalCookie = new DnaCookie();
            testNormalCookie.Value = TestUserAccounts.GetBannedUserAccount.Cookie; //"6042002|DotNetNormalUser|DotNetNormalUser|1273497514775|0|bf78fdd57a1f70faee630c07ba31674eab181a3f6c6f";
            testNormalCookie.Name = "IDENTITY";

            DnaCookie testNormalCookie2 = new DnaCookie();
            testNormalCookie2.Value = TestUserAccounts.GetBannedUserAccount.SecureCookie; // "1eda650cb28e56156217427336049d0b8e164765";
            testNormalCookie2.Name = "IDENTITY-HTTPS";

            // Now set the two test cookies. One for each user
            DnaCookie cookie1 = new DnaCookie();
            cookie1.Name = "SSO2-UID";
            cookie1.Value = "VALID-COOKIE-ABCDEFGHIJKLMNOPQRRSTUVWXYZ-SSO-BANNED-USER-ACCOUNT";

            DnaCookie cookie2 = new DnaCookie();
            cookie2.Name = "SSO2-UID";
            cookie2.Value = "VALID-COOKIE-ABCDEFGHIJKLMNOPQRRSTUVWXYZ-SSO-NORMAL-USER-ACCOUNT";

            // Stub the cookies to the contexts
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY").Will(Return.Value(testBannedCookie));
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY-HTTPS").Will(Return.Value(testBannedCookie2));

            Stub.On(mockedInput2).Method("GetCookie").With("IDENTITY").Will(Return.Value(testNormalCookie));
            Stub.On(mockedInput2).Method("GetCookie").With("IDENTITY-HTTPS").Will(Return.Value(testNormalCookie2));
            
            Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie1));
			Stub.On(mockedInput2).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie2));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
			Stub.On(mockedInput2).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));
            Stub.On(mockedInput2).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            // Now add the mocked profile connections
            CreateMockedProfileConnection(mockery, mockedInput, 106663681, "BadFink", "TEST-TEST-TEST-BANNED-USER", "*****@*****.**", true);
            IDnaIdentityWebServiceProxy mockedGoodProfile = CreateMockedProfileConnection(mockery, mockedInput2, 1063883681, "GoodFink", "TEST-TEST-TEST-NORMAL-USER", "*****@*****.**", true);

            // Create the mocked data reader for the createnewuserfromuserid call
            CreateMockedCreateUserDataReader(mockery, mockedInput2, 106663681);

            // Set the diagnostics for the contexts
            SetDefaultDiagnostics(mockery, mockedInput);
            SetDefaultDiagnostics(mockery, mockedInput2);

            // Add the site for the contexts
            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");
            CreateMockedSite(mockery, mockedInput2, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            CreateMockedReaderForUserNotInDataBase(mockery, mockedInput);

            //CreateMockedReaderForUserNotInDataBase(mockery, mockedInput2);
            IDnaDataReader mockedNormalUserReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedNormalUserReader).Method("AddParameter").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Execute").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Dispose").Will(Return.Value(null));
            Stub.On(mockedNormalUserReader).Method("Read").Will(Return.Value(false));

            // Create an action list for the Read and HasRows method/property
            IAction mockReaderResults = new MockedReaderResults(new bool[] {false,true,true});
            Stub.On(mockedNormalUserReader).GetProperty("HasRows").Will(mockReaderResults);

            // These both need to return the same results, so use the same mocked reader for both requests
            Stub.On(mockedInput2).Method("CreateDnaDataReader").With("fetchusersgroups").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput2).Method("CreateDnaDataReader").With("finduserfromid").Will(Return.Value(mockedNormalUserReader));
            //Stub.On(mockedInput2).Method("CreateDnaDataReader").With("GetDnaUserIDFromSSOUserID").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput2).Method("CreateDnaDataReader").With("GetDnaUserIDFromIdentityUserID").Will(Return.Value(mockedNormalUserReader));
            
            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 1, true);
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput2, 1, false);

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));
            Stub.On(mockedInput2).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Now do the test.
            // 1. Test banned user is caught and not created in the database
            // 2. Test that a normal user can be created after the banned user
            // 3. Test to make sure the banned user is caught by the banned cookie list with out calling the database.

            // Banned user first call. This should check the database and then add their cookie to the list
            User bannedUser = new User(mockedInput);
            bannedUser.CreateUser();

            // Normal user. This should check the database and return false for being in the banned list. This should create the user in the database.
            User normalUser = new User(mockedInput2);
            normalUser.CreateUser();

            // Banned user second call. This should not call the database, but be caught by the cookie list.
            bannedUser.CreateUser();

            // This will fail if the create user call got to check the data base more than once for both users!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("After TestNormalUserCanBeCreatedAfterABannedUserIsCaught");
        }
예제 #9
0
        public void CheckPrefStatusAndGroupForUsersWhenChangingModerationStatus()
        {
            Console.WriteLine("Starting CheckPrefStatusAndChangedDateForUserBeingPutIntoPreMod");

            // Restore the database
            SnapshotInitialisation.RestoreFromSnapshot();

            // Create a context capable for creating real data readers
            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            ISite mockedSite = DnaMockery.CurrentMockery.NewMock<ISite>();
            Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));
            Stub.On(mockedSite).GetProperty("UseIdentitySignInSystem").Will(Return.Value(false));
            Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            // Mock the siteoption call for the checkusernameset option
            Stub.On(context).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            IDnaIdentityWebServiceProxy mockedSignIn = DnaMockery.CurrentMockery.NewMock<IDnaIdentityWebServiceProxy>();
            Stub.On(mockedSignIn).GetProperty("GetCookieValue").Will(Return.Value(""));
            Stub.On(context).GetProperty("GetCurrentSignInObject").Will(Return.Value(mockedSignIn));

            // Create a new user in the database for h2g2
            int userID = CreateUserInDatabase(context);

            // Now put the user into premod
            SetUsersModerationStatus(context, userID, 1);

            // Check to make sure that users is not in the premod group.
            //CheckUserBelongsToGroup(context, userID, "PREMODERATED", false);
            User user = new User(context);
            user.CreateUser(userID);

            // Check to make sure that the status of the user is correct
            CheckUsersPrefStatus(context, userID, 1);

            // Users Moderation Status is no longer put into GROUPS.
            CheckUserXML(context, userID, ModerationUserStatuses.Status.Premoderated);

            // Now put the user into premod
            SetUsersModerationStatus(context, userID, 2);

            // Check to make sure that users is not in the premod group.
            CheckUserXML(context, userID, ModerationUserStatuses.Status.Postmoderated);

            // Check to make sure that the status of the user is correct
            CheckUsersPrefStatus(context, userID, 2);

            // Now put the user into premod
            SetUsersModerationStatus(context, userID, 3);

            // Check to make sure that the status of the user is correct
            CheckUsersPrefStatus(context, userID, 3);

            // Now put the user into premod
            SetUsersModerationStatus(context, userID, 4);

            // Check to make sure that users is not in the premod group.
            CheckUserXML(context, userID, ModerationUserStatuses.Status.Restricted);

            // Check to make sure that the status of the user is correct
            CheckUsersPrefStatus(context, userID, 4);


            // Now put the user into premod
            SetUsersModerationStatus(context, userID, 0);

            // Check to make sure that the status of the user is correct
            CheckUsersPrefStatus(context, userID, 0);

            // Check to see if they are in the correct group in the XML
            CheckUserXML(context, userID, ModerationUserStatuses.Status.Standard);

            Console.WriteLine("Finishing CheckPrefStatusAndChangedDateForUserBeingPutIntoPreMod");
        }
예제 #10
0
        /// <summary>
        /// Helper method for checking if a user belongs to a given group. This is done by checking the XML for the user
        /// </summary>
        /// <param name="context">The context in which to create the object</param>
        /// <param name="userID">The id of the user you want to check against</param>
        /// <param name="groupToCheck">The group you want tocheck against</param>
        /// <param name="expectedResult">The expected outcome of the test</param>
        private static void CheckUserXML(IInputContext context, int userID, ModerationUserStatuses.Status prefStatus )
        {
            // Create a user object using this userid so we can check that the XML contains the correct group information
            User user = new User(context);
            user.CreateUser(userID);

           /* IDnaDataReader mockedReader = DnaMockery.CurrentMockery.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("UserName").Will(Return.Value("MR TESTER"));
            Stub.On(mockedReader).Method("DoesFieldExist").With("ZeitgeistScore").Will(Return.Value(false));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("FirstNames").Will(Return.Value("MR"));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("LastName").Will(Return.Value("TESTER"));
            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("Status").Will(Return.Value(1));
            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("TaxonomyNode").Will(Return.Value(0));
            Stub.On(mockedReader).Method("GetBoolean").With("Active").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("UserName").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("ZeitgeistScore").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("FirstNames").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("LastName").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("Status").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("TaxonomyNode").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("Active").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("SiteSuffix").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Exists").With("Journal").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Exists").With("Area").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Exists").With("Title").Will(Return.Value(false));
            user.AddUserXMLBlock(mockedReader, userID, parentNode); */

            XmlNode parentNode = user.RootElement;

            // Check to see if the user belongs to the group
            /*XmlNode groupNode = parentNode.SelectSingleNode("//GROUPS/GROUP/NAME['" + groupToCheck + "']");

            if (expectedResult)
            {
                Assert.IsNotNull(groupNode, "Failed to find expected group - " + groupToCheck);
            }
            else
            {
                Assert.IsNull(groupNode, "The user should not belong to this group - " + groupToCheck);
            }*/

            //Check Users Pref / /Mod Status
            XmlNode node = parentNode.SelectSingleNode("//USER/MODERATIONSTATUS[@ID=" + (int) prefStatus + "]");
            Assert.IsNotNull(node, "User Pref Status XML Check");
        }