/// <summary>
        /// A protected factory method that does the actual work of creating the specified feed.
        /// </summary>
        /// <typeparam name="T">The type of repository to create.</typeparam>
        /// <param name="feedSettings">The feed settings to initialize the repository.</param>
        /// <returns>IRepository&lt;Package&gt;.</returns>
        /// <exception cref="System.ArgumentNullException">feedSettings</exception>
        /// <exception cref="System.InvalidOperationException">If no repository can be found based on the feed type.</exception>
        protected IRepository <Package> Create <T>(Feed feedSettings)
            where T : IRepository <Package>
        {
            if (feedSettings == null)
            {
                throw new ArgumentNullException(nameof(feedSettings));
            }

            Debug.Assert(feedSettings.Type.Equals(Type, StringComparison.CurrentCultureIgnoreCase));

            Logger.LogDebug($"Creating Repository named \"{feedSettings.Name}\" of type \"{feedSettings.Type}\"");
            var repository = ActivatorUtilities.CreateInstance <T>(
                ServiceProvider,
                feedSettings.CloneAndMergeSettings(ApplicationSettings.SettingsGroups.Find(feedSettings.SettingsGroup)));

            return(repository);
        }
Esempio n. 2
0
        public void Test_Feed_CloneAndMergeSettings()
        {
            var feed = new Feed
            {
                Name          = "TestName",
                Type          = "TestType",
                SettingsGroup = "TestSettingsGroup",
                Settings      = { { "Key1", "Value1" }, { "Key2", "Value2" }, { "Key3", "Value3" } }
            };
            var expectedSettings = new SettingsCollection {
                { "Key1", "Value1" }, { "Key3", "Value3" }, { "Key2", "Value2" }, { "Key4", "Value4-new" }
            };
            var settingsGroup = new SettingsCollection {
                { "Key2", "Value2-new" }, { "Key3", "Value3-new" }, { "Key4", "Value4-new" }
            };

            var sut = feed.CloneAndMergeSettings(settingsGroup);

            Assert.Equal(feed.Name, sut.Name);
            Assert.Equal(feed.Type, sut.Type);
            Assert.Equal(feed.SettingsGroup, sut.SettingsGroup);
            Assert.Equal(expectedSettings, sut.Settings);
        }