Ejemplo n.º 1
0
        /// <summary>
        /// Resolves the message against specified <see cref="IMessageSource"/>.
        /// </summary>
        /// <param name="messageSource">Message source to resolve this error message against.</param>
        /// <returns>Resolved error message.</returns>
        public string GetMessage(IMessageSource messageSource)
        {
            if (messageSource == null)
            {
                return(Id);
            }

            if (Parameters == null)
            {
                return(messageSource.GetMessage(Id));
            }
            else
            {
                return(messageSource.GetMessage(Id, Parameters));
            }
        }
        public void GetMessageParentMessageSource()
        {
            object[]       args         = new object[] { "arguments" };
            IMessageSource parentSource = A.Fake <IMessageSource>();

            A.CallTo(() => parentSource.GetMessage("null", null, CultureInfo.CurrentCulture, A <object[]> ._)).Returns("my parent message");
            ParentMessageSource = parentSource;
            Assert.AreEqual("my parent message", GetMessage("null", "message", CultureInfo.CurrentCulture, args[0]));
        }
Ejemplo n.º 3
0
        public void GetMessageCodeCultureArgs()
        {
            A.CallTo(() => mockMsgSource.GetMessage(MSGCODE, MSGCULTURE, MSGARGS)).Returns(MSGRESULT);

            MessageSourceAccessor msgSourceAccessor = new MessageSourceAccessor(mockMsgSource);

            Assert.AreEqual(MSGRESULT, msgSourceAccessor.GetMessage(MSGCODE, MSGCULTURE, MSGARGS));
        }
Ejemplo n.º 4
0
        public void GetMessageCodeCultureArgs()
        {
            Expect.Call(mockMsgSource.GetMessage(MSGCODE, MSGCULTURE, MSGARGS)).Return(MSGRESULT);
            mocks.ReplayAll();

            MessageSourceAccessor msgSourceAccessor = new MessageSourceAccessor(mockMsgSource);

            Assert.AreEqual(MSGRESULT, msgSourceAccessor.GetMessage(MSGCODE, MSGCULTURE, MSGARGS));
        }
Ejemplo n.º 5
0
        public void GetMessageParentMessageSource()
        {
            object[]       args         = new object[] { "arguments" };
            IMessageSource parentSource = mocks.StrictMock <IMessageSource>();

            Expect.Call(parentSource.GetMessage("null", null, CultureInfo.CurrentCulture, args)).Return(
                "my parent message");
            ParentMessageSource = parentSource;
            mocks.ReplayAll();
            Assert.AreEqual("my parent message", GetMessage("null", "message", CultureInfo.CurrentCulture, args[0]));
            mocks.VerifyAll();
        }
        public void GetResolvableDefaultsToParentMessageSource()
        {
            string MSGCODE = "nullCode";

            object[] MSGARGS = new object[] { "arg1", "arg2" };

            IMessageSourceResolvable res = A.Fake <IMessageSourceResolvable>();

            A.CallTo(() => res.GetArguments()).Returns(MSGARGS);
            A.CallTo(() => res.GetCodes()).Returns(new string[] { MSGCODE }).Once();

            IMessageSource parentSource = A.Fake <IMessageSource>();

            A.CallTo(() => parentSource.GetMessage(MSGCODE, null, CultureInfo.CurrentCulture, A <object[]> ._)).Returns("MockMessageSource");
            ParentMessageSource = parentSource;

            Assert.AreEqual("MockMessageSource", GetMessage(res, CultureInfo.CurrentCulture), "My Message");
        }
Ejemplo n.º 7
0
        public void GetResolvableDefaultsToParentMessageSource()
        {
            string MSGCODE = "nullCode";

            object[] MSGARGS = new object[] { "arg1", "arg2" };

            IMessageSourceResolvable res = mocks.StrictMock <IMessageSourceResolvable>();

            Expect.Call(res.GetArguments()).Return(MSGARGS);
            Expect.Call(res.GetCodes()).Return(new string[] { MSGCODE }).Repeat.Once();

            IMessageSource parentSource = mocks.StrictMock <IMessageSource>();

            Expect.Call(parentSource.GetMessage(MSGCODE, null, CultureInfo.CurrentCulture, MSGARGS)).Return(
                "MockMessageSource");
            ParentMessageSource = parentSource;

            mocks.ReplayAll();
            Assert.AreEqual("MockMessageSource", GetMessage(res, CultureInfo.CurrentCulture), "My Message");
            mocks.VerifyAll();
        }
