Skip to content

Commit

Permalink
- Added Mongo.Linq and Mongo.Linq.Tests projects
Browse files Browse the repository at this point in the history
  • Loading branch information
sdether committed Oct 5, 2009
1 parent 2d2a1c7 commit 314a480
Show file tree
Hide file tree
Showing 19 changed files with 1,765 additions and 14 deletions.
10 changes: 10 additions & 0 deletions MongoDB.Linq.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<appSettings>
<add key="mongo.host" value="dev01.notify.me"/>
<add key="mongo.port" value="27017"/>
</appSettings>
</configuration>
21 changes: 21 additions & 0 deletions MongoDB.Linq.Tests/AppSettingsFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using MongoDB.Driver;

namespace MongoDB.Linq.Tests {
public static class AppSettingsFactory {

public static string Host { get { return ConfigurationManager.AppSettings["mongo.host"]; } }
public static int Port { get { return int.Parse(ConfigurationManager.AppSettings["mongo.port"]); } }

public static Mongo CreateMongo() {
return new Mongo(Host, Port);
}

public static Connection CreateConnection() {
return new Connection(Host, Port);
}
}
}
85 changes: 85 additions & 0 deletions MongoDB.Linq.Tests/MongoDB.Linq.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{870FE8E1-3461-4C79-BF25-9C35E41BF582}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MongoDB.Linq.Tests</RootNamespace>
<AssemblyName>MongoDB.Linq.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</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="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\redist\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\redist\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppSettingsFactory.cs" />
<Compile Include="TestExpressions.cs" />
<Compile Include="TestMongoDocumentQuerySyntax.cs" />
<Compile Include="TestQueryExecution.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestQueryParsing.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MongoDB.Linq\MongoDB.Linq.csproj">
<Project>{2E48891E-72F9-445D-9A5A-DBA787BFFE9E}</Project>
<Name>MongoDB.Linq</Name>
</ProjectReference>
<ProjectReference Include="..\MongoDBDriver\MongoDB.Driver.csproj">
<Project>{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}</Project>
<Name>MongoDB.Driver</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
36 changes: 36 additions & 0 deletions MongoDB.Linq.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("MongoDB.Linq.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MongoDB.Linq.Tests")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[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("c3a2a135-887c-47db-a891-18924f9cf068")]

// 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")]
64 changes: 64 additions & 0 deletions MongoDB.Linq.Tests/TestExpressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
using NUnit.Framework;

namespace MongoDB.Linq.Tests {
// ReSharper disable InconsistentNaming
[TestFixture]
public class TestExpressions {
[Test]
public void Getting_at_member_expression_values() {
var foo = new { Bar = "abc" };
Expression<Func<string>> expression = () => foo.Bar;
var memberExpression = expression.Body as MemberExpression;
switch (memberExpression.Member.MemberType) {
case MemberTypes.Property:
var propertyInfo = (PropertyInfo)memberExpression.Member;
var innerMember = (MemberExpression)memberExpression.Expression;
var fieldInfo = (FieldInfo)innerMember.Member;
var obj = fieldInfo.GetValue(((ConstantExpression)innerMember.Expression).Value);
Assert.AreEqual("abc", propertyInfo.GetValue(obj, null));
break;
default:
Assert.Fail();
break;
}
}

[Test]
public void Getting_field_from_closure() {
string key = "xyz";
Expression<Func<string>> expression = () => key;
var memberExpression = expression.Body as MemberExpression;
switch (memberExpression.Member.MemberType) {
case MemberTypes.Field:
var fieldInfo = (FieldInfo)memberExpression.Member;
Assert.AreEqual("xyz", fieldInfo.GetValue(((ConstantExpression)memberExpression.Expression).Value));
break;
default:
Assert.Fail();
break;
}
}

[Test]
public void Evaluating_a_MethodCallExpression_with_known_return_type() {
Expression<Func<DateTime>> expression = () => DateTime.Parse("2009/10/10");
var methodCallExpression = expression.Body as MethodCallExpression;
Expression<Func<DateTime>> lambda = Expression.Lambda<Func<DateTime>>(methodCallExpression);
var value = lambda.Compile()();
Assert.AreEqual(DateTime.Parse("2009/10/10"), value);
}

[Test]
public void Evaluating_a_MethodCallExpression_with_unknown_return_type() {
Expression<Func<DateTime>> expression = () => DateTime.Parse("2009/10/10");
var methodCallExpression = expression.Body as MethodCallExpression;
var lambda = Expression.Lambda(methodCallExpression);
var value = lambda.Compile().DynamicInvoke();
Assert.AreEqual(DateTime.Parse("2009/10/10"), value);
}
}
// ReSharper restore InconsistentNaming
}
Loading

0 comments on commit 314a480

Please sign in to comment.