public void ShouldUpdateSubstitutionsWhenOneUpdates()
        {
            // given
            var provider1     = A.Fake <ISubstitutionProvider>();
            var provider2     = A.Fake <ISubstitutionProvider>();
            var provider3     = A.Fake <ISubstitutionProvider>();
            var monitor       = new SubstitutionsMonitor(new[] { provider1, provider2, provider3 });
            var substitutions = new Substitutions();

            // when
            provider1.OnSubstitutionsUpdated += Raise.FreeForm.With(substitutions);

            // then
            A.CallTo(() => provider2.UpdateSubstitutionsAsync(substitutions))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => provider3.UpdateSubstitutionsAsync(substitutions))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => provider1.UpdateSubstitutionsAsync(substitutions))
            .MustNotHaveHappened();
        }
        public void ShouldInitializeSubstitutionsWithMain()
        {
            // given
            var provider1     = A.Fake <ISubstitutionProvider>();
            var provider2     = A.Fake <ISubstitutionProvider>();
            var provider3     = A.Fake <ISubstitutionProvider>();
            var substitutions = new Substitutions();

            A.CallTo(() => provider1.GetSubstitutionsAsync()).ReturnsLazily(() => substitutions);

            // when
            var monitor = new SubstitutionsMonitor(new[] { provider1, provider2, provider3 }, provider1);

            // then
            A.CallTo(() => provider2.UpdateSubstitutionsAsync(substitutions))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => provider3.UpdateSubstitutionsAsync(substitutions))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => provider1.UpdateSubstitutionsAsync(substitutions))
            .MustNotHaveHappened();
        }
Ejemplo n.º 3
0
        public App(string configFile)
        {
            var configText = File.ReadAllText(configFile);
            var config     = JsonSerializer.Deserialize <Config>(configText, new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = false,
                PropertyNamingPolicy        = JsonNamingPolicy.CamelCase
            });
            ISubstitutionProvider main = null;
            var providers = config.Providers
                            .Select((providerConfig) =>
            {
                ISubstitutionProvider provider = null;
                if (providerConfig.Type == "json")
                {
                    provider = new FileSubstitutionsProvider(providerConfig.Path, new JsonFileLoader());
                }
                if (providerConfig.Type == "mac")
                {
                    provider = new FileSubstitutionsProvider(providerConfig.Path, new MacFileLoader());
                }
                if (providerConfig.IsPrimarySource)
                {
                    main = provider;
                }
                if (provider == null)
                {
                    Console.Error.WriteLine($"Provider {providerConfig.Type} unknown, skipping");
                }
                return(provider);
            })
                            .Where(provider => provider != null)
                            .ToList();

            Console.WriteLine($"{providers.Count()} providers");
            var monitor = new SubstitutionsMonitor(providers, main);
        }