public async Task TranslateAsync_CustomPostProcessor_ShouldApplyPostProcessing() { var postProcessor = Substitute.For <IPostProcessor>(); postProcessor.Process("test", "translated", Arg.Any <IDictionary <string, object> >()).Returns("post-processed"); postProcessor.Keyword.Returns("testProcess"); _translationTree.GetValue("test", Arg.Any <IDictionary <string, object> >()).Returns("translated"); _translator.PostProcessors.Add(postProcessor); var args = new { postProcess = "testProcess" }; var result = await _translator.TranslateAsync("en-US", "test", "test", args.ToDictionary()); result.Should().Be("post-processed"); await _backend.Received(1).LoadNamespaceAsync("en-US", "test"); _translationTree.Received(1).GetValue("test", Arg.Any <IDictionary <string, object> >()); await _interpolator.ReceivedWithAnyArgs(1).InterpolateAsync(null, null, null, null); _interpolator.Received(1).CanNest("translated"); await _interpolator.ReceivedWithAnyArgs(0).NestAsync(null, null, null, null); _pluralResolver.ReceivedWithAnyArgs(0).GetPluralSuffix(null, 0); _pluralResolver.ReceivedWithAnyArgs(0).NeedsPlural(null); postProcessor.Received(1).Process("test", "translated", Arg.Any <IDictionary <string, object> >()); }
public async Task TranslateAsync_CallMultiplePostProcessors_ShouldApplyPostProcessorsInOrder() { var postProcessor1 = Substitute.For <IPostProcessor>(); postProcessor1.Process("test", "translated", Arg.Any <IDictionary <string, object> >()).Returns("post-processed1"); postProcessor1.Keyword.Returns("testProcess1"); var postProcessor2 = Substitute.For <IPostProcessor>(); postProcessor2.Keyword.Returns("testProcess2"); var postProcessor3 = Substitute.For <IPostProcessor>(); postProcessor3.Process("test", "post-processed1", Arg.Any <IDictionary <string, object> >()).Returns("post-processed3"); postProcessor3.Keyword.Returns("testProcess3"); _translationTree.GetValue("test", Arg.Any <IDictionary <string, object> >()).Returns("translated"); _translator.PostProcessors.Add(postProcessor1); _translator.PostProcessors.Add(postProcessor2); _translator.PostProcessors.Add(postProcessor3); var args = new { postProcess = new[] { "testProcess1", "testProcess3" } }; var result = await _translator.TranslateAsync("en-US", "test", args.ToDictionary(), _options); result.Should().Be("post-processed3"); await _backend.Received(1).LoadNamespaceAsync("en-US", "test"); _translationTree.Received(1).GetValue("test", Arg.Any <IDictionary <string, object> >()); await _interpolator.ReceivedWithAnyArgs(1).InterpolateAsync(null, null, null, null); _interpolator.Received(1).CanNest("translated"); await _interpolator.ReceivedWithAnyArgs(0).NestAsync(null, null, null, null); _pluralResolver.ReceivedWithAnyArgs(0).GetPluralSuffix(null, 0); _pluralResolver.ReceivedWithAnyArgs(0).NeedsPlural(null); postProcessor1.Received(1).Process("test", "translated", Arg.Any <IDictionary <string, object> >()); postProcessor2.ReceivedWithAnyArgs(0).Process(null, null, null); postProcessor3.Received(1).Process("test", "post-processed1", Arg.Any <IDictionary <string, object> >()); }