Entity framework testing is pretty good must say
This commit is contained in:
		
							parent
							
								
									8abed33160
								
							
						
					
					
						commit
						b348bdfe90
					
				| @ -1,13 +1,13 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <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" /> | ||||
|     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> | ||||
|   </configSections> | ||||
|   <entityFramework> | ||||
|     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> | ||||
|     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/> | ||||
|     <providers> | ||||
|       <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> | ||||
|       <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/> | ||||
|     </providers> | ||||
|   </entityFramework> | ||||
| </configuration> | ||||
| <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration> | ||||
|  | ||||
| @ -9,8 +9,9 @@ | ||||
|     <AppDesignerFolder>Properties</AppDesignerFolder> | ||||
|     <RootNamespace>PoweredSoft.DynamicLinq.Dal</RootNamespace> | ||||
|     <AssemblyName>PoweredSoft.DynamicLinq.Dal</AssemblyName> | ||||
|     <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||||
|     <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||||
|     <FileAlignment>512</FileAlignment> | ||||
|     <TargetFrameworkProfile /> | ||||
|   </PropertyGroup> | ||||
|   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||||
|     <DebugSymbols>true</DebugSymbols> | ||||
|  | ||||
							
								
								
									
										17
									
								
								PoweredSoft.DynamicLinq.EntityFramework/App.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								PoweredSoft.DynamicLinq.EntityFramework/App.config
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <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> | ||||
|   <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> | ||||
| @ -0,0 +1,35 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Data.Entity; | ||||
| using System.Linq; | ||||
| using System.Reflection; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using PoweredSoft.DynamicLinq.Extensions; | ||||
| using PoweredSoft.DynamicLinq.Fluent; | ||||
| 
 | ||||
