Exemplo n.º 1
0
        public void TryGetEnumerationValueDisplayName_WithResourceManager()
        {
            var resourceManagerStub = MockRepository.GenerateStub <IResourceManager>();

            resourceManagerStub.Stub(_ => _.IsNull).Return(false);
            resourceManagerStub.Stub(_ => _.TryGetString(Arg.Is("enumName"), out Arg <string> .Out("expected").Dummy)).Return(true);

            _globalizationServiceStub.Stub(_ => _.GetResourceManager(TypeAdapter.Create(typeof(EnumWithResources)))).Return(resourceManagerStub);
            _memberInformationNameResolverStub.Stub(_ => _.GetEnumName(EnumWithResources.Value1)).Return("enumName");

            string resourceValue;

            Assert.That(_service.TryGetEnumerationValueDisplayName(EnumWithResources.Value1, out resourceValue), Is.True);
            Assert.That(resourceValue, Is.EqualTo("expected"));
        }
        public void TryGetExtensibleEnumValueDisplayName_WithResourceManager_ReturnsLocalizedValue()
        {
            var resourceManagerStub = MockRepository.GenerateStub <IResourceManager>();

            resourceManagerStub.Stub(_ => _.IsNull).Return(false);
            _globalizationServiceStub
            .Stub(_ => _.GetResourceManager(TypeAdapter.Create(typeof(ColorExtensions))))
            .Return(resourceManagerStub);
            resourceManagerStub
            .Stub(
                _ => _.TryGetString(
                    Arg.Is("Color.Red"),
                    out Arg <string> .Out("expected").Dummy))
            .Return(true);

            string resourceValue;

            Assert.That(_service.TryGetExtensibleEnumValueDisplayName(Color.Values.Red(), out resourceValue), Is.True);
            Assert.That(resourceValue, Is.EqualTo("expected"));
        }