Beispiel #1
0
        public void Logger_Audit_Default()
        {
            Test(() =>
            {
                // operations for a "content created" audit event
                var folder = new SystemFolder(Repository.Root)
                {
                    Name = "Folder1"
                };
                folder.Save();
                var folderId = folder.Id;

                // operations for a "content modified" audit event
                folder = Node.Load <SystemFolder>(folderId);
                folder.Index++;
                folder.Save();

                // operations for a "content deleted" audit event
                folder = Node.Load <SystemFolder>(folderId);
                folder.ForceDelete();

                // load audit log entries
                var entries        = DataStore.GetDataProviderExtension <ITestingDataProviderExtension>().LoadLastAuditLogEntries(10);
                var relatedEntries = entries.Where(e => e.ContentId == folderId).ToArray();

                // assertions
                Assert.AreEqual(3, relatedEntries.Length);
                var messages = string.Join(", ", relatedEntries.Select(e => e.Message).ToArray());
                Assert.AreEqual("ContentCreated, ContentUpdated, ContentDeleted", messages);
            });
        }
Beispiel #2
0
        public void Settings_WrongExtension()
        {
            var r = new SystemFolder(TestRoot)
            {
                Name = "R"
            }; r.Save();

            try
            {
                var rS = new Folder(r)
                {
                    Name = Settings.SETTINGSCONTAINERNAME
                }; rS.Save();
                var rS1 = new Settings(rS)
                {
                    Name = "Settings1"
                };
                rS1.Binary.SetStream(Tools.GetStreamFromString("{x: 1, y: 2, z: 3}"));
                rS1.Save();
            }
            finally
            {
                r.ForceDelete();
            }
        }
 public void SystemFlag_OnFolderUnderSystemFolder()
 {
     IntegrationTest(() =>
     {
         var root = new SystemFolder(Repository.Root)
         {
             Name = Guid.NewGuid().ToString()
         };
         root.Save();
         var folder = new Folder(root)
         {
             Name = Guid.NewGuid().ToString()
         };
         folder.Save();
         try
         {
             var x = Node.LoadNode(folder.Id);
             Assert.IsTrue(x.IsSystem);
         }
         finally
         {
             root.ForceDelete();
         }
     });
 }
Beispiel #4
0
        private async Task IntegrationTestAsync(bool isolated, Func <Task> callback, Func <SystemFolder, Task> callbackWithSandbox)
        {
            var platformName   = Platform.GetType().Name;
            var needToStartNew = isolated || _repositoryInstance == null || platformName != _lastPlatformName;

            if (needToStartNew)
            {
                Logger.Log("  (cleanup repository)");
                _repositoryInstance?.Dispose();
                _repositoryInstance = null;
                _lastPlatformName   = null;

                var builder = Platform.CreateRepositoryBuilder();

                Logger.Log("  start new repository");
                _repositoryInstance = Repository.Start(builder);
                _lastPlatformName   = platformName;

                //PrepareRepository();
            }

            SystemFolder sandbox = null;

            try
            {
                using (new SystemAccount())
                {
                    if (callback != null)
                    {
                        await callback();
                    }
                    else
                    {
                        await callbackWithSandbox(sandbox = CreateSandbox());
                    }
                }
            }
            finally
            {
                if (sandbox != null)
                {
                    using (new SystemAccount())
                        sandbox.ForceDelete();
                }

                if (isolated)
                {
                    Logger.Log("  cleanup repository");
                    _repositoryInstance?.Dispose();
                    _repositoryInstance = null;
                    _lastPlatformName   = null;
                }
            }
        }
        public void PredicationEngine_Deleted()
        {
            Test(() =>
            {
                var testNode = new SystemFolder(Repository.Root)
                {
                    Name = "TestRoot"
                };
                testNode.Save();
                testNode.ForceDelete();

                var testContent = testNode.Content ?? Content.Create(testNode);
                var prE         = new PredicationEngine(testContent);

                Assert.IsTrue(prE.IsTrue("Name:TestRoot"));
            });
        }
