Exemple #1
0
        public void CreateCommentForum_CreateCommentAsNonAgreedTermsAndConditionsUser()
        {
            Console.WriteLine("Before CreateCommentAsNonAgreedTermsAndConditionsUser");

            var request = new DnaTestURLRequest("identity606");

            string userName = "******" + DateTime.Now.Ticks;
            string userEmail = userName + "@bbc.co.uk";
            request.SetCurrentUserSuperUser();
            /*
            Assert.IsTrue(
                request.SetCurrentUserAsNewIdentityUser(userName, "password", "Comment User", userEmail, "1989-12-31",
                                                        TestUserCreator.IdentityPolicies.Adult, "identity606",
                                                        TestUserCreator.UserType.SuperUser),
                "Failed to create a test identity user");
            */
            string id = "FunctiontestCommentForum-" + Guid.NewGuid(); //have to randomize the string to post
            string title = "Functiontest Title";
            string parentUri = "http://www.bbc.co.uk/dna/h2g2/";
            string commentForumXml = String.Format("<commentForum xmlns=\"BBC.Dna.Api\">" +
                                                   "<id>{0}</id>" +
                                                   "<title>{1}</title>" +
                                                   "<parentUri>{2}</parentUri>" +
                                                   "</commentForum>", id, title, parentUri);

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/",
                                       "identity606");

            try
            {
                // now get the response
                request.RequestPageWithFullURL(url, commentForumXml, "text/xml");
            }
            catch
            {
            }
            ;

            Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.OK);

            userName = "******" + DateTime.Now.Ticks;
            userEmail = userName + "@bbc.co.uk";
            //Assert.IsTrue(request.SetCurrentUserAsNewIdentityUser(userName, "password", "Comment User", userEmail, "1989-12-31", TestUserCreator.IdentityPolicies.Adult, true, false, 1, false), "Failed to create a test identity user");

            Cookie cookie;
            Cookie secureCookie;
            string identityUserID;
            Assert.IsTrue(TestUserCreator.CreateIdentityUser(userName, "password", "1989-12-31", userEmail,
                                                             "Comment User", true,
                                                             TestUserCreator.IdentityPolicies.Adult, false, 0,
                                                             out cookie,
                                                             out secureCookie,
                                                             out identityUserID));

            request.UseDebugUser = false;
            request.ClearCookieContainer();
            request.UseIdentitySignIn = true;

            request.CurrentCookie = cookie.Value;
            request.CurrentSecureCookie = secureCookie.Value;

            string text = "Functiontest Title" + Guid.NewGuid();
            commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" +
                                            "<text>{0}</text>" +
                                            "</comment>", text);

            // Setup the comment request url - needs to be secure
            url =
                String.Format(
                    "https://" + _secureServer + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/",
                    "identity606", id);

            try
            {
                // now get the response
                request.RequestPageWithFullURL(url, commentForumXml, "text/xml");
            }
            catch
            {
            }
            ;

            Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.Unauthorized);

            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();

            var nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("bda", "BBC.Dna.Api");
            Assert.IsNotNull(xml.SelectSingleNode("//bda:error/bda:code", nsmgr), "Failed to find the error code");
            Assert.AreEqual("FailedTermsAndConditions", xml.SelectSingleNode("//bda:error/bda:code", nsmgr).InnerText);
            Assert.IsNotNull(xml.SelectSingleNode("//bda:error/bda:detail", nsmgr), "Failed to find the error deatils");
            Assert.AreEqual("comment",
                            xml.SelectSingleNode("//bda:error/bda:detail", nsmgr).InnerText);

            Console.WriteLine("After CreateCommentAsNonAgreedTermsAndConditionsUser");
        }