Exemplo n.º 1
0
        public void TestGetSetRessourceAsync(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.GetRessourceAsync <RessourceString>("Test.Ressource1");

            ressource.Wait(100);
            Assert.IsTrue(ressource.IsCompleted);
            Assert.IsTrue(ressource.Result.Id == "Test.Ressource1");
            Assert.IsTrue(ressource.Result.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Result.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.GetRessourceAsync <RessourceBinary>("Test.Ressource1");

            ressourceb.Wait(100);
            Assert.IsTrue(ressourceb.IsCompleted);
            Assert.IsTrue(ressourceb.Result.Id == "Test.Ressource1");
            Assert.IsTrue(ressourceb.Result.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(System.Text.Encoding.ASCII.GetString(ressourceb.Result.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.GetRessourceAsync <RessourceString>("Test.Ressource1");
            ressource.Wait(100);
            Assert.IsTrue(ressource.IsCompleted);
            Assert.IsTrue(ressource.Result.Id == "Test.Ressource1");
            Assert.IsTrue(ressource.Result.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(ressource.Result.Value == "test value in fr");

            manager.Flush();

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

            ressourceb = manager.GetRessourceAsync <RessourceBinary>("Test.Ressource1");
            ressourceb.Wait(100);
            Assert.IsTrue(ressourceb.IsCompleted);
            Assert.IsTrue(ressourceb.Result.Id == "Test.Ressource1");
            Assert.IsTrue(ressourceb.Result.Culture == CultureInfo.GetCultureInfo("en"));
            Assert.IsTrue(System.Text.Encoding.ASCII.GetString(ressourceb.Result.Value) == "test value");
        }
Exemplo n.º 2
0
        public void FailGetSetRessource(IRessourceService manager)
        {
            manager.Invoking(x => x.GetRessource <RessourceString>(null)).Should().Throw <ArgumentNullException>();
            Func <Task> call = () => manager.GetRessourceAsync <RessourceString>(null);

            call.Should().Throw <ArgumentNullException>();

            manager.Invoking(x => x.SetRessource <RessourceString>(null)).Should().Throw <ArgumentNullException>();
            Func <Task> call2 = () => manager.SetRessourceAsync <RessourceString>(null);

            call2.Should().Throw <ArgumentNullException>();
        }