Beispiel #6
0
        public void Settings_Duplication()
        {
            // R
            //     (settings)
            //         Settings1.settings
            //         F
            //             Settings1.settings (error: duplicated)

            var r = new SystemFolder(TestRoot)
            {
                Name = "R"
            }; r.Save();

            try
            {
                var rS = new Folder(r)
                {
                    Name = Settings.SETTINGSCONTAINERNAME
                }; rS.Save();
                var rSf = new Folder(rS)
                {
                    Name = "F"
                }; rSf.Save();

                var rS1 = new Settings(rS)
                {
                    Name = "Settings1.settings"
                };
                rS1.Binary.SetStream(Tools.GetStreamFromString("{x: 1, y: 2, z: 3}"));
                rS1.Save();

                var rSf1 = new Settings(rS)
                {
                    Name = "Settings1.settings"
                };
                rSf1.Binary.SetStream(Tools.GetStreamFromString("{x: 1, y: 2, z: 3}"));
                rSf1.Save();
            }
            finally
            {
                r.ForceDelete();
            }
        }
        public void ContentProtector_ExtendTheList()
        {
            // TEST-1: The "TestFolder" is protected.
            Test(builder =>
            {
                // Protect a content with the white list extension
                builder.ProtectContent("/Root/TestFolder");
            }, () =>
            {
                var node = new SystemFolder(Repository.Root)
                {
                    Name = "TestFolder"
                };
                node.Save();

                try
                {
                    node.ForceDelete();
                    Assert.Fail("The expected exception was not thrown.");
                }
                catch (ApplicationException)
                {
                    // do nothing
                }
            });

            // CLEANUP: Restore the original list
            Providers.Instance.ContentProtector = new ContentProtector();

            // TEST-2: The "TestFolder" is deletable.
            Test(() =>
            {
                var node = new SystemFolder(Repository.Root)
                {
                    Name = "TestFolder"
                };
                node.Save();

                node.ForceDelete();
            });
        }
Beispiel #8
0
        private void IntegrationTest(Action <RepositoryBuilder> initialize,
                                     Action callback, Action <SystemFolder> callbackWithSandbox)
        {
            var builder = Platform.CreateRepositoryBuilder();

            initialize?.Invoke(builder);

            using (var repository = Repository.Start(builder))
            {
                Cache.Reset();
                ContentTypeManager.Reset();

                this.Platform.OnAfterRepositoryStart(repository);

                SystemFolder sandbox = null;
                try
                {
                    using (new SystemAccount())
                    {
                        TestInitializer?.Invoke(builder);
                        if (callback != null)
                        {
                            callback();
                        }
                        else
                        {
                            callbackWithSandbox(sandbox = CreateSandbox());
                        }
                    }
                }
                finally
                {
                    if (sandbox != null)
                    {
                        using (new SystemAccount())
                            sandbox.ForceDelete();
                    }
                }
            }
        }
