Skip to content
Browse files

Added unit test for dynamic insert strongly typed load

  • Loading branch information...
1 parent 97bce1a commit db2e8a6c60853fc21e0207e619b79aadd892991d @phillip-haydon committed Sep 30, 2012
View
10 src/Raven.DynamicSession.TestConsole/Raven.DynamicSession.TestConsole.csproj
@@ -34,11 +34,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Raven.Abstractions">
- <HintPath>..\packages\RavenDB.Client.1.2.2099-Unstable\lib\net40\Raven.Abstractions.dll</HintPath>
+ <Reference Include="Raven.Abstractions, Version=1.2.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\RavenDB.Client.1.2.2100-Unstable\lib\net40\Raven.Abstractions.dll</HintPath>
</Reference>
- <Reference Include="Raven.Client.Lightweight">
- <HintPath>..\packages\RavenDB.Client.1.2.2099-Unstable\lib\net40\Raven.Client.Lightweight.dll</HintPath>
+ <Reference Include="Raven.Client.Lightweight, Version=1.2.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\RavenDB.Client.1.2.2100-Unstable\lib\net40\Raven.Client.Lightweight.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
View
2 src/Raven.DynamicSession.TestConsole/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="RavenDB.Client" version="1.2.2099-Unstable" targetFramework="net45" />
+ <package id="RavenDB.Client" version="1.2.2100-Unstable" targetFramework="net45" />
</packages>
View
36 src/Raven.DynamicSession.Tests/Properties/AssemblyInfo.cs
@@ -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("Raven.DynamicSession.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Raven.DynamicSession.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[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("37ef0303-e610-4bd8-b3d1-2f3fdf15ce30")]
+
+// 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")]
View
60 src/Raven.DynamicSession.Tests/QueryGetFixture.cs
@@ -0,0 +1,60 @@
+using System;
+using NUnit.Framework;
+using Raven.Abstractions.Data;
+using Raven.Client.Embedded;
+
+namespace Raven.DynamicSession.Tests
+{
+ [TestFixture]
+ public class QueryGetFixture
+ {
+ [Test]
+ public void Can_query_post_after_dynamic_insert()
+ {
+ //Arrange
+ var store = (new EmbeddableDocumentStore
+ {
+ RunInMemory = true
+ }).Initialize();
+
+ //TODO: Wrap up the conventions for Raven.DynamicSession
+ store.Conventions.FindClrType = (id, doc, metadata) =>
+ {
+ var clrType = metadata.Value<string>(DynamicSession.DynamicClrTypePlaceHolder);
+
+ if (clrType.Equals("Posts", StringComparison.OrdinalIgnoreCase))
+ return "Raven.DynamicSession.Tests.QueryGetFixture.Post, Raven.DynamicSession.Tests";
+
+ return metadata.Value<string>(Constants.RavenClrType);
+ };
+
+ using (dynamic session = store.OpenDynamicSession())
+ {
+ session.posts.insert(new
+ {
+ Name = "Hello World"
+ }, 123);
+
+ session.SaveChanges();
+ }
+
+ //Act
+ Post result;
+
+ using (var session = store.OpenSession())
+ {
+ result = session.Load<Post>("posts/123");
+ }
+
+ //Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Name, Is.EqualTo("Hello World"));
+ }
+
+ public class Post
+ {
+ public string Id { get; set; }
+ public string Name { get; set; }
+ }
+ }
+}
View
123 src/Raven.DynamicSession.Tests/Raven.DynamicSession.Tests.csproj
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{86317CD3-F334-4366-BAB6-4773058CE7DB}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Raven.DynamicSession.Tests</RootNamespace>
+ <AssemblyName>Raven.DynamicSession.Tests</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </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="BouncyCastle.Crypto">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\BouncyCastle.Crypto.dll</HintPath>
+ </Reference>
+ <Reference Include="Esent.Interop">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\Esent.Interop.dll</HintPath>
+ </Reference>
+ <Reference Include="GeoAPI">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\GeoAPI.dll</HintPath>
+ </Reference>
+ <Reference Include="ICSharpCode.NRefactory">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\ICSharpCode.NRefactory.dll</HintPath>
+ </Reference>
+ <Reference Include="Lucene.Net">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\Lucene.Net.dll</HintPath>
+ </Reference>
+ <Reference Include="Lucene.Net.Contrib.Spatial.NTS">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\Lucene.Net.Contrib.Spatial.NTS.dll</HintPath>
+ </Reference>
+ <Reference Include="NetTopologySuite">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\NetTopologySuite.dll</HintPath>
+ </Reference>
+ <Reference Include="NLog">
+ <HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework">
+ <HintPath>..\packages\NUnit.2.6.1\lib\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="PowerCollections">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\PowerCollections.dll</HintPath>
+ </Reference>
+ <Reference Include="Raven.Abstractions">
+ <HintPath>..\packages\RavenDB.Client.1.2.2100-Unstable\lib\net40\Raven.Abstractions.dll</HintPath>
+ </Reference>
+ <Reference Include="Raven.Backup">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\Raven.Backup.exe</HintPath>
+ </Reference>
+ <Reference Include="Raven.Client.Embedded">
+ <HintPath>..\packages\RavenDB.Embedded.1.2.2100-Unstable\lib\net40\Raven.Client.Embedded.dll</HintPath>
+ </Reference>
+ <Reference Include="Raven.Client.Lightweight">
+ <HintPath>..\packages\RavenDB.Client.1.2.2100-Unstable\lib\net40\Raven.Client.Lightweight.dll</HintPath>
+ </Reference>
+ <Reference Include="Raven.Database">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\Raven.Database.dll</HintPath>
+ </Reference>
+ <Reference Include="Raven.Smuggler">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\Raven.Smuggler.exe</HintPath>
+ </Reference>
+ <Reference Include="Spatial4n.Core.NTS">
+ <HintPath>..\packages\RavenDB.Database.1.2.2100-Unstable\lib\net40\Spatial4n.Core.NTS.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.ComponentModel.Composition" />
+ <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.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="QueryGetFixture.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Raven.DynamicSession\Raven.DynamicSession.csproj">
+ <Project>{0ee00eee-db5b-49aa-a61c-5d81d40cb446}</Project>
+ <Name>Raven.DynamicSession</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="..\packages\RavenDB.Embedded.1.2.2100-Unstable\tools\Raven.Studio.xap">
+ <Link>Raven.Studio.xap</Link>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
8 src/Raven.DynamicSession.Tests/packages.config
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NLog" version="2.0.0.2000" targetFramework="net45" />
+ <package id="NUnit" version="2.6.1" targetFramework="net45" />
+ <package id="RavenDB.Client" version="1.2.2100-Unstable" targetFramework="net45" />
+ <package id="RavenDB.Database" version="1.2.2100-Unstable" targetFramework="net45" />
+ <package id="RavenDB.Embedded" version="1.2.2100-Unstable" targetFramework="net45" />
+</packages>
View
6 src/Raven.DynamicSession.sln
@@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{8FCD47
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raven.DynamicSession.Tests", "Raven.DynamicSession.Tests\Raven.DynamicSession.Tests.csproj", "{86317CD3-F334-4366-BAB6-4773058CE7DB}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +28,10 @@ Global
{B5241777-362F-4BEE-B9DE-C496AEFB7023}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5241777-362F-4BEE-B9DE-C496AEFB7023}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5241777-362F-4BEE-B9DE-C496AEFB7023}.Release|Any CPU.Build.0 = Release|Any CPU
+ {86317CD3-F334-4366-BAB6-4773058CE7DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86317CD3-F334-4366-BAB6-4773058CE7DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86317CD3-F334-4366-BAB6-4773058CE7DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86317CD3-F334-4366-BAB6-4773058CE7DB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
6 src/Raven.DynamicSession/DynamicSession.cs
@@ -10,6 +10,11 @@ public class DynamicSession : DynamicObject, IDisposable
{
protected IDocumentSession Session { get; set; }
+ public static string DynamicClrTypePlaceHolder
+ {
+ get { return "Raven.DynamicSession.DynamicClrTypePlaceHolder"; }
+ }
+
public DynamicSession(IDocumentSession session)
{
Session = session;
@@ -59,6 +64,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
var metadata = Session.Advanced.GetMetadataFor(objectToStore);
metadata["Raven-Entity-Name"] = CollectionName;
+ metadata[DynamicClrTypePlaceHolder] = CollectionName;
result = null;
return true;
View
10 src/Raven.DynamicSession/Raven.DynamicSession.csproj
@@ -32,11 +32,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Raven.Abstractions">
- <HintPath>..\packages\RavenDB.Client.1.2.2099-Unstable\lib\net40\Raven.Abstractions.dll</HintPath>
+ <Reference Include="Raven.Abstractions, Version=1.2.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\RavenDB.Client.1.2.2100-Unstable\lib\net40\Raven.Abstractions.dll</HintPath>
</Reference>
- <Reference Include="Raven.Client.Lightweight">
- <HintPath>..\packages\RavenDB.Client.1.2.2099-Unstable\lib\net40\Raven.Client.Lightweight.dll</HintPath>
+ <Reference Include="Raven.Client.Lightweight, Version=1.2.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\RavenDB.Client.1.2.2100-Unstable\lib\net40\Raven.Client.Lightweight.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
View
2 src/Raven.DynamicSession/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="RavenDB.Client" version="1.2.2099-Unstable" targetFramework="net45" />
+ <package id="RavenDB.Client" version="1.2.2100-Unstable" targetFramework="net45" />
</packages>

0 comments on commit db2e8a6

Please sign in to comment.
Something went wrong with that request. Please try again.