Exemple #1
0
 public void GenericAction_NotAnnotated()
 {
     ODataTests.CreateTestSite();
     try
     {
         ODataTests.Error error;
         using (var output = new System.IO.StringWriter())
         {
             var pc      = ODataTests.CreatePortalContext("/OData.svc/Root('IMS')/TestAction0", "", output);
             var handler = new ODataHandler();
             handler.ProcessRequest(pc.OwnerHttpContext, "POST", null);
             error = ODataTests.GetError(output);
         }
         Assert.IsTrue(error.Message.ToLower().Contains("access denied"));
     }
     finally
     {
         ODataTests.CleanupTestSite();
     }
 }
Exemple #2
0
 public void GenericAction_SingleContent()
 {
     ODataTests.CreateTestSite();
     try
     {
         ODataTests.Entity entity;
         using (var output = new System.IO.StringWriter())
         {
             var pc      = ODataTests.CreatePortalContext("/OData.svc/Root('IMS')/TestAction3", "", output);
             var handler = new ODataHandler();
             var stream  = ODataTests.CreateRequestStream(String.Concat("{ path: '", User.Administrator.Path, "' }"));
             handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
             entity = ODataTests.GetEntity(output);
         }
         Assert.AreEqual(1, entity.Id);
     }
     finally
     {
         ODataTests.CleanupTestSite();
     }
 }
Exemple #3
0
 public void GenericAction_RightOverload()
 {
     ODataTests.CreateTestSite();
     try
     {
         string result;
         using (var output = new System.IO.StringWriter())
         {
             var pc      = ODataTests.CreatePortalContext("/OData.svc/Root('IMS')/TestAction2", "", output);
             var handler = new ODataHandler();
             var stream  = ODataTests.CreateRequestStream("{iii: 42, sss: 'asdf' }");
             handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
             result = ODataTests.GetStringResult(output);
         }
         Assert.AreEqual("asdf: 42", result);
     }
     finally
     {
         ODataTests.CleanupTestSite();
     }
 }
Exemple #4
0
 public void GenericAction_MultipleContents()
 {
     ODataTests.CreateTestSite();
     try
     {
         ODataTests.Entities entities;
         using (var output = new System.IO.StringWriter())
         {
             var pc      = ODataTests.CreatePortalContext("/OData.svc/Root('IMS')/TestAction4", "$orderby=Name&$filter=Id lt 11", output);
             var handler = new ODataHandler();
             var stream  = ODataTests.CreateRequestStream("{ path: '/Root/IMS/BuiltIn/Portal' }");
             handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
             entities = ODataTests.GetEntities(output);
         }
         var actual = String.Join(", ", entities.Select(e => e.Name));
         Assert.AreEqual("Admin, Administrators, Creators, Everyone, LastModifiers, Visitor", actual);
     }
     finally
     {
         ODataTests.CleanupTestSite();
     }
 }
Exemple #5
0
        public void Aspect_OData_LongTextDoesNotContainCdata()
        {
            var fieldValue = "<p>Field value</p>";
            var aspect     = EnsureAspect("LongTextTest");

            aspect.AddFields(new FieldInfo {
                Name = "Field1", Type = "LongText"
            });

            var content = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString());

            content.AddAspects(aspect);
            content["LongTextTest.Field1"] = fieldValue;
            content.Save();

            var uri = ODataTools.GetODataUrl(content);

            ODataTests.CreateTestSite();
            ODataTests.Entity entity;
            try
            {
                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(uri, "", output);
                    var handler = new ODataHandler();
                    handler.ProcessRequest(pc.OwnerHttpContext, "GET", null);
                    entity = ODataTests.GetEntity(output);
                }
                var value       = entity.AllProperties["LongTextTest.Field1"];
                var jvalue      = value as JValue;
                var stringValue = (string)jvalue.Value;
                Assert.AreEqual(fieldValue, stringValue);
            }
            finally
            {
                ODataTests.CleanupTestSite();
            }
        }
