예제 #1
0
 private object TryGetInitializerFromEntityFrameworkSection(Type contextType)
 {
     return(this._entityFrameworkSettings.Contexts.OfType <ContextElement>().Where <ContextElement>((Func <ContextElement, bool>)(e =>
     {
         if (!e.IsDatabaseInitializationDisabled)
         {
             return !string.IsNullOrWhiteSpace(e.DatabaseInitializer.InitializerTypeName);
         }
         return true;
     })).Select <ContextElement, object>((Func <ContextElement, object>)(e => InitializerConfig.TryGetInitializer(contextType, e.ContextTypeName, e.DatabaseInitializer.InitializerTypeName ?? string.Empty, e.IsDatabaseInitializationDisabled, (Func <object[]>)(() => e.DatabaseInitializer.Parameters.GetTypedParameterValues()), new Func <object, object, string>(Strings.Database_InitializeFromConfigFailed)))).FirstOrDefault <object>((Func <object, bool>)(i => i != null)));
 }
예제 #2
0
        public void TryGetInitializer_throws_if_null_or_empty_context_type_is_registered_in_app_settings_section()
        {
            var configurationCollection = new KeyValueConfigurationCollection
            {
                { "DatabaseInitializerForType ", "Disabled" }
            };

            var initializerConfig = new InitializerConfig(new EntityFrameworkSection(), configurationCollection);

            Assert.Equal(
                Strings.Database_BadLegacyInitializerEntry("DatabaseInitializerForType ", "Disabled"),
                Assert.Throws <InvalidOperationException>(() => initializerConfig.TryGetInitializer(typeof(FakeContext))).Message);
        }
예제 #3
0
        public void TryGetInitializer_returns_initializer_created_with_given_parameters_when_registered_in_config_section()
        {
            var initializer = new InitializerConfig(
                CreateEfSection(
                    typeof(FakeContext).AssemblyQualifiedName,
                    typeof(FakeInitializer <FakeContext>).AssemblyQualifiedName,
                    initializerDisabled: false,
                    initializerParams: new object[] { "Wiggo", 1 }),
                new KeyValueConfigurationCollection()).TryGetInitializer(typeof(FakeContext));

            Assert.IsType <FakeInitializer <FakeContext> >(initializer);
            Assert.Equal("Wiggo", ((FakeInitializer <FakeContext>)initializer).Hero);
            Assert.Equal(1, ((FakeInitializer <FakeContext>)initializer).Wheredecome);
        }
예제 #4
0
        private static void TestBadType(string contextTypeName, string initializerTypeName, bool initializerDisabled)
        {
            var initializerConfig = new InitializerConfig(
                CreateEfSection(contextTypeName, initializerTypeName, initializerDisabled),
                new KeyValueConfigurationCollection());

            var exception = Assert.Throws <InvalidOperationException>(() => initializerConfig.TryGetInitializer(typeof(FakeContext)));

            Assert.Equal(
                Strings.Database_InitializeFromConfigFailed(
                    initializerDisabled ? "Disabled" : initializerTypeName,
                    contextTypeName), exception.Message);

            Assert.IsType <TypeLoadException>(exception.InnerException);
        }
예제 #5
0
        private static void TestBadTypeLegacy(string contextTypeName, string configValue, bool initializerDisabled)
        {
            var configurationCollection = new KeyValueConfigurationCollection
            {
                { "DatabaseInitializerForType " + contextTypeName, configValue }
            };

            var initializerConfig = new InitializerConfig(new EntityFrameworkSection(), configurationCollection);

            var exception = Assert.Throws <InvalidOperationException>(() => initializerConfig.TryGetInitializer(typeof(FakeContext)));

            Assert.Equal(
                Strings.Database_InitializeFromLegacyConfigFailed(
                    initializerDisabled ? "Disabled" : configValue,
                    contextTypeName), exception.Message);

            Assert.IsType <TypeLoadException>(exception.InnerException);
        }
예제 #6
0
 private object TryGetInitializerFromLegacyConfig(Type contextType)
 {
     foreach (string index in ((IEnumerable <string>) this._appSettings.AllKeys).Where <string>((Func <string, bool>)(k => k.StartsWith("DatabaseInitializerForType", StringComparison.OrdinalIgnoreCase))))
     {
         string contextTypeName     = index.Remove(0, "DatabaseInitializerForType".Length).Trim();
         string initializerTypeName = (this._appSettings[index].Value ?? string.Empty).Trim();
         if (string.IsNullOrWhiteSpace(contextTypeName))
         {
             throw new InvalidOperationException(Strings.Database_BadLegacyInitializerEntry((object)index, (object)initializerTypeName));
         }
         object initializer = InitializerConfig.TryGetInitializer(contextType, contextTypeName, initializerTypeName, initializerTypeName.Length == 0 || initializerTypeName.Equals("Disabled", StringComparison.OrdinalIgnoreCase), (Func <object[]>)(() => new object[0]), new Func <object, object, string>(Strings.Database_InitializeFromLegacyConfigFailed));
         if (initializer != null)
         {
             return(initializer);
         }
     }
     return((object)null);
 }