Ejemplo n.º 8
0
        public void SpawnMessage(bool correct)
        {
            var content = _messageSource.GetMessage(correct);

            if (content != null)
            {
                var messageObject = Instantiate(_messagePrefab, transform);
                var message       = messageObject.GetComponent <Message>();
                if (message == null)
                {
                    Debug.LogError("Message game object does not contain Message script");
                }
                else
                {
                    message.SetContent(content);
                }
            }
            else
            {
                Debug.LogError($"No message content available for {correct}");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Resolves the message against specified <see cref="IMessageSource"/>.
        /// </summary>
        /// <param name="messageSource">Message source to resolve this error message against.</param>
        /// <returns>Resolved error message.</returns>
        public string GetMessage(IMessageSource messageSource)
        {
            if (messageSource == null)
            {
                return Id;
            }

            if (Parameters == null)
            {
                return messageSource.GetMessage(Id);
            }
            else
            {
                return messageSource.GetMessage(Id, Parameters);
            }
        }
        private void GetMessageLocalizationFallbacks(IMessageSource msgSource)
        {
            Assert.AreEqual("Dies ist Spring.NET",
                            msgSource.GetMessage("MyMessage", new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Isso e Spring.NET",
                            msgSource.GetMessage("MyMessage", new CultureInfo("pt-BR"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Visual Studio liebt Spring.NET",
                            msgSource.GetMessage("MyNewMessage", new object[] { "Spring", ".NET" }), "message not as expected");

            // test localization fallbacks
            Assert.AreEqual("Visual Studio loves Spring.NET",
                            msgSource.GetMessage("MyNewMessage", new CultureInfo("pt-BR"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Des is Spring.NET",
                            msgSource.GetMessage("MyMessage", new CultureInfo("de-AT"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Dies ist Spring.NET",
                            msgSource.GetMessage("MyMessage", new CultureInfo("de"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Visual Studio liebt Spring.NET",
                            msgSource.GetMessage("MyNewMessage", new CultureInfo("de-AT"), new object[] { "Spring", ".NET" }), "message not as expected");

            // extra tests for the "exotic" serbian culture
            if (!SystemUtils.MonoRuntime)
            {
                Assert.AreEqual("Ovo je Spring.NET",
                                msgSource.GetMessage("MyMessage", new CultureInfo(CultureInfoUtils.SerbianLatinCultureName), new object[] { "Spring", ".NET" }), "message not as expected");

                Assert.AreEqual("Ово је Spring.NET",
                                msgSource.GetMessage("MyMessage", new CultureInfo(CultureInfoUtils.SerbianCyrillicCultureName),
                                                     new object[] { "Spring", ".NET" }), "message not as expected");

                Assert.AreEqual("Visual Studio voli Spring.NET",
                                msgSource.GetMessage("MyNewMessage", new CultureInfo(CultureInfoUtils.SerbianCyrillicCultureName), new object[] { "Spring", ".NET" }), "message not as expected");

                Assert.AreEqual("First name",
                                msgSource.GetMessage("field.firstname", new CultureInfo(CultureInfoUtils.SerbianCyrillicCultureName)), "message not as expected");
            }
        }
        private void GetMessageLocalizationFallbacks(IMessageSource msgSource)
        {
            Assert.AreEqual("Dies ist Spring.NET",
                            msgSource.GetMessage("MyMessage", new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Isso e Spring.NET",
                            msgSource.GetMessage("MyMessage", new CultureInfo("pt-BR"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Visual Studio liebt Spring.NET",
                            msgSource.GetMessage("MyNewMessage", new object[] { "Spring", ".NET" }), "message not as expected");

            // test localization fallbacks
            Assert.AreEqual("Visual Studio loves Spring.NET",
                            msgSource.GetMessage("MyNewMessage", new CultureInfo("pt-BR"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Des is Spring.NET",
                            msgSource.GetMessage("MyMessage", new CultureInfo("de-AT"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Dies ist Spring.NET",
                            msgSource.GetMessage("MyMessage", new CultureInfo("de"), new object[] { "Spring", ".NET" }), "message not as expected");

            Assert.AreEqual("Visual Studio liebt Spring.NET",
                            msgSource.GetMessage("MyNewMessage", new CultureInfo("de-AT"), new object[] { "Spring", ".NET" }), "message not as expected");

            // extra tests for the "exotic" serbian culture
            if (!SystemUtils.MonoRuntime)
            {

                Assert.AreEqual("Ovo je Spring.NET",
                                msgSource.GetMessage("MyMessage", new CultureInfo(CultureInfoUtils.SerbianLatinCultureName), new object[] { "Spring", ".NET" }), "message not as expected");

                Assert.AreEqual("Ово је Spring.NET",
                                msgSource.GetMessage("MyMessage", new CultureInfo(CultureInfoUtils.SerbianCyrillicCultureName),
                                                         new object[] { "Spring", ".NET" }), "message not as expected");

                Assert.AreEqual("Visual Studio voli Spring.NET",
                                msgSource.GetMessage("MyNewMessage", new CultureInfo(CultureInfoUtils.SerbianCyrillicCultureName), new object[] { "Spring", ".NET" }), "message not as expected");

                Assert.AreEqual("First name",
                                msgSource.GetMessage("field.firstname", new CultureInfo(CultureInfoUtils.SerbianCyrillicCultureName)), "message not as expected");
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Retrieve the message for the given code and the default
 /// <see cref="System.Globalization.CultureInfo"/>.
 /// </summary>
 /// <param name="code">The code of the message.</param>
 /// <returns>The message.</returns>
 public string GetMessage(string code)
 {
     return(_messageSource.GetMessage(code, _defaultCultureInfo));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns message for the specified resource name.
 /// </summary>
 /// <param name="name">Resource name.</param>
 /// <returns>Message text.</returns>
 public string GetMessage(string name)
 {
     return(messageSource.GetMessage(name, UserCulture));
 }