public void DoesAddWordsGenerationServiceWork() { //arrange var expectedOptions = new WordsGenerationOptions { WordsDictionaryLocation = "words.json" }; IConfiguration configuration = new ConfigurationBuilder() .AddJsonStream( "{\"StringGenerationOptions\" : {\"WordsDictionaryLocation\" : \"words.json\"}}".ToStream()) .Build(); //act var serviceProvider = new ServiceCollection() .AddMemoryCache() .AddSingleton <IFileReader>(new FakeFileReader("[\"Hamburger\"]")) .AddRandomService() .AddWordGenerationService() .AddScoped(_ => configuration) .BuildServiceProvider(); //assert serviceProvider.GetService <Api.WordGeneration.WordGeneration>().Should().NotBeNull(); serviceProvider.GetService <WordsGenerationOptions>().Should().BeEquivalentTo(expectedOptions); }
public WordGeneration(WordsGenerationOptions options, IRandomGenerator randomGenerator, GetWordParametersValidator validator, IFileReader fileReader, IMemoryCache memoryCache) { _randomGenerator = randomGenerator; _validator = validator; _words = LoadDictionary(memoryCache, fileReader, options.WordsDictionaryLocation); }
public void ConstructorShouldReturnWordsDictionaryLocationUnspecifiedExceptionOnInvalidPath(string path) { //arrange var fakeFile = new FakeFileReader("Hamburger"); var fakeOptions = new WordsGenerationOptions { WordsDictionaryLocation = path }; Action constructWordsStringGenerationService = () => GetWordGenerationService(fakeFile, fakeOptions); //act/assert constructWordsStringGenerationService.Should().ThrowExactly <WordsDictionaryLocationUnspecifiedException>(); }
private static Api.WordGeneration.WordGeneration GetWordGenerationService(IFileReader fileReader, WordsGenerationOptions options = null) { return(new Api.WordGeneration.WordGeneration(options ?? GetFakeOptions(), new RandomGenerator(), new GetWordParametersValidator(), fileReader, new MemoryCache(new MemoryCacheOptions()))); }