Exemplo n.º 1
0
        public void TestRemoveRessourceAsync(IRessourceService manager)
        {
            manager.SetRessource <RessourceString>(new RessourceString("test", "value", CultureInfo.GetCultureInfo(1)));
            var awaitingResult = manager.RemoveRessourceAsync <RessourceString>("test");

            awaitingResult.Wait(100);
            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));

            manager.Flush();

            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));

            manager.SetRessource <RessourceString>(new RessourceString("test", "value", CultureInfo.GetCultureInfo(1)));
            manager.Flush();

            awaitingResult = manager.RemoveRessourceAsync <RessourceString>("test");
            awaitingResult.Wait(100);

            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));

            manager.Flush();

            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));
        }
Exemplo n.º 2
0
        public void TestGetSetRessource(IRessourceService manager)
        {
            //create 2 resource with different type
            manager.SetRessource(new RessourceString("Test.Ressource1", "test value"));
            manager.SetRessource(new RessourceBinary("Test.Ressource1", System.Text.Encoding.ASCII.GetBytes("test value")));

            var ressource = manager.GetRessource <RessourceString>("Test.Ressource1");

            Assert.IsTrue(ressource.Id == "Test.Ressource1");
            Assert.IsTrue(ressource.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Value == "test value");

            manager.RemoveRessource <RessourceString>("Test.Ressource1");

            Assert.IsFalse(manager.ContainsRessource <RessourceString>("Test.Ressource1"));
            Assert.IsTrue(manager.ContainsRessource <RessourceBinary>("Test.Ressource1"));

            var ressourceb = manager.GetRessource <RessourceBinary>("Test.Ressource1");

            Assert.IsTrue(ressourceb.Id == "Test.Ressource1");
            Assert.IsTrue(ressourceb.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(System.Text.Encoding.ASCII.GetString(ressourceb.Value) == "test value");

            //add ressource with another culture
            manager.SetRessource(new RessourceString("Test.Ressource1", "test value in fr", CultureInfo.GetCultureInfo("fr")));

            //ressource is overrided but save in culture of ressource manager
            ressource = manager.GetRessource <RessourceString>("Test.Ressource1");
            Assert.IsTrue(ressource.Id == "Test.Ressource1");
            Assert.IsTrue(ressource.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Value == "test value in fr");

            manager.Flush();

            ressource = manager.GetRessource <RessourceString>("Test.Ressource1");
            Assert.IsTrue(ressource.Id == "Test.Ressource1");
            Assert.IsTrue(ressource.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Value == "test value in fr");

            ressourceb = manager.GetRessource <RessourceBinary>("Test.Ressource1");
            Assert.IsTrue(ressourceb.Id == "Test.Ressource1");
            Assert.IsTrue(ressourceb.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(System.Text.Encoding.ASCII.GetString(ressourceb.Value) == "test value");
        }
Exemplo n.º 3
0
        public void TestPerformanceGetRessource(IRessourceService managerEn, IRessourceService managerFr)
        {
            //i will create 100000 ressource string
            var tot = 10000;

            for (var i = 1; i <= tot; i++)
            {
                managerEn.SetRessource(new RessourceString($"Test.Ressource{i}", $"Test value {i}"));
            }

            managerEn.Flush();

            for (var i = 1; i <= tot; i++)
            {
                managerFr.SetRessource(new RessourceString($"Test.Ressource{i}", $"Test value {i} in fr"));
            }

            managerFr.Flush();

            var ressource = managerEn.GetRessource <RessourceString>($"Test.Ressource{tot}");

            Assert.IsTrue(ressource.Id == $"Test.Ressource{tot}");
            Assert.IsTrue(ressource.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Value == $"Test value {tot}");

            managerEn.SetRessource(new RessourceString($"Test.Ressource{tot}", $"Test value ok"));

            managerEn.Flush();

            ressource = managerEn.GetRessource <RessourceString>($"Test.Ressource{tot}");
            Assert.IsTrue(ressource.Id == $"Test.Ressource{tot}");
            Assert.IsTrue(ressource.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Value == "Test value ok", ressource.Value);

            ressource = managerEn.GetRessource <RessourceString>($"Test.Ressource1");
            Assert.IsTrue(ressource.Id == $"Test.Ressource1");
            Assert.IsTrue(ressource.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Value == "Test value 1", ressource.Value);
        }
Exemplo n.º 4
0
        public void TestRemoveRessource(IRessourceService manager)
        {
            manager.SetRessource <RessourceString>(new RessourceString("test", "value", CultureInfo.GetCultureInfo(1)));
            manager.RemoveRessource <RessourceString>("test");
            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));

            manager.Flush();

            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));

            manager.SetRessource <RessourceString>(new RessourceString("test", "value", CultureInfo.GetCultureInfo(1)));
            manager.Flush();
            manager.RemoveRessource <RessourceString>("test");
            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));

            manager.Flush();

            Assert.IsNull(manager.GetRessource <RessourceString>("test"));
            Assert.IsFalse(manager.ContainsRessource <RessourceString>("test"));
        }