Beispiel #9
0
        private async Task IntegrationTestAsync(Action <RepositoryBuilder> initialize,
                                                Func <Task> callback, Func <SystemFolder, Task> callbackWithSandbox)
        {
            var builder = InitIntegrationTest(initialize);

            using (var repository = Repository.Start(builder))
            {
                Cache.Reset();
                ContentTypeManager.Reset();

                this.Platform.OnAfterRepositoryStart(repository);

                SystemFolder sandbox = null;
                try
                {
                    using (new SystemAccount())
                    {
                        TestInitializer?.Invoke(builder);
                        if (callback != null)
                        {
                            await callback();
                        }
                        else
                        {
                            await callbackWithSandbox(sandbox = CreateSandbox());
                        }
                    }
                }
                finally
                {
                    if (sandbox != null)
                    {
                        using (new SystemAccount())
                            sandbox.ForceDelete();
                    }
                }
            }
        }
        public void SystemFlag_Move_FromSystemFolderToFolder()
        {
            IntegrationTest(() =>
            {
                var srcParent = new SystemFolder(Repository.Root)
                {
                    Name = "Source-" + Guid.NewGuid()
                };
                srcParent.Save();
                var target = new Folder(Repository.Root)
                {
                    Name = "Target-" + Guid.NewGuid()
                };
                target.Save();
                var nodeIds = CreateSourceStructure(srcParent);
                Node f1, f2, s3, f4, s5, f6, f7, f8, f9, f10, f11, f12;
                try
                {
                    f1  = Node.LoadNode(nodeIds["F1"]);
                    f2  = Node.LoadNode(nodeIds["F2"]);
                    s3  = Node.LoadNode(nodeIds["S3"]);
                    f4  = Node.LoadNode(nodeIds["F4"]);
                    s5  = Node.LoadNode(nodeIds["S5"]);
                    f6  = Node.LoadNode(nodeIds["F6"]);
                    f7  = Node.LoadNode(nodeIds["F7"]);
                    f8  = Node.LoadNode(nodeIds["F8"]);
                    f9  = Node.LoadNode(nodeIds["F9"]);
                    f10 = Node.LoadNode(nodeIds["F10"]);
                    f11 = Node.LoadNode(nodeIds["F11"]);
                    f12 = Node.LoadNode(nodeIds["F12"]);

                    Assert.IsTrue(f1.IsSystem, "F1");
                    Assert.IsTrue(f2.IsSystem, "F2");
                    Assert.IsTrue(s3.IsSystem, "S3");
                    Assert.IsTrue(f4.IsSystem, "F4");
                    Assert.IsTrue(s5.IsSystem, "S5");
                    Assert.IsTrue(f6.IsSystem, "F6");
                    Assert.IsTrue(f7.IsSystem, "F7");
                    Assert.IsTrue(f8.IsSystem, "F8");
                    Assert.IsTrue(f9.IsSystem, "F9");
                    Assert.IsTrue(f10.IsSystem, "F10");
                    Assert.IsTrue(f11.IsSystem, "F11");
                    Assert.IsTrue(f12.IsSystem, "F12");

                    f1.MoveTo(target);

                    f1  = Node.LoadNode(nodeIds["F1"]);
                    f2  = Node.LoadNode(nodeIds["F2"]);
                    s3  = Node.LoadNode(nodeIds["S3"]);
                    f4  = Node.LoadNode(nodeIds["F4"]);
                    s5  = Node.LoadNode(nodeIds["S5"]);
                    f6  = Node.LoadNode(nodeIds["F6"]);
                    f7  = Node.LoadNode(nodeIds["F7"]);
                    f8  = Node.LoadNode(nodeIds["F8"]);
                    f9  = Node.LoadNode(nodeIds["F9"]);
                    f10 = Node.LoadNode(nodeIds["F10"]);
                    f11 = Node.LoadNode(nodeIds["F11"]);
                    f12 = Node.LoadNode(nodeIds["F12"]);

                    Assert.IsFalse(f1.IsSystem, "F1");
                    Assert.IsFalse(f2.IsSystem, "F2");
                    Assert.IsTrue(s3.IsSystem, "S3");
                    Assert.IsFalse(f4.IsSystem, "F4");
                    Assert.IsTrue(s5.IsSystem, "S5");
                    Assert.IsFalse(f6.IsSystem, "F6");
                    Assert.IsTrue(f7.IsSystem, "F7");
                    Assert.IsTrue(f8.IsSystem, "F8");
                    Assert.IsFalse(f9.IsSystem, "F9");
                    Assert.IsFalse(f10.IsSystem, "F10");
                    Assert.IsTrue(f11.IsSystem, "F11");
                    Assert.IsTrue(f12.IsSystem, "F12");

                    Assert.AreEqual(6, GetSystemFlagRelatedContentCount(false));
                    Assert.AreEqual(12, GetSystemFlagRelatedContentCount(true));
                }
                finally
                {
                    srcParent.ForceDelete();
                    target.ForceDelete();
                }
            });
        }
