У меня есть приложение на основе базы данных ASP. NET MVC с моделью, представлениями и контроллерами, созданными MVC, которые я сильно настроил. У меня есть основной проект и тестовый проект в моем решении. Мой тестовый код, который пытается получить доступ к объектам в моей модели, не работает и выдает эту ошибку:
Сообщение: метод теста KurantCollections.Tests.Logi c .KurantLogicTests.TestCreatingUserAndTown выбросил исключение: System.Data.Entity .Core.MetadataException: указанная схема недопустима. Ошибки: Models.KurantCollectionsDataModel.ssdl (2,2): ошибка 0152: не найден поставщик Entity Framework для поставщика ADO. NET с инвариантным именем «System.Data.SqlClient». Убедитесь, что поставщик зарегистрирован в разделе «entityFramework» файла конфигурации приложения. См. http://go.microsoft.com/fwlink/?LinkId=260882 для получения дополнительной информации.
Признаюсь, я не до конца понимаю все в файле web.config и думаю, что мне нужно создать файл app.config для тестового проекта чтобы соответствовать. Может быть, проблема в том, что модель, к которой я пытаюсь получить доступ в тестовом классе, не находится в том же проекте, который ее определяет?
Мне интересно, предоставляю ли я содержимое файла web.config из основного проекта и Файл app.config из тестового проекта, который кто-то может сказать мне, что не так или отсутствует в моем app.config?
Вот файл web.config для основного проекта, в котором определена модель.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-KurantCollections-20191030015559.mdf;Initial Catalog=aspnet-KurantCollections-20191030015559;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="KurantCollectionsEntities" connectionString="metadata=res://*/Models.KurantCollectionsDataModel.csdl|res://*/Models.KurantCollectionsDataModel.ssdl|res://*/Models.KurantCollectionsDataModel.msl;provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\MSSQLLocalDB;attachdbfilename="C:\Users\jkura\source\repos\KurantCollectionsSol\KurantCollections\App_Data\KurantCollections.mdf";integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
<customErrors mode="On" defaultRedirect="~/Views/Shared/Error">
<error statusCode="404" redirect="~/Views/Shared/Error" />
</customErrors>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
, а вот файл app.config из тестового проекта:
<?xml version="1.0" encoding="utf-8" ?>
<!--
Note: Add entries to the App.config file for configuration settings
that apply only to the Test project.
-->
<configuration>
<appSettings>
</appSettings>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-KurantCollections-20191030015559.mdf;Initial Catalog=aspnet-KurantCollections-20191030015559;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="KurantCollectionsEntities" connectionString="metadata=res://*/Models.KurantCollectionsDataModel.csdl|res://*/Models.KurantCollectionsDataModel.ssdl|res://*/Models.KurantCollectionsDataModel.msl;provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\MSSQLLocalDB;attachdbfilename="C:\Users\jkura\source\repos\KurantCollectionsSol\KurantCollections\App_Data\KurantCollections.mdf";integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Здесь что-то явно отсутствует? Я sh Я лучше понял смысл всего этого:
<add name="KurantCollectionsEntities" connectionString="metadata=res://*/Models.KurantCollectionsDataModel.csdl|res://*/Models.KurantCollectionsDataModel.ssdl|res://*/Models.KurantCollectionsDataModel.msl;provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\MSSQLLocalDB;attachdbfilename="C:\Users\jkura\source\repos\KurantCollectionsSol\KurantCollections\App_Data\KurantCollections.mdf";integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
Я просто добавил это в свой app.config:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
и теперь я получаю эту ошибку:
Message:
Configuration system failed to initialize
Stack Trace:
ClientConfigurationSystem.EnsureInit(String configKey)
ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
IInternalConfigSystem.GetSection(String sectionName)
ConfigurationManager.GetSection(String sectionName)
PrivilegedConfigurationManager.GetSection(String sectionName)
DiagnosticsConfiguration.GetConfigSection()
DiagnosticsConfiguration.Initialize()
DiagnosticsConfiguration.get_IndentSize()
TraceInternal.InitializeSettings()
TraceInternal.get_Listeners()
Trace.get_Listeners()
TraceListenerManager.Add(ITraceListener traceListener)