示例#1
0
        public void TestGroup(IRessourceService manager)
        {
            var r1 = new RessourceString("Test.test1", "value1");
            var r2 = new RessourceString("Test2.test2", "value2");
            var r3 = new RessourceString("Test.child.test3", "value3");

            manager.SetRessource <RessourceString>(r1);
            manager.SetRessource <RessourceString>(r2);
            manager.SetRessource <RessourceString>(r3);

            manager.AttachRessourceToGroup <RessourceString>(r1, "grp1");
            manager.AttachRessourceToGroup <RessourceString>(r2, "grp2");
            manager.AttachRessourceToGroup <RessourceString>(r3, "grp2");

            Assert.IsTrue(manager.GetAllGroups().Count() == 2, manager.GetAllGroups().Count().ToString());

            var grp1 = manager.GetGroupRessources <RessourceString>((Identity)"grp1");

            Assert.IsTrue(grp1.Culture == manager.Culture);
            Assert.IsTrue(grp1.Id == "grp1");
            Assert.IsTrue(grp1.Ressources.Count == 1);
            Assert.IsTrue(grp1.Ressources.First().Id == "Test.test1");
            Assert.IsTrue(grp1.Ressources.First().Value == "value1");

            var grp2 = manager.GetGroupRessources <RessourceString>((Identity)"grp2");

            Assert.IsTrue(grp2.Culture == manager.Culture);
            Assert.IsTrue(grp2.Id == "grp2");
            Assert.IsTrue(grp2.Ressources.Count == 2);
            Assert.IsTrue(grp2.Ressources.First().Id == "Test2.test2");
            Assert.IsTrue(grp2.Ressources.First().Value == "value2");
            Assert.IsTrue(grp2.Ressources.Last().Id == "Test.child.test3");
            Assert.IsTrue(grp2.Ressources.Last().Value == "value3");

            manager.Flush();

            Assert.IsTrue(manager.GetAllGroups().Count() == 2, manager.GetAllGroups().Count().ToString());

            var r4 = new RessourceString("Test.test2", "value2");

            manager.SetRessource <RessourceString>(r4);
            manager.AttachRessourceToGroup <RessourceString>(r1, "grp4");

            Assert.IsTrue(manager.GetAllGroups().Count() == 3);

            manager.DetachRessourceToGroup <RessourceString>(r3, "grp2");

            grp2 = manager.GetGroupRessources <RessourceString>((Identity)"grp2");
            Assert.IsTrue(grp2.Culture == manager.Culture);
            Assert.IsTrue(grp2.Id == "grp2");
            Assert.IsTrue(grp2.Ressources.Count == 1);
            Assert.IsTrue(grp2.Ressources.First().Id == "Test2.test2");
            Assert.IsTrue(grp2.Ressources.First().Value == "value2");

            manager.AttachRessourceToGroup <RessourceString>(r1, "grp2");

            manager.Flush();

            grp2 = manager.GetGroupRessources <RessourceString>((Identity)"grp2");
            Assert.IsTrue(grp2.Culture == manager.Culture);
            Assert.IsTrue(grp2.Id == "grp2");
            Assert.IsTrue(grp2.Ressources.Count == 2);


            var grpnamespace = manager.GetGroupRessources <RessourceString>((Namespace)"Test", false);

            Assert.IsTrue(grpnamespace.Culture == manager.Culture);
            Assert.IsTrue(grpnamespace.Id == "Test");
            Assert.IsTrue(grpnamespace.Ressources.Count == 2);
            Assert.IsTrue(grpnamespace.Ressources.First().Id == "Test.test1");
            Assert.IsTrue(grpnamespace.Ressources.First().Value == "value1");

            grpnamespace = manager.GetGroupRessources <RessourceString>((Namespace)"Test", true);
            Assert.IsTrue(grpnamespace.Culture == manager.Culture);
            Assert.IsTrue(grpnamespace.Id == "Test");
            Assert.IsTrue(grpnamespace.Ressources.Count == 3);
            Assert.IsTrue(grpnamespace.Ressources.First().Id == "Test.test1");
            Assert.IsTrue(grpnamespace.Ressources.First().Value == "value1");
        }