public void TestAnotherProperty() { var stringProvider = new Mock<ILocalizedStringProvider>(); var provider = new LocalizedModelMetadataProvider(stringProvider.Object); stringProvider.Setup( k => k.GetModelString(It.Is<Type>(t => t == typeof (TestModel)), It.Is<string>(t => t == "RequiredStringLength10"))). Returns("Efternamn").Verifiable(); var subject = new TestModel { RequiredStringLength10 = "Arne", Required = "hej" }; var actual = provider.GetMetadataForProperty(() => subject, typeof (TestModel), "RequiredStringLength10"); Assert.Equal("Efternamn", actual.DisplayName); stringProvider.VerifyAll(); }
public void TestNotTranslatedProperty() { DefaultUICulture.Reset(); var stringProvider = new Mock<ILocalizedStringProvider>(); var provider = new LocalizedModelMetadataProvider(stringProvider.Object); stringProvider.Setup( k => k.GetModelString(It.Is<Type>(t => t == typeof (TestModel)), It.Is<string>(t => t == "Required"))). Returns((string) null).Verifiable(); var subject = new TestModel { RequiredStringLength10 = "Arne", Required = "hej" }; var actual = provider.GetMetadataForProperty(() => subject, typeof (TestModel), "Required"); Assert.Equal(null, actual.DisplayName); }
public void TestAProperty() { var stringProvider = new Mock<ILocalizedStringProvider>(); var provider = new LocalizedModelMetadataProvider(stringProvider.Object); stringProvider.Setup( k => k.GetModelString(It.Is<Type>(t => t == typeof (MetadataTarget)), It.Is<string>(t => t == "UserName"))). Returns("Användarnamn").Verifiable(); var subject = new MetadataTarget { LastName = "Arne", UserName = "******" }; var actual = provider.GetMetadataForProperty(() => subject, typeof (MetadataTarget), "UserName"); Assert.Equal("Användarnamn", actual.DisplayName); stringProvider.VerifyAll(); }