private static RazorMailMessageFactory GetRazorMailMessageFactory() { var culture = new CultureInfo("en-US"); var templateResolver = new DefaultTemplateResolver("Infrastructure", "TemplateMailMessages"); var translations = new List<Translation> { new Translation("KindRegards", "Kind regards", culture), new Translation("DearSirOrMadam", "Dear sir or madam", culture), new Translation("ResetPasswordMailMessage", "ResetPasswordMailMessage", culture), new Translation("ResetPassword", "Reset password", culture) }; var translationService = new TranslationService(translations, culture); var applicationSettingsMock = new Mock<IApplicationSettings>(); applicationSettingsMock.Setup(x => x.DefaultCulture).Returns(culture); Func<Type, Object> dependencyResolver = t => { if (t == typeof (ITranslationService)) { return translationService; } if (t == typeof (IApplicationSettings)) { return applicationSettingsMock.Object; } return null; }; var factory = new RazorMailMessageFactory(templateResolver, typeof (ViewBaseClass<>), dependencyResolver); return factory; }
public void CanTranslateUsingMethodCallInsteadOfProperty() { var translations = new List<Translation> { new Translation("WelcomeMessage", "Hello this is a test", new CultureInfo("en-US")) }; var translationService = new TranslationService(translations, new CultureInfo("en-US")); Assert.AreEqual("Hello this is a test", translationService.Translate("WelcomeMessage")); }
public void CanTranslateItemWithSpecificCulture() { var translations = new List<Translation> { new Translation("WelcomeMessage", "Hello this is a test", new CultureInfo("en-US")), new Translation("WelcomeMessage", "Hallo dit is een test", new CultureInfo("nl-NL")) }; var translationService = new TranslationService(translations, new CultureInfo("en-US")); Assert.AreEqual("Hallo dit is een test", translationService.Translate("WelcomeMessage", new CultureInfo("nl-NL"))); }
public void IfTranslationForSpecificCultureDoesNotExistDefaultCutureIsUsed() { var translations = new List<Translation> { new Translation("WelcomeMessage", "Hello this is a test", new CultureInfo("en-US")) }; var translationService = new TranslationService(translations, new CultureInfo("en-US")); Assert.AreEqual("Hello this is a test", translationService.Translate("WelcomeMessage", new CultureInfo("nl-NL"))); }
public void IfTranslationDoesNotExistCodeIsReturned() { var translations = new List<Translation>(); var translationService = new TranslationService(translations, new CultureInfo("en-US")); Assert.AreEqual("WelcomeMessage", translationService.Translate.WelcomeMessage); }
public void WhenDefaultCultureIsNullServiceWillNotBreak() { var translations = new List<Translation> { new Translation("WelcomeMessage", "Hallo dit is een test", new CultureInfo("nl-NL")) }; var translationService = new TranslationService(translations, null); Assert.AreEqual("WelcomeMessage", translationService.Translate.WelcomeMessage); Assert.AreEqual("Hallo dit is een test", translationService.Translate("WelcomeMessage", new CultureInfo("nl-NL"))); }