Beispiel #11
0
        public void Settings_NestedObject()
        {
            ContentTypeInstaller.InstallContentType(NotLoadableAspect.CTD);
            var z = new NotLoadableAspect(Repository.AspectsFolder)
            {
                Name = "z"
            };

            z.Save();

            // R
            //     (settings)
            //         Settings1.settings
            //     C
            var n = Node.LoadNode(TestRoot.Path + "/R");

            if (n != null)
            {
                n.ForceDelete();
            }

            var x = 42m;
            var y = "'aa'";
            var a = 44m;
            var b = "'bb'";
            var r = new SystemFolder(TestRoot)
            {
                Name = "R"
            }; r.Save();

            try
            {
                var rS = new Folder(r)
                {
                    Name = Settings.SETTINGSCONTAINERNAME
                }; rS.Save();
                var rSf = new Folder(rS)
                {
                    Name = "F"
                }; rSf.Save();

                var rS1 = new Settings(rS)
                {
                    Name = "Settings1.settings"
                };
                rS1.Binary.SetStream(Tools.GetStreamFromString("{x: " + x + ", y: " + y + ", z: {a:" + a + ", b: " + b + "}}"));
                rS1.Binary.FileName = rS1.Name;
                rS1.Save();

                var rc = Content.CreateNew("Car", r, null);
                rc.Save();

                Assert.AreEqual(x, Settings.GetValue <int>("Settings1", "x", rc.Path));
                Assert.AreEqual(y.Trim('\''), Settings.GetValue <string>("Settings1", "y", rc.Path));
                Assert.AreEqual(a, Settings.GetValue <int>("Settings1", "z.a", rc.Path));
                Assert.AreEqual(b.Trim('\''), Settings.GetValue <string>("Settings1", "z.b", rc.Path));

                var settingsContent = Content.Load(rS1.Id);

                Assert.AreEqual(x, (decimal)settingsContent["x"]);
                Assert.AreEqual(y.Trim('\''), (string)settingsContent["y"]);
                Assert.AreEqual(a, (decimal)settingsContent["z.a"]);
                Assert.AreEqual(b.Trim('\''), (string)settingsContent["z.b"]);

                // different internal content creation
                rS1             = (Settings)Node.LoadNode(rS1.Id);
                settingsContent = Content.Create(rS1);

                Assert.AreEqual(x, (decimal)settingsContent["x"]);
                Assert.AreEqual(y.Trim('\''), (string)settingsContent["y"]);
                Assert.AreEqual(a, (decimal)settingsContent["z.a"]);
                Assert.AreEqual(b.Trim('\''), (string)settingsContent["z.b"]);
            }
            finally
            {
                r.ForceDelete();
                z.ForceDelete();
            }
        }