| namespace PoweredSoft.DynamicLinq.EntityFramework.Extensions | ||||
| { | ||||
|     public static class DbContextExtensions | ||||
|     { | ||||
|         private static readonly MethodInfo QueryMethod = typeof(DbContextExtensions) | ||||
|             .GetMethods(BindingFlags.Static | BindingFlags.Public) | ||||
|             .First(t => t.Name == "Query" && t.IsGenericMethod); | ||||
| 
 | ||||
|         public static IQueryable Query(this DbContext context, Type pocoType, Action<QueryBuilderBase> callback) | ||||
|         { | ||||
|             var method = QueryMethod.MakeGenericMethod(pocoType); | ||||
|             var invokeResult = method.Invoke(null, new object[] {context, callback}); | ||||
|             var ret = invokeResult as IQueryable; | ||||
|             return ret; | ||||
|         } | ||||
| 
 | ||||
|         public static IQueryable<T> Query<T>(this DbContext context, Action<QueryBuilderBase> callback) | ||||
|             where T : class | ||||
|         { | ||||
|             var query = context.Set<T>().AsQueryable(); | ||||
|             query = query.Query(callback); | ||||
|             return query; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,64 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||
|   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||||
|   <PropertyGroup> | ||||
|     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||||
|     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||||
|     <ProjectGuid>{15587E3C-D4BB-474C-A4AC-4E6305F92BCE}</ProjectGuid> | ||||
|     <OutputType>Library</OutputType> | ||||
|     <AppDesignerFolder>Properties</AppDesignerFolder> | ||||
|     <RootNamespace>PoweredSoft.DynamicLinq.EntityFramework</RootNamespace> | ||||
|     <AssemblyName>PoweredSoft.DynamicLinq.EntityFramework</AssemblyName> | ||||
|     <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||||
|     <FileAlignment>512</FileAlignment> | ||||
|   </PropertyGroup> | ||||
|   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||||
|     <DebugSymbols>true</DebugSymbols> | ||||
|     <DebugType>full</DebugType> | ||||
|     <Optimize>false</Optimize> | ||||
|     <OutputPath>bin\Debug\</OutputPath> | ||||
|     <DefineConstants>DEBUG;TRACE</DefineConstants> | ||||
|     <ErrorReport>prompt</ErrorReport> | ||||
|     <WarningLevel>4</WarningLevel> | ||||
|   </PropertyGroup> | ||||
|   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||||
|     <DebugType>pdbonly</DebugType> | ||||
|     <Optimize>true</Optimize> | ||||
|     <OutputPath>bin\Release\</OutputPath> | ||||
|     <DefineConstants>TRACE</DefineConstants> | ||||
|     <ErrorReport>prompt</ErrorReport> | ||||
|     <WarningLevel>4</WarningLevel> | ||||
|   </PropertyGroup> | ||||
|   <ItemGroup> | ||||
|     <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> | ||||
|       <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath> | ||||
|     </Reference> | ||||
|     <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> | ||||
|       <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath> | ||||
|     </Reference> | ||||
|     <Reference Include="System" /> | ||||
|     <Reference Include="System.ComponentModel.DataAnnotations" /> | ||||
|     <Reference Include="System.Core" /> | ||||
|     <Reference Include="System.Xml.Linq" /> | ||||
|     <Reference Include="System.Data.DataSetExtensions" /> | ||||
|     <Reference Include="Microsoft.CSharp" /> | ||||
|     <Reference Include="System.Data" /> | ||||
|     <Reference Include="System.Net.Http" /> | ||||
|     <Reference Include="System.Xml" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <Compile Include="Extensions\DbContextExtensions.cs" /> | ||||
|     <Compile Include="Properties\AssemblyInfo.cs" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <None Include="App.config" /> | ||||
|     <None Include="packages.config" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\PoweredSoft.DynamicLinq\PoweredSoft.DynamicLinq.csproj"> | ||||
|       <Project>{2ABC5A60-B549-4ECD-BEF4-31CA7BA4EF06}</Project> | ||||
|       <Name>PoweredSoft.DynamicLinq</Name> | ||||
|     </ProjectReference> | ||||
|   </ItemGroup> | ||||
|   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||||
| </Project> | ||||
| @ -0,0 +1,36 @@ | ||||
| using System.Reflection; | ||||
| using System.Runtime.CompilerServices; | ||||
| using System.Runtime.InteropServices; | ||||
| 
 | ||||
| // General Information about an assembly is controlled through the following | ||||
| // set of attributes. Change these attribute values to modify the information | ||||
| // associated with an assembly. | ||||
| [assembly: AssemblyTitle("PoweredSoft.DynamicLinq.EntityFramework")] | ||||
| [assembly: AssemblyDescription("")] | ||||
| [assembly: AssemblyConfiguration("")] | ||||
| [assembly: AssemblyCompany("")] | ||||
| [assembly: AssemblyProduct("PoweredSoft.DynamicLinq.EntityFramework")] | ||||
| [assembly: AssemblyCopyright("Copyright ©  2018")] | ||||
| [assembly: AssemblyTrademark("")] | ||||
| [assembly: AssemblyCulture("")] | ||||
| 
 | ||||
| // Setting ComVisible to false makes the types in this assembly not visible | ||||
| // to COM components.  If you need to access a type in this assembly from | ||||
| // COM, set the ComVisible attribute to true on that type. | ||||
| [assembly: ComVisible(false)] | ||||
| 
 | ||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||||
| [assembly: Guid("15587e3c-d4bb-474c-a4ac-4e6305f92bce")] | ||||
| 
 | ||||
| // Version information for an assembly consists of the following four values: | ||||
| // | ||||
| //      Major Version | ||||
| //      Minor Version | ||||
| //      Build Number | ||||
| //      Revision | ||||
| // | ||||
| // You can specify all the values or you can default the Build and Revision Numbers | ||||
| // by using the '*' as shown below: | ||||
| // [assembly: AssemblyVersion("1.0.*")] | ||||
| [assembly: AssemblyVersion("1.0.0.0")] | ||||
| [assembly: AssemblyFileVersion("1.0.0.0")] | ||||
							
								
								
									
										4
									
								
								PoweredSoft.DynamicLinq.EntityFramework/packages.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								PoweredSoft.DynamicLinq.EntityFramework/packages.config
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <packages> | ||||
|   <package id="EntityFramework" version="6.2.0" targetFramework="net462" /> | ||||
| </packages> | ||||
| @ -1,9 +1,11 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Data.Entity; | ||||
| using System.Linq; | ||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||
| using PoweredSoft.DynamicLinq.Dal; | ||||
| using PoweredSoft.DynamicLinq.Dal.Pocos; | ||||
| using PoweredSoft.DynamicLinq.EntityFramework.Extensions; | ||||
| using PoweredSoft.DynamicLinq.Extensions; | ||||
| 
 | ||||
| namespace PoweredSoft.DynamicLinq.Test | ||||
| @ -174,5 +176,17 @@ namespace PoweredSoft.DynamicLinq.Test | ||||
|             for (var i = 0; i < dq.Count; i++) | ||||
|                 Assert.AreEqual(dq[i].Id, sq[i].Id); | ||||
|         } | ||||
| 
 | ||||
|         [TestMethod] | ||||
|         public void TestContextTypeLessHelper() | ||||
|         { | ||||
|             var context = new BlogContext(testConnectionString); | ||||
|             SeedForTests(context); | ||||
| 
 | ||||
|             var queryable = context.Query(typeof(Author), q => q.Compare("FirstName", ConditionOperators.Equal, "David")); | ||||
|             var result = queryable.ToListAsync().Result; | ||||
|             var first = result.FirstOrDefault() as Author; | ||||
|             Assert.AreEqual(first?.FirstName, "David"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -9,7 +9,7 @@ | ||||
|     <AppDesignerFolder>Properties</AppDesignerFolder> | ||||
|     <RootNamespace>PoweredSoft.DynamicLinq.Test</RootNamespace> | ||||
|     <AssemblyName>PoweredSoft.DynamicLinq.Test</AssemblyName> | ||||
|     <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||||
|     <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||||
|     <FileAlignment>512</FileAlignment> | ||||
|     <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||||
|     <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion> | ||||
| @ -19,6 +19,7 @@ | ||||
|     <TestProjectType>UnitTest</TestProjectType> | ||||
|     <NuGetPackageImportStamp> | ||||
|     </NuGetPackageImportStamp> | ||||
|     <TargetFrameworkProfile /> | ||||
|   </PropertyGroup> | ||||
|   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||||
|     <DebugSymbols>true</DebugSymbols> | ||||
| @ -73,6 +74,10 @@ | ||||
|       <Project>{C16927E7-1358-4B9D-BDD7-149E505DE6CC}</Project> | ||||
|       <Name>PoweredSoft.DynamicLinq.Dal</Name> | ||||
|     </ProjectReference> | ||||
|     <ProjectReference Include="..\PoweredSoft.DynamicLinq.EntityFramework\PoweredSoft.DynamicLinq.EntityFramework.csproj"> | ||||
|       <Project>{15587e3c-d4bb-474c-a4ac-4e6305f92bce}</Project> | ||||
|       <Name>PoweredSoft.DynamicLinq.EntityFramework</Name> | ||||
|     </ProjectReference> | ||||
|     <ProjectReference Include="..\PoweredSoft.DynamicLinq\PoweredSoft.DynamicLinq.csproj"> | ||||
|       <Project>{2abc5a60-b549-4ecd-bef4-31ca7ba4ef06}</Project> | ||||
|       <Name>PoweredSoft.DynamicLinq</Name> | ||||
|  | ||||
| @ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicLinq.Dal | ||||
| EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicLinq.Test", "PoweredSoft.DynamicLinq.Test\PoweredSoft.DynamicLinq.Test.csproj", "{6F5C80F0-9045-4098-913F-7BDAD135E6DD}" | ||||
| EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicLinq.EntityFramework", "PoweredSoft.DynamicLinq.EntityFramework\PoweredSoft.DynamicLinq.EntityFramework.csproj", "{15587E3C-D4BB-474C-A4AC-4E6305F92BCE}" | ||||
| EndProject | ||||
| Global | ||||
| 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| 		Debug|Any CPU = Debug|Any CPU | ||||
| @ -27,6 +29,10 @@ Global | ||||
| 		{6F5C80F0-9045-4098-913F-7BDAD135E6DD}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{6F5C80F0-9045-4098-913F-7BDAD135E6DD}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{6F5C80F0-9045-4098-913F-7BDAD135E6DD}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{15587E3C-D4BB-474C-A4AC-4E6305F92BCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{15587E3C-D4BB-474C-A4AC-4E6305F92BCE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{15587E3C-D4BB-474C-A4AC-4E6305F92BCE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{15587E3C-D4BB-474C-A4AC-4E6305F92BCE}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 	EndGlobalSection | ||||
| 	GlobalSection(SolutionProperties) = preSolution | ||||
| 		HideSolutionNode = FALSE | ||||
|  | ||||
| @ -9,8 +9,9 @@ | ||||
|     <AppDesignerFolder>Properties</AppDesignerFolder> | ||||
|     <RootNamespace>PoweredSoft.DynamicLinq</RootNamespace> | ||||
|     <AssemblyName>PoweredSoft.DynamicLinq</AssemblyName> | ||||
|     <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||||
|     <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||||
|     <FileAlignment>512</FileAlignment> | ||||
|     <TargetFrameworkProfile /> | ||||
|   </PropertyGroup> | ||||
|   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||||
|     <DebugSymbols>true</DebugSymbols> | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user