Provides strings for TResourceSource.
Наследование: IStringLocalizer
        public void StringLocalizer_CanBeCastToBaseType()
        {
            // Arrange and act
            IStringLocalizer <BaseType> localizer = new StringLocalizer <DerivedType>(Mock.Of <IStringLocalizerFactory>());

            // Assert
            Assert.NotNull(localizer);
        }
        public void Constructor_ResolvesLocalizerFromFactory()
        {
            // Arrange
            var factory = new Mock <IStringLocalizerFactory>();

            // Act
            _ = new StringLocalizer <object>(factory.Object);

            // Assert
            factory.Verify(mock => mock.Create(typeof(object)), Times.Once());
        }
Пример #3
0
        public void Indexer_ThrowsAnExceptionForNullName()
        {
            // Arrange
            var factory        = new Mock <IStringLocalizerFactory>();
            var innerLocalizer = new Mock <IStringLocalizer>();

            factory.Setup(mock => mock.Create(typeof(object)))
            .Returns(innerLocalizer.Object);

            var localizer = new StringLocalizer <object>(factory.Object);

            // Act and assert
            var exception = Assert.Throws <ArgumentNullException>(() => localizer[name: null !]);
        public void Indexer_InvokesIndexerFromInnerLocalizer_WithArguments()
        {
            // Arrange
            var factory        = new Mock <IStringLocalizerFactory>();
            var innerLocalizer = new Mock <IStringLocalizer>();

            factory.Setup(mock => mock.Create(typeof(object)))
            .Returns(innerLocalizer.Object);

            var localizer = new StringLocalizer <object>(factory.Object);

            // Act
            _ = localizer["Welcome, {0}", "Bob"];

            // Assert
            innerLocalizer.Verify(mock => mock["Welcome, {0}", "Bob"], Times.Once());
        }
        public void GetAllStrings_InvokesGetAllStringsFromInnerLocalizer()
        {
            // Arrange
            var factory        = new Mock <IStringLocalizerFactory>();
            var innerLocalizer = new Mock <IStringLocalizer>();

            factory.Setup(mock => mock.Create(typeof(object)))
            .Returns(innerLocalizer.Object);

            var localizer = new StringLocalizer <object>(factory.Object);

            // Act
            localizer.GetAllStrings(includeParentCultures: true);

            // Assert
            innerLocalizer.Verify(mock => mock.GetAllStrings(true), Times.Once());
        }
        public void WithCulture_InvokesWithCultureFromInnerLocalizer()
        {
            // Arrange
            var factory        = new Mock <IStringLocalizerFactory>();
            var innerLocalizer = new Mock <IStringLocalizer>();

            factory.Setup(mock => mock.Create(typeof(object)))
            .Returns(innerLocalizer.Object);

            var localizer = new StringLocalizer <object>(factory.Object);

            // Act
#pragma warning disable CS0618
            localizer.WithCulture(CultureInfo.GetCultureInfo("fr-FR"));
#pragma warning restore CS0618

            // Assert
#pragma warning disable CS0618
            innerLocalizer.Verify(mock => mock.WithCulture(CultureInfo.GetCultureInfo("fr-FR")), Times.Once());
#pragma warning restore CS0618
        }