Exemple #6
0
        public void Aspect_OData_AddRemoveFields()
        {
            var aspect = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString());

            aspect.Save();
            //var aspectPath = aspect.Path;
            var resourcePath = ODataHandler.GetEntityUrl(aspect.Path);

            var content = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString());

            content.AddAspects(aspect.Path);
            content.Save();

            var odataHandlerAcc        = new PrivateType(typeof(ODataHandler));
            var originalActionResolver = odataHandlerAcc.GetStaticProperty("ActionResolver");

            odataHandlerAcc.SetStaticProperty("ActionResolver", new ODataTests.TestActionResolver());

            var fieldInfosJson = GetJson(new[] {
                new FieldInfo {
                    Name = "Field1", Type = "ShortText"
                },
                new FieldInfo {
                    Name = "Field2", Type = "ShortText"
                },
                new FieldInfo {
                    Name = "Field3", Type = "ShortText"
                },
            });

            ODataTests.CreateTestSite();
            try
            {
                string result;
                Field  field;

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddFields"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{fields:", fieldInfosJson, "}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field1", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field2", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field));
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field4", out field));

                fieldInfosJson = GetJson(new[] {
                    new FieldInfo {
                        Name = "Field4", Type = "ShortText"
                    },
                });

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddFields"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{fields:", fieldInfosJson, "}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field1", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field2", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field4", out field));

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveFields"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{fields:[\"Field1\"]}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field1", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field2", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field4", out field));

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveFields"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{fields:[\"Field4\",\"Field2\"]}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field1", out field));
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field2", out field));
                Assert.IsTrue(content.Fields.TryGetValue(aspect.Name + ".Field3", out field));
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field4", out field));

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAllFields"), "", output);
                    var handler = new ODataHandler();
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", null);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field1", out field));
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field2", out field));
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field3", out field));
                Assert.IsFalse(content.Fields.TryGetValue(aspect.Name + ".Field4", out field));
            }
            finally
            {
                odataHandlerAcc.SetStaticProperty("ActionResolver", originalActionResolver);
                content.DeletePhysical();
                ODataTests.CleanupTestSite();
            }
        }
Exemple #7
0
        public void Aspect_OData_AddRemoveAspect()
        {
            var content = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString());

            content.Save();
            var resourcePath = ODataHandler.GetEntityUrl(content.Path);
            var aspect1      = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString());

            aspect1.Save();
            var aspect1Path = aspect1.Path;
            var aspect2     = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString());

            aspect2.Save();
            var aspect2Path = aspect2.Path;
            var aspect3     = Content.CreateNew("Aspect", Repository.AspectsFolder, Guid.NewGuid().ToString());

            aspect3.Save();
            var aspect3Path = aspect3.Path;

            var odataHandlerAcc        = new PrivateType(typeof(ODataHandler));
            var originalActionResolver = odataHandlerAcc.GetStaticProperty("ActionResolver");

            odataHandlerAcc.SetStaticProperty("ActionResolver", new ODataTests.TestActionResolver());

            ODataTests.CreateTestSite();
            try
            {
                string result;

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddAspects"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect1Path, "\"]}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler));
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler));
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler));

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/AddAspects"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect2Path, "\", \"", aspect3Path, "\"]}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler));
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler));
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler));

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAspects"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect1Path, "\", \"", aspect3Path, "\"]}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler));
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler));
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler));

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAspects"), "", output);
                    var handler = new ODataHandler();
                    var stream  = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect2Path, "\"]}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", stream);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler));
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler));
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler));


                content.AddAspects((Aspect)aspect1.ContentHandler, (Aspect)aspect2.ContentHandler, (Aspect)aspect3.ContentHandler);
                content.Save();
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler));
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler));
                Assert.IsTrue(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler));

                using (var output = new System.IO.StringWriter())
                {
                    var pc      = ODataTests.CreatePortalContext(string.Concat("/OData.svc", resourcePath, "/RemoveAllAspects"), "", output);
                    var handler = new ODataHandler();
                    //var stream = ODataTests.CreateRequestStream(String.Concat("{aspects:[\"", aspect2Path, "\"]}"));
                    handler.ProcessRequest(pc.OwnerHttpContext, "POST", null);
                    result = output.GetStringBuilder().ToString();
                }
                content = Content.Load(content.Path);
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect1.ContentHandler));
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect2.ContentHandler));
                Assert.IsFalse(((GenericContent)content.ContentHandler).HasReference("Aspects", aspect3.ContentHandler));
            }
            finally
            {
                odataHandlerAcc.SetStaticProperty("ActionResolver", originalActionResolver);
                content.DeletePhysical();
                ODataTests.CleanupTestSite();
            }
        }