Exemplo n.º 1
0
        public void TestUnSerialize()
        {
            var ressource = new RessourceString("test", "value", CultureInfo.GetCultureInfo(1));

            using (var stream = new MemoryStream())
            {
                var settings = new XmlWriterSettings
                {
                    Encoding           = Encoding.UTF8,
                    Indent             = true,
                    OmitXmlDeclaration = true,
                };
                using (var writer = XmlWriter.Create(stream, settings))
                {
                    ressource.Serialize(writer, null);
                }
                var settingsString = Encoding.UTF8.GetString(stream.ToArray()).Trim();
                settingsString = settingsString.RemoveByteOrderMarkUtf8();
                var xdoc         = XDocument.Parse(settingsString);
                var newressource = new RessourceString();
                using (var reader = xdoc.Root.CreateReader())
                {
                    newressource.UnSerialize(reader, null);
                }
                Assert.IsTrue(newressource.Value == "value");
            }
        }
Exemplo n.º 2
0
        public void TestClone()
        {
            var ressource  = new RessourceString("test", "value", CultureInfo.GetCultureInfo(1));
            var ressource2 = ressource.Clone() as IRessource <string>;

            Assert.IsFalse(ressource == ressource2);
            Assert.IsTrue(ressource.Id == ressource2.Id);
            Assert.IsTrue(ressource.Culture == ressource2.Culture);
            Assert.IsTrue(ressource.Value == ressource2.Value);
        }
Exemplo n.º 3
0
        public void TestInitialize()
        {
            var ressource = new RessourceString();

            Assert.IsTrue(string.IsNullOrWhiteSpace(ressource.Value));
            Assert.IsFalse(ressource.HasValue);

            ressource = new RessourceString("test", "value", CultureInfo.GetCultureInfo(1));
            Assert.IsTrue(ressource.Value == "value");
            Assert.IsTrue(ressource.HasValue);

            ressource = new RessourceString("test", "", CultureInfo.GetCultureInfo(1));
            Assert.IsTrue(ressource.Value == "[Shiva.Ressources.RessourceString]{test:ar}", ressource.Value);
            Assert.IsFalse(ressource.HasValue);
        }
Exemplo n.º 4
0
        public void FailUnserialize()
        {
            var ressource = new RessourceString("test", "value", CultureInfo.GetCultureInfo(1));

            ressource.Invoking(x => x.UnSerialize(null, null)).Should().Throw <ArgumentNullException>();

            var xdoc = XDocument.Parse(@"<test></test>");

            using (var reader = xdoc.CreateReader())
            {
                ressource.Invoking(x => x.UnSerialize(reader, null))
                .Should()
                .Throw <InvalidOperationException>();
            }
        }
Exemplo n.º 5
0
        public void FailGroup(IRessourceService manager)
        {
            var r1 = new RessourceString("test.fail", "value1");

            manager.Invoking(x => x.AttachRessourceToGroup <RessourceString>(null, "test")).Should().Throw <ArgumentNullException>();
            manager.Invoking(x => x.AttachRessourceToGroup <RessourceString>(new RessourceString(), "test")).Should().Throw <InvalidOperationException>();
            manager.Invoking(x => x.AttachRessourceToGroup <RessourceString>(r1, null)).Should().Throw <ArgumentNullException>();
            manager.Invoking(x => x.DetachRessourceToGroup <RessourceString>(null, "test")).Should().Throw <ArgumentNullException>();
            manager.Invoking(x => x.DetachRessourceToGroup <RessourceString>(new RessourceString(), "test")).Should().Throw <InvalidOperationException>();
            manager.Invoking(x => x.DetachRessourceToGroup <RessourceString>(r1, null)).Should().Throw <ArgumentNullException>();
            manager.Invoking(x => x.GetGroupRessources <RessourceString>((Identity)null)).Should().Throw <ArgumentNullException>();
            manager.Invoking(x => x.GetGroupRessources <RessourceString>((Namespace)null, true)).Should().Throw <ArgumentNullException>();
            manager.Invoking(x => x.RemoveGroup((Identity)null)).Should().Throw <ArgumentNullException>();
            manager.Invoking(x => x.AttachRessourceToGroup(r1, "test")).Should().Throw <InvalidOperationException>();
        }
Exemplo n.º 6
0
        public void TestPerformanceGroup(IRessourceService manager)
        {
            //i will create 100000 ressource string
            var tot = 10000;

            for (var i = 1; i <= tot; i++)
            {
                var r = new RessourceString($"Test.Ressource{i}", $"Test value {i}");
                manager.SetRessource(r);
                if (i % 100 == 0)
                {
                    manager.AttachRessourceToGroup(r, "Test");
                }
            }

            manager.Flush();

            var grp = manager.GetGroupRessources <RessourceString>("Test");

            Assert.IsTrue(grp.Ressources.Count == 100, grp.Ressources.Count.ToString());
        }
Exemplo n.º 7
0
        public void FailSerialize()
        {
            var ressource = new RessourceString("test", "value", CultureInfo.GetCultureInfo(1));

            ressource.Invoking(x => x.Serialize(null, null)).Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 8
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");
        }