Beispiel #12
0
        public void Settings_OverridingValues()
        {
            // R
            //     (settings)
            //         Settings1.settings
            //     A
            //         (settings)
            //             Settings1.settings
            //         B
            //             C
            //                 (settings)
            //                     Settings1.settings
            //                 D

            var setting1 = Tools.GetStreamFromString("{x: 1, y: 2, z: 3}");
            var setting2 = Tools.GetStreamFromString("{x: 2,       z: 6}");
            var setting3 = Tools.GetStreamFromString("{x: 3, y: 4      }");

            var r = new SystemFolder(TestRoot)
            {
                Name = "R"
            }; r.Save();

            try
            {
                var rS = new Folder(r)
                {
                    Name = Settings.SETTINGSCONTAINERNAME
                }; rS.Save();
                var rS1 = new Settings(rS)
                {
                    Name = "Settings1.settings"
                }; rS1.Binary.SetStream(setting1); rS1.Binary.FileName = rS1.Name; rS1.Save();

                var a = new SystemFolder(r)
                {
                    Name = "A"
                }; a.Save();
                var aS = new Folder(a)
                {
                    Name = Settings.SETTINGSCONTAINERNAME
                }; aS.Save();
                var aS1 = new Settings(aS)
                {
                    Name = "Settings1.settings"
                }; aS1.Binary.SetStream(setting2); aS1.Binary.FileName = aS1.Name; aS1.Save();

                var b = new SystemFolder(a)
                {
                    Name = "B"
                }; b.Save();

                var c = new SystemFolder(b)
                {
                    Name = "C"
                }; c.Save();
                var cS = new Folder(c)
                {
                    Name = Settings.SETTINGSCONTAINERNAME
                }; cS.Save();
                var cS1 = new Settings(cS)
                {
                    Name = "Settings1.settings"
                }; cS1.Binary.SetStream(setting3); cS1.Binary.FileName = cS1.Name; cS1.Save();

                var d = new SystemFolder(c)
                {
                    Name = "D"
                }; d.Save();

                // =============================== Testing Settings.GetValue API

                var rX = Settings.GetValue <int>("Settings1", "x", r.Path);
                var rY = Settings.GetValue <int>("Settings1", "y", r.Path);
                var rZ = Settings.GetValue <int>("Settings1", "z", r.Path);

                var aX = Settings.GetValue <int>("Settings1", "x", a.Path);
                var aY = Settings.GetValue <int>("Settings1", "y", a.Path);
                var aZ = Settings.GetValue <int>("Settings1", "z", a.Path);

                var bX = Settings.GetValue <int>("Settings1", "x", b.Path);
                var bY = Settings.GetValue <int>("Settings1", "y", b.Path);
                var bZ = Settings.GetValue <int>("Settings1", "z", b.Path);

                var cX = Settings.GetValue <int>("Settings1", "x", c.Path);
                var cY = Settings.GetValue <int>("Settings1", "y", c.Path);
                var cZ = Settings.GetValue <int>("Settings1", "z", c.Path);

                var dX = Settings.GetValue <int>("Settings1", "x", d.Path);
                var dY = Settings.GetValue <int>("Settings1", "y", d.Path);
                var dZ = Settings.GetValue <int>("Settings1", "z", d.Path);

                Assert.IsTrue(rX == 1, String.Format("rX is {0}, expected: 1", rX));
                Assert.IsTrue(rY == 2, String.Format("rY is {0}, expected: 2", rY));
                Assert.IsTrue(rZ == 3, String.Format("rZ is {0}, expected: 3", rZ));

                Assert.IsTrue(aX == 2, String.Format("aX is {0}, expected: 2", aX));
                Assert.IsTrue(aY == 2, String.Format("aY is {0}, expected: 2", aY));
                Assert.IsTrue(aZ == 6, String.Format("aZ is {0}, expected: 6", aZ));

                Assert.IsTrue(bX == 2, String.Format("bX is {0}, expected: 2", bX));
                Assert.IsTrue(bY == 2, String.Format("bY is {0}, expected: 2", bY));
                Assert.IsTrue(bZ == 6, String.Format("bZ is {0}, expected: 6", bZ));

                Assert.IsTrue(cX == 3, String.Format("cX is {0}, expected: 3", cX));
                Assert.IsTrue(cY == 4, String.Format("cY is {0}, expected: 4", cY));
                Assert.IsTrue(cZ == 6, String.Format("cZ is {0}, expected: 6", cZ));

                Assert.IsTrue(dX == 3, String.Format("dX is {0}, expected: 3", dX));
                Assert.IsTrue(dY == 4, String.Format("dY is {0}, expected: 4", dY));
                Assert.IsTrue(dZ == 6, String.Format("dZ is {0}, expected: 6", dZ));

                // =============================== Testing dynamic fields

                var rs1content = Content.Load(rS1.Id);
                var as1content = Content.Load(aS1.Id);
                var cs1content = Content.Load(cS1.Id);

                Assert.AreEqual(rs1content["x"], 1m, string.Format("rs1content[\"x\"] is {0}, expected: 1", rs1content["x"]));
                Assert.AreEqual(rs1content["y"], 2m, string.Format("rs1content[\"y\"] is {0}, expected: 2", rs1content["y"]));
                Assert.AreEqual(rs1content["z"], 3m, string.Format("rs1content[\"z\"] is {0}, expected: 3", rs1content["z"]));

                Assert.AreEqual(as1content["x"], 2m, string.Format("as1content[\"x\"] is {0}, expected: 2", as1content["x"]));
                Assert.AreEqual(as1content["y"], 2m, string.Format("as1content[\"y\"] is {0}, expected: 2", as1content["y"]));
                Assert.AreEqual(as1content["z"], 6m, string.Format("as1content[\"z\"] is {0}, expected: 6", as1content["z"]));

                Assert.AreEqual(cs1content["x"], 3m, string.Format("cs1content[\"x\"] is {0}, expected: 3", cs1content["x"]));
                Assert.AreEqual(cs1content["y"], 4m, string.Format("cs1content[\"y\"] is {0}, expected: 4", cs1content["y"]));
                Assert.AreEqual(cs1content["z"], 6m, string.Format("cs1content[\"z\"] is {0}, expected: 6", cs1content["z"]));
            }
            finally
            {
                r.ForceDelete();
            }
        }