Skip to content
Browse files

Merge branch 'master' of git://github.com/davidmohara/mongodb-csharp …

…into mohara

Conflicts:
	MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj
	MongoDB.Net-Tests/TestCollection.cs
	MongoDBDriver/MongoDB.Driver.csproj
	MongoDBDriver/Oid.cs
  • Loading branch information...
2 parents 4f45ef2 + e7c6c1a commit d6abd326e0e31fca623ca0e4ecce17c1808ff467 Samuel Corder committed Apr 2, 2010
View
41 MongoDB.Driver.Benchmark/MongoDB.Driver.Benchmark.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,6 +10,26 @@
<RootNamespace>MongoDB.Driver.Benchmark</RootNamespace>
<AssemblyName>MongoDB.Driver.Benchmark</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <UpgradeBackupLocation>
+ </UpgradeBackupLocation>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -19,13 +39,15 @@
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -40,5 +62,22 @@
<Name>MongoDB.Driver</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
View
41 MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,6 +10,26 @@
<AssemblyName>MongoDB.GridFS.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<RootNamespace>MongoDB.GridFS.Tests</RootNamespace>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <UpgradeBackupLocation>
+ </UpgradeBackupLocation>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -20,6 +40,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@@ -28,6 +49,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -58,5 +80,22 @@
<Name>MongoDB.GridFS</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
View
41 MongoDB.GridFS/MongoDB.GridFS.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,6 +10,26 @@
<AssemblyName>MongoDB.GridFS</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<RootNamespace>MongoDB.GridFS</RootNamespace>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <UpgradeBackupLocation>
+ </UpgradeBackupLocation>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -20,6 +40,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@@ -28,6 +49,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -45,5 +67,22 @@
<Name>MongoDB.Driver</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
View
2 MongoDB.Linq.Tests/App.config
@@ -4,7 +4,7 @@
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<appSettings>
- <add key="mongo.host" value="dev01.notify.me"/>
+ <add key="mongo.host" value="localhost"/>
<add key="mongo.port" value="27017"/>
</appSettings>
</configuration>
View
41 MongoDB.Linq.Tests/MongoDB.Linq.Tests.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -12,6 +12,26 @@
<AssemblyName>MongoDB.Linq.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <UpgradeBackupLocation>
+ </UpgradeBackupLocation>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -21,6 +41,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,6 +50,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920">
@@ -74,6 +96,23 @@
<Name>MongoDB.Driver</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\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.
View
41 MongoDB.Linq/MongoDB.Linq.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -12,6 +12,26 @@
<AssemblyName>MongoDB.Linq</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <UpgradeBackupLocation>
+ </UpgradeBackupLocation>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -21,6 +41,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,6 +50,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -61,6 +83,23 @@
<Name>MongoDB.Driver</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\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.
View
36 MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj
@@ -10,9 +10,16 @@
<AssemblyName>MongoDB.Driver.Tests</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
- <OldToolsVersion>2.0</OldToolsVersion>
+ <OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <RootNamespace>MongoDB.Driver.Tests</RootNamespace>
+ <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\scorder\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
+ <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
+ <NoStdLib>False</NoStdLib>
+ <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@@ -25,15 +32,8 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <RootNamespace>MongoDB.Driver.Tests</RootNamespace>
- <SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\scorder\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
- <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
- <NoStdLib>False</NoStdLib>
- <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -43,13 +43,15 @@
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
@@ -118,18 +120,31 @@
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
+ <ProductName>
+ </ProductName>
+ <Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
+ <ProductName>
+ </ProductName>
+ <Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
+ <ProductName>
+ </ProductName>
+ <Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
@@ -144,8 +159,5 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
- <ItemGroup>
- <Folder Include="Util\" />
- <Folder Include="Configuration\" />
- </ItemGroup>
+ <ItemGroup />
</Project>
View
865 MongoDB.Net-Tests/TestCollection.cs
@@ -1,412 +1,453 @@
-using System;
-using System.Collections.Generic;
-
-using NUnit.Framework;
-using MongoDB.Driver.Bson;
-
-namespace MongoDB.Driver
-{
- [TestFixture]
- public class TestCollection : MongoTestBase
- {
- private string pound = "\u00a3";
-
- public override string TestCollections {
- get {
- return "inserts,updates,counts,counts_spec,finds,charreads,saves";
- }
- }
-
- public override void OnInit (){
- IMongoCollection finds = DB["finds"];
- for(int j = 1; j < 100; j++){
- finds.Insert(new Document(){{"x", 4},{"h", "hi"},{"j", j}});
- }
- for(int j = 100; j < 105; j++){
- finds.Insert(new Document(){{"x", 4},{"n", 1},{"j", j}});
- }
- IMongoCollection charreads = DB["charreads"];
- charreads.Insert(new Document(){{"test", "1234" + pound + "56"}});
-
- }
-
-
- [Test]
- public void TestFindOne(){
- Document query = new Document();
- query["j"] = 10;
- Document result = DB["finds"].FindOne(query);
- Assert.IsNotNull(result);
- Assert.AreEqual(4, result["x"]);
- Assert.AreEqual(10, result["j"]);
-
- }
-
- [Test]
- public void TestFindOneNotThere(){
- Document query = new Document();
- query["not_there"] = 10;
- Document result = DB["finds"].FindOne(query);
- Assert.IsNull(result);
- }
-
- [Test]
- public void TestFindNulls(){
- Document query = new Document().Append("n",DBNull.Value);
- long numnulls = DB["finds"].Count(query);
- Assert.AreEqual(99,numnulls);
- }
-
- [Test]
- public void TestFindAttributeLimit(){
- Document query = new Document();
- query["j"] = 10;
- Document fields = new Document();
- fields["x"] = 1;
-
- ICursor c = DB["finds"].Find(query,-1,0,fields);
- foreach(Document result in c.Documents){
- Assert.IsNotNull(result);
- Assert.AreEqual(4, result["x"]);
- Assert.IsNull(result["j"]);
- }
- }
-
- [Test]
- public void TestFindGTRange(){
- Document query = new Document();
- query["j"] = new Document().Append("$gt",20);
-
- ICursor c = DB["finds"].Find(query);
- foreach(Document result in c.Documents){
- Assert.IsNotNull(result);
- Object j = result["j"];
- Assert.IsTrue(Convert.ToDouble(j) > 20);
- }
- }
-
- [Test]
- public void TestManualWhere(){
- Document query = new Document().Append("$where", new Code("this.j % 2 == 0"));
- ICursor c = DB["finds"].Find(query);
- foreach(Document result in c.Documents){
- Assert.IsNotNull(result);
- Object j = result["j"];
- Assert.IsTrue(Convert.ToInt32(j) % 2 == 0);
- }
- }
- [Test]
- public void TestFindWhereEquivalency(){
- IMongoCollection col = DB["finds"];
- Document lt = new Document().Append("j", new Document().Append("$lt", 5));
- string where = "this.j < 5";
- Document explicitWhere = new Document().Append("$where", new Code(where));
- CodeWScope func = new CodeWScope("function() { return this.j < 5; }", new Document());
- Document funcDoc = new Document().Append("$where", func);
-
- Assert.AreEqual(4, CountDocs(col.Find(lt)), "Basic find didn't return 4 docs");
- Assert.AreEqual(4, CountDocs(col.Find(where)), "String where didn't return 4 docs");
- Assert.AreEqual(4, CountDocs(col.Find(explicitWhere)), "Explicit where didn't return 4 docs");
- Assert.AreEqual(4, CountDocs(col.Find(funcDoc)), "Function where didn't return 4 docs");
- }
-
- private int CountDocs(ICursor cur){
- int cnt = 0;
- foreach(Document doc in cur.Documents){
- cnt++;
- }
- return cnt;
- }
- [Test]
- public void TestWhere(){
- ICursor c = DB["finds"].Find("this.j % 2 == 0");
- foreach(Document result in c.Documents){
- Assert.IsNotNull(result);
- Object j = result["j"];
- Assert.IsTrue(Convert.ToInt32(j) % 2 == 0);
- }
- }
-
- [Test]
- public void TestFindOneObjectContainingUKPound(){
- Document query = new Document();
- Document result = DB["charreads"].FindOne(query);
- Assert.IsNotNull(result);
- Assert.IsTrue(result.Contains("test"));
- Assert.AreEqual("1234£56",result["test"]);
- }
-
- [Test]
- public void TestSimpleInsert(){
- IMongoCollection inserts = DB["inserts"];
- Document indoc = new Document();
- indoc["song"] = "Palmdale";
- indoc["artist"] = "Afroman";
- indoc["year"] = 1999;
-
- inserts.Insert(indoc);
-
- Document result = inserts.FindOne(new Document().Append("song","Palmdale"));
- Assert.IsNotNull(result);
- Assert.AreEqual(1999,result["year"]);
- }
-
- [Test]
- public void TestReallySimpleInsert(){
- IMongoCollection inserts = DB["inserts"];
- Document indoc = new Document();
- indoc["y"] = 1;
- indoc["x"] = 2;
- inserts.Insert(indoc);
-
- Document result = inserts.FindOne(new Document().Append("x",2));
- Assert.IsNotNull(result);
- Assert.AreEqual(1,result["y"]);
- }
-
- [Test]
- public void TestPoundSymbolInsert(){
- IMongoCollection inserts = DB["inserts"];
- Document indoc = new Document().Append("x","1234" + pound + "56").Append("y",1);;
- inserts.Insert(indoc);
-
- Document result = inserts.FindOne(new Document().Append("x","1234" + pound + "56"));
- Assert.IsNotNull(result);
- Assert.AreEqual(1,result["y"]);
- }
-
- [Test]
- public void TestArrayInsert(){
- IMongoCollection inserts = DB["inserts"];
- Document indoc1 = new Document();
- indoc1["song"] = "The Axe";
- indoc1["artist"] = "Tinsley Ellis";
- indoc1["year"] = 2006;
-
- Document indoc2 = new Document();
- indoc2["song"] = "The Axe2";
- indoc2["artist"] = "Tinsley Ellis2";
- indoc2["year"] = 2008;
-
- inserts.Insert(new Document[]{indoc1,indoc2});
-
- Document result = inserts.FindOne(new Document().Append("song","The Axe"));
- Assert.IsNotNull(result);
- Assert.AreEqual(2006,result["year"]);
-
- result = inserts.FindOne(new Document().Append("song","The Axe2"));
- Assert.IsNotNull(result);
- Assert.AreEqual(2008,result["year"]);
- }
-
- [Test]
- public void TestInsertOfArray(){
- OidGenerator ogen = new OidGenerator();
- IMongoCollection inserts = DB["inserts"];
- Document album = new Document();
- album["_id"] = ogen.Generate();
- album["artist"] = "Popa Chubby";
- album["title"] = "Deliveries After Dark";
- album["songs"] = new[] {
- new Document().Append("title", "Let The Music Set You Free").Append("length", "5:15").Append("_id", ogen.Generate()),
- new Document().Append("title", "Sally Likes to Run").Append("length", "4:06").Append("_id", ogen.Generate()),
- new Document().Append("title", "Deliveries After Dark").Append("length", "4:17").Append("_id", ogen.Generate()),
- new Document().Append("title", "Theme From The Godfather").Append("length", "3:06").Append("_id", ogen.Generate()),
- new Document().Append("title", "Grown Man Crying Blues").Append("length", "8:09").Append("_id", ogen.Generate()),
- };
- inserts.Insert(album);
-
- Document result = inserts.FindOne(new Document().Append("songs.title","Deliveries After Dark"));
- Assert.IsNotNull(result);
-
- Assert.AreEqual(album.ToString(), result.ToString());
- }
-
- [Test]
- public void TestInsertLargerThan4MBDocument(){
- Binary b = new Binary(new byte[1024 * 1024]);
- Document big = new Document(){{"name", "Big Document"}, {"b1", b}, {"b2", b}, {"b3", b}, {"b4", b}};
- IMongoCollection inserts = DB["inserts"];
- bool thrown = false;
- try{
- inserts.Insert(big);
- }catch(MongoException){
- thrown = true;
- }catch(Exception e){
- Assert.Fail("Wrong Exception thrown " + e.GetType().Name);
- }
- Assert.IsTrue(thrown, "Shouldn't be able to insert large document");
- }
-
- [Test]
- public void TestInsertBulkLargerThan4MBOfDocuments(){
- Binary b = new Binary(new byte[1024 * 1024 * 2]);
- IMongoCollection inserts = DB["inserts"];
- try{
- Document[] docs = new Document[10];
- //6MB+ of documents
- for(int x = 0; x < docs.Length; x++){
- docs[x] = new Document(){{"name", "bulk"}, {"b", b}, {"x", x}};
- }
- inserts.Insert(docs,true);
- long count = inserts.Count(new Document(){{"name", "bulk"}});
- Assert.AreEqual(docs.Length, count, "Wrong number of documents inserted");
- }catch(MongoException){
- Assert.Fail("MongoException should not have been thrown.");
- }
- }
-
- [Test]
- public void TestDelete(){
- IMongoCollection deletes = DB["deletes"];
- Document doc = new Document();
- doc["y"] = 1;
- doc["x"] = 2;
- deletes.Insert(doc);
-
- Document selector = new Document().Append("x",2);
-
- Document result = deletes.FindOne(selector);
- Assert.IsNotNull(result);
- Assert.AreEqual(1,result["y"]);
-
- deletes.Delete(selector);
- result = deletes.FindOne(selector);
- Assert.IsNull(result,"Shouldn't have been able to find a document that was deleted");
-
- }
-
- [Test]
- public void TestUpdateUpsertNotExisting(){
- IMongoCollection updates = DB["updates"];
- Document doc = new Document();
- doc["First"] = "Sam";
- doc["Last"] = "CorderNE";
-
- updates.Update(doc);
- Document selector = new Document().Append("Last", "CorderNE");
- Document result = updates.FindOne(selector);
- Assert.IsNotNull(result);
- Assert.AreEqual("Sam", result["First"]);
- }
-
- [Test]
- public void TestUpdateUpsertExisting(){
- IMongoCollection updates = DB["updates"];
- Document doc = new Document();
- doc["First"] = "Mtt";
- doc["Last"] = "Brewer";
-
- updates.Insert(doc);
-
- Document selector = new Document().Append("Last", "Brewer");
- doc = updates.FindOne(selector);
- Assert.IsNotNull(doc);
- Assert.AreEqual("Mtt", doc["First"]);
- Assert.IsNotNull(doc["_id"]);
-
- doc["First"] = "Matt";
- updates.Update(doc);
-
- Document result = updates.FindOne(selector);
- Assert.IsNotNull(result);
- Assert.AreEqual("Matt", result["First"]);
-
- }
- [Test]
- public void TestSave(){
- IMongoCollection saves = DB["saves"];
- string[] vals = {"a","b","c","d"};
- foreach(var v in vals){
- saves.Save(new Document(){{"value", v}});
- }
- Assert.AreEqual(vals.Length, saves.Count());
- Document d = saves.FindOne(new Document(){{"value", "b"}});
- d["value"] = "b2";
- saves.Save(d);
-
- Assert.AreEqual(1, saves.Count(new Document(){{"value", "b2"}}));
-
- }
- [Test]
- public void TestUpdateMany(){
- IMongoCollection updates = DB["updates"];
-
- updates.Insert(new Document().Append("Last", "Cordr").Append("First","Sam"));
- updates.Insert(new Document().Append("Last", "Cordr").Append("First","Sam2"));
- updates.Insert(new Document().Append("Last", "Cordr").Append("First","Sam3"));
-
- Document selector = new Document().Append("Last", "Cordr");
- ICursor results = updates.Find(selector);
- bool found = false;
- foreach(Document doc in results.Documents){
- Assert.AreEqual("Cordr", doc["Last"]);
- found = true;
- }
- Assert.IsTrue(found,"Should have found docs inserted for TestUpdateMany");
- Assert.AreEqual(3, updates.Count(selector), "Didn't find all Documents inserted for TestUpdateMany with Selector");
-
- //Document updateData = new Document().Append("$set", new Document().Append("Last", "Corder2"));
- Document updateData = new Document().Append("Last", "Corder2");
- updates.UpdateAll(updateData, selector);
-
- selector["Last"] = "Corder2";
- Assert.AreEqual(3, updates.Count(selector), "Not all Cordr documents were updated");
-
- results = updates.Find(selector);
- found = false;
- foreach(Document doc in results.Documents){
- Assert.AreEqual("Corder2", doc["Last"]);
- Assert.IsNotNull(doc["First"],"First name should not disappear");
- found = true;
- }
- Assert.IsTrue(found,"Should have found docs updated for TestMany");
- }
-
- [Test]
- public void TestUpdatePartial(){
- IMongoCollection updates = DB["updates"];
- int coolness = 5;
- Document einstein = new Document(){{"Last", "Einstien"},{"First", "Albert"},{"Coolness",coolness++}};
- updates.Insert(einstein);
- Document selector = new Document(){{"_id", einstein["_id"]}};
-
- updates.Update(new Document(){{"$inc", new Document(){{"Coolness", 1}}}}, selector);
- Assert.AreEqual(coolness++, Convert.ToInt32(updates.FindOne(selector)["Coolness"]), "Coolness field not incremented", true);
-
- updates.Update(new Document(){{"$set",new Document(){{"Last", "Einstein"}}},
- {"$inc",new Document(){{"Coolness",1}}}},selector,true);
- Assert.AreEqual(coolness++, Convert.ToInt32(updates.FindOne(selector)["Coolness"]), "Coolness field not incremented");
- }
-
- [Test]
- public void TestCount(){
- IMongoCollection counts = DB["counts"];
- int top = 100;
- for(int i = 0; i < top; i++){
- counts.Insert(new Document().Append("Last", "Cordr").Append("First","Sam").Append("cnt", i));
- }
- long cnt = counts.Count();
- Assert.AreEqual(top,cnt, "Count not the same as number of inserted records");
- }
-
- [Test]
- public void TestCountWithSpec(){
- IMongoCollection counts = DB["counts_spec"];
- counts.Insert(new Document().Append("Last", "Cordr").Append("First","Sam").Append("cnt", 1));
- counts.Insert(new Document().Append("Last", "Cordr").Append("First","Sam").Append("cnt", 2));
- counts.Insert(new Document().Append("Last", "Corder").Append("First","Sam").Append("cnt", 3));
-
- Assert.AreEqual(2, counts.Count(new Document().Append("Last", "Cordr")));
- Assert.AreEqual(1, counts.Count(new Document().Append("Last", "Corder")));
- Assert.AreEqual(0, counts.Count(new Document().Append("Last", "Brown")));
-
- }
-
- [Test]
- public void TestCountInvalidCollection(){
- IMongoCollection counts = DB["counts_wtf"];
- Assert.AreEqual(0, counts.Count());
- }
- }
-}
+using System;
+
+using NUnit.Framework;
+
+namespace MongoDB.Driver
+{
+ [TestFixture]
+ public class TestCollection : MongoTestBase
+ {
+ private string pound = "£";
+
+ public override string TestCollections {
+ get { return "inserts,updates,find_and_modify,counts,counts_spec,finds,charreads,saves"; }
+ }
+
+ public override void OnInit() {
+ IMongoCollection finds = DB["finds"];
+ for(int j = 1; j < 100; j++) {
+ finds.Insert(new Document { { "x", 4 }, { "h", "hi" }, { "j", j } });
+ }
+ for(int j = 100; j < 105; j++) {
+ finds.Insert(new Document { { "x", 4 }, { "n", 1 }, { "j", j } });
+ }
+ IMongoCollection charreads = DB["charreads"];
+ charreads.Insert(new Document { { "test", "1234" + pound + "56" } });
+
+ }
+
+
+ [Test]
+ public void TestFindOne() {
+ Document query = new Document();
+ query["j"] = 10;
+ Document result = DB["finds"].FindOne(query);
+ Assert.IsNotNull(result);
+ Assert.AreEqual(4, result["x"]);
+ Assert.AreEqual(10, result["j"]);
+
+ }
+
+ [Test]
+ public void TestFindOneNotThere() {
+ Document query = new Document();
+ query["not_there"] = 10;
+ Document result = DB["finds"].FindOne(query);
+ Assert.IsNull(result);
+ }
+
+ [Test]
+ public void TestFindNulls() {
+ Document query = new Document().Append("n", DBNull.Value);
+ long numnulls = DB["finds"].Count(query);
+ Assert.AreEqual(99, numnulls);
+ }
+
+ [Test]
+ public void TestFindAttributeLimit() {
+ Document query = new Document();
+ query["j"] = 10;
+ Document fields = new Document();
+ fields["x"] = 1;
+
+ ICursor c = DB["finds"].Find(query, -1, 0, fields);
+ foreach(Document result in c.Documents) {
+ Assert.IsNotNull(result);
+ Assert.AreEqual(4, result["x"]);
+ Assert.IsNull(result["j"]);
+ }
+ }
+
+ [Test]
+ public void TestFindGTRange() {
+ Document query = new Document();
+ query["j"] = new Document().Append("$gt", 20);
+
+ ICursor c = DB["finds"].Find(query);
+ foreach(Document result in c.Documents) {
+ Assert.IsNotNull(result);
+ Object j = result["j"];
+ Assert.IsTrue(Convert.ToDouble(j) > 20);
+ }
+ }
+
+ [Test]
+ public void TestManualWhere() {
+ Document query = new Document().Append("$where", new Code("this.j % 2 == 0"));
+ ICursor c = DB["finds"].Find(query);
+ foreach(Document result in c.Documents) {
+ Assert.IsNotNull(result);
+ Object j = result["j"];
+ Assert.IsTrue(Convert.ToInt32(j) % 2 == 0);
+ }
+ }
+ [Test]
+ public void TestFindWhereEquivalency() {
+ IMongoCollection col = DB["finds"];
+ Document lt = new Document().Append("j", new Document().Append("$lt", 5));
+ string @where = "this.j < 5";
+ Document explicitWhere = new Document().Append("$where", new Code(@where));
+ CodeWScope func = new CodeWScope("function() { return this.j < 5; }", new Document());
+ Document funcDoc = new Document().Append("$where", func);
+
+ Assert.AreEqual(4, CountDocs(col.Find(lt)), "Basic find didn't return 4 docs");
+ Assert.AreEqual(4, CountDocs(col.Find(@where)), "String where didn't return 4 docs");
+ Assert.AreEqual(4, CountDocs(col.Find(explicitWhere)), "Explicit where didn't return 4 docs");
+ Assert.AreEqual(4, CountDocs(col.Find(funcDoc)), "Function where didn't return 4 docs");
+ }
+
+ private int CountDocs(ICursor cur) {
+ int cnt = 0;
+ foreach(Document doc in cur.Documents) {
+ cnt++;
+ }
+ return cnt;
+ }
+ [Test]
+ public void TestWhere() {
+ ICursor c = DB["finds"].Find("this.j % 2 == 0");
+ foreach(Document result in c.Documents) {
+ Assert.IsNotNull(result);
+ Object j = result["j"];
+ Assert.IsTrue(Convert.ToInt32(j) % 2 == 0);
+ }
+ }
+
+ [Test]
+ public void TestFindOneObjectContainingUKPound() {
+ Document query = new Document();
+ Document result = DB["charreads"].FindOne(query);
+ Assert.IsNotNull(result);
+ Assert.IsTrue(result.Contains("test"));
+ Assert.AreEqual("1234£56", result["test"]);
+ }
+
+ [Test]
+ public void TestSimpleInsert() {
+ IMongoCollection inserts = DB["inserts"];
+ Document indoc = new Document();
+ indoc["song"] = "Palmdale";
+ indoc["artist"] = "Afroman";
+ indoc["year"] = 1999;
+
+ inserts.Insert(indoc);
+
+ Document result = inserts.FindOne(new Document().Append("song", "Palmdale"));
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1999, result["year"]);
+ }
+
+ [Test]
+ public void TestReallySimpleInsert() {
+ IMongoCollection inserts = DB["inserts"];
+ Document indoc = new Document();
+ indoc["y"] = 1;
+ indoc["x"] = 2;
+ inserts.Insert(indoc);
+
+ Document result = inserts.FindOne(new Document().Append("x", 2));
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result["y"]);
+ }
+
+ [Test]
+ public void TestPoundSymbolInsert() {
+ IMongoCollection inserts = DB["inserts"];
+ Document indoc = new Document().Append("x", "1234" + pound + "56").Append("y", 1);
+ ;
+ inserts.Insert(indoc);
+
+ Document result = inserts.FindOne(new Document().Append("x", "1234" + pound + "56"));
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result["y"]);
+ }
+
+ [Test]
+ public void TestArrayInsert() {
+ IMongoCollection inserts = DB["inserts"];
+ Document indoc1 = new Document();
+ indoc1["song"] = "The Axe";
+ indoc1["artist"] = "Tinsley Ellis";
+ indoc1["year"] = 2006;
+
+ Document indoc2 = new Document();
+ indoc2["song"] = "The Axe2";
+ indoc2["artist"] = "Tinsley Ellis2";
+ indoc2["year"] = 2008;
+
+ inserts.Insert(new Document[] { indoc1, indoc2 });
+
+ Document result = inserts.FindOne(new Document().Append("song", "The Axe"));
+ Assert.IsNotNull(result);
+ Assert.AreEqual(2006, result["year"]);
+
+ result = inserts.FindOne(new Document().Append("song", "The Axe2"));
+ Assert.IsNotNull(result);
+ Assert.AreEqual(2008, result["year"]);
+ }
+
+ [Test]
+ public void TestInsertOfArray() {
+ OidGenerator ogen = new OidGenerator();
+ IMongoCollection inserts = DB["inserts"];
+ Document album = new Document();
+ album["_id"] = ogen.Generate();
+ album["artist"] = "Popa Chubby";
+ album["title"] = "Deliveries After Dark";
+ album["songs"] = new[] { new Document().Append("title", "Let The Music Set You Free").Append("length", "5:15").Append("_id", ogen.Generate()), new Document().Append("title", "Sally Likes to Run").Append("length", "4:06").Append("_id", ogen.Generate()), new Document().Append("title", "Deliveries After Dark").Append("length", "4:17").Append("_id", ogen.Generate()), new Document().Append("title", "Theme From The Godfather").Append("length", "3:06").Append("_id", ogen.Generate()), new Document().Append("title", "Grown Man Crying Blues").Append("length", "8:09").Append("_id", ogen.Generate()) };
+ inserts.Insert(album);
+
+ Document result = inserts.FindOne(new Document().Append("songs.title", "Deliveries After Dark"));
+ Assert.IsNotNull(result);
+
+ Assert.AreEqual(album.ToString(), result.ToString());
+ }
+
+ [Test]
+ public void TestInsertLargerThan4MBDocument() {
+ Binary b = new Binary(new byte[1024 * 1024]);
+ Document big = new Document { { "name", "Big Document" }, { "b1", b }, { "b2", b }, { "b3", b }, { "b4", b } };
+ IMongoCollection inserts = DB["inserts"];
+ bool thrown = false;
+ try {
+ inserts.Insert(big);
+ } catch(MongoException) {
+ thrown = true;
+ } catch(Exception e) {
+ Assert.Fail("Wrong Exception thrown " + e.GetType().Name);
+ }
+ Assert.IsTrue(thrown, "Shouldn't be able to insert large document");
+ }
+
+ [Test]
+ public void TestInsertBulkLargerThan4MBOfDocuments() {
+ Binary b = new Binary(new byte[1024 * 1024 * 2]);
+ IMongoCollection inserts = DB["inserts"];
+ try {
+ Document[] docs = new Document[10];
+ //6MB+ of documents
+ for(int x = 0; x < docs.Length; x++) {
+ docs[x] = new Document { { "name", "bulk" }, { "b", b }, { "x", x } };
+ }
+ inserts.Insert(docs, true);
+ long count = inserts.Count(new Document { { "name", "bulk" } });
+ Assert.AreEqual(docs.Length, count, "Wrong number of documents inserted");
+ } catch(MongoException) {
+ Assert.Fail("MongoException should not have been thrown.");
+ }
+ }
+
+ [Test]
+ public void TestDelete() {
+ IMongoCollection deletes = DB["deletes"];
+ Document doc = new Document();
+ doc["y"] = 1;
+ doc["x"] = 2;
+ deletes.Insert(doc);
+
+ Document selector = new Document().Append("x", 2);
+
+ Document result = deletes.FindOne(selector);
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result["y"]);
+
+ deletes.Delete(selector);
+ result = deletes.FindOne(selector);
+ Assert.IsNull(result, "Shouldn't have been able to find a document that was deleted");
+
+ }
+
+ [Test]
+ public void TestUpdateUpsertNotExisting() {
+ IMongoCollection updates = DB["updates"];
+ Document doc = new Document();
+ doc["First"] = "Sam";
+ doc["Last"] = "CorderNE";
+
+ updates.Update(doc);
+ Document selector = new Document().Append("Last", "CorderNE");
+ Document result = updates.FindOne(selector);
+ Assert.IsNotNull(result);
+ Assert.AreEqual("Sam", result["First"]);
+ }
+
+ [Test]
+ public void TestUpdateUpsertExisting() {
+ IMongoCollection updates = DB["updates"];
+ Document doc = new Document();
+ doc["First"] = "Mtt";
+ doc["Last"] = "Brewer";
+
+ updates.Insert(doc);
+
+ Document selector = new Document().Append("Last", "Brewer");
+ doc = updates.FindOne(selector);
+ Assert.IsNotNull(doc);
+ Assert.AreEqual("Mtt", doc["First"]);
+ Assert.IsNotNull(doc["_id"]);
+
+ doc["First"] = "Matt";
+ updates.Update(doc);
+
+ Document result = updates.FindOne(selector);
+ Assert.IsNotNull(result);
+ Assert.AreEqual("Matt", result["First"]);
+
+ }
+ [Test]
+ public void TestSave() {
+ IMongoCollection saves = DB["saves"];
+ string[] vals = { "a", "b", "c", "d" };
+ foreach(var v in vals) {
+ saves.Save(new Document { { "value", v } });
+ }
+ Assert.AreEqual(vals.Length, saves.Count());
+ Document d = saves.FindOne(new Document { { "value", "b" } });
+ d["value"] = "b2";
+ saves.Save(d);
+
+ Assert.AreEqual(1, saves.Count(new Document { { "value", "b2" } }));
+
+ }
+ [Test]
+ public void TestUpdateMany() {
+ IMongoCollection updates = DB["updates"];
+
+ updates.Insert(new Document().Append("Last", "Cordr").Append("First", "Sam"));
+ updates.Insert(new Document().Append("Last", "Cordr").Append("First", "Sam2"));
+ updates.Insert(new Document().Append("Last", "Cordr").Append("First", "Sam3"));
+
+ Document selector = new Document().Append("Last", "Cordr");
+ ICursor results = updates.Find(selector);
+ bool found = false;
+ foreach(Document doc in results.Documents) {
+ Assert.AreEqual("Cordr", doc["Last"]);
+ found = true;
+ }
+ Assert.IsTrue(found, "Should have found docs inserted for TestUpdateMany");
+ Assert.AreEqual(3, updates.Count(selector), "Didn't find all Documents inserted for TestUpdateMany with Selector");
+
+ //Document updateData = new Document().Append("$set", new Document().Append("Last", "Corder2"));
+ Document updateData = new Document().Append("Last", "Corder2");
+ updates.UpdateAll(updateData, selector);
+
+ selector["Last"] = "Corder2";
+ Assert.AreEqual(3, updates.Count(selector), "Not all Cordr documents were updated");
+
+ results = updates.Find(selector);
+ found = false;
+ foreach(Document doc in results.Documents) {
+ Assert.AreEqual("Corder2", doc["Last"]);
+ Assert.IsNotNull(doc["First"], "First name should not disappear");
+ found = true;
+ }
+ Assert.IsTrue(found, "Should have found docs updated for TestMany");
+ }
+
+ [Test]
+ public void TestUpdatePartial() {
+ IMongoCollection updates = DB["updates"];
+ int coolness = 5;
+ Document einstein = new Document { { "Last", "Einstien" }, { "First", "Albert" }, { "Coolness", coolness++ } };
+ updates.Insert(einstein);
+ Document selector = new Document { { "_id", einstein["_id"] } };
+
+ updates.Update(new Document { { "$inc", new Document { { "Coolness", 1 } } } }, selector);
+ Assert.AreEqual(coolness++, Convert.ToInt32(updates.FindOne(selector)["Coolness"]), "Coolness field not incremented", true);
+
+ updates.Update(new Document { { "$set", new Document { { "Last", "Einstein" } } }, { "$inc", new Document { { "Coolness", 1 } } } }, selector, true);
+ Assert.AreEqual(coolness++, Convert.ToInt32(updates.FindOne(selector)["Coolness"]), "Coolness field not incremented");
+ }
+
+ [Test]
+ public void TestCount() {
+ IMongoCollection counts = DB["counts"];
+ int top = 100;
+ for(int i = 0; i < top; i++) {
+ counts.Insert(new Document().Append("Last", "Cordr").Append("First", "Sam").Append("cnt", i));
+ }
+ long cnt = counts.Count();
+ Assert.AreEqual(top, cnt, "Count not the same as number of inserted records");
+ }
+
+ [Test]
+ public void TestCountWithSpec() {
+ IMongoCollection counts = DB["counts_spec"];
+ counts.Insert(new Document().Append("Last", "Cordr").Append("First", "Sam").Append("cnt", 1));
+ counts.Insert(new Document().Append("Last", "Cordr").Append("First", "Sam").Append("cnt", 2));
+ counts.Insert(new Document().Append("Last", "Corder").Append("First", "Sam").Append("cnt", 3));
+
+ Assert.AreEqual(2, counts.Count(new Document().Append("Last", "Cordr")));
+ Assert.AreEqual(1, counts.Count(new Document().Append("Last", "Corder")));
+ Assert.AreEqual(0, counts.Count(new Document().Append("Last", "Brown")));
+
+ }
+
+ [Test]
+ public void TestCountInvalidCollection() {
+ IMongoCollection counts = DB["counts_wtf"];
+ Assert.AreEqual(0, counts.Count());
+ }
+
+ [Test]
+ public void TestFindAndModifyReturnsOldDocument() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document person = new Document().Append("First", "Sally").Append("Last", "Simmons");
+ collection.Insert(person);
+
+ Document spec = new Document().Append("_id", person["_id"]);
+ Document loaded = collection.FindAndModify(new Document().Append("First", "Jane"), spec);
+
+ Assert.AreEqual("Sally", loaded["First"]);
+ }
+
+ [Test]
+ public void TestFindAndModifyReturnsNewDocument() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document person = new Document().Append("First", "Susie").Append("Last", "O'Hara");
+ collection.Insert(person);
+
+ Document spec = new Document().Append("_id", person["_id"]);
+ Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);
+
+ Assert.AreEqual("Darlene", loaded["First"]);
+ }
+
+ [Test]
+ public void TestFindAndModifySortsResults() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document doc1 = new Document().Append("handled", false).Append("priority", 1).Append("value", "Test 1");
+ Document doc2 = new Document().Append("handled", false).Append("priority", 2).Append("value", "Test 2");
+ collection.Insert(doc1);
+ collection.Insert(doc2);
+
+ Document update = new Document().Append("handled", true);
+ Document spec = new Document().Append("handled", false);
+ Document sort = new Document().Append("priority", -1);
+ Document loaded = collection.FindAndModify(update, spec, sort, true);
+
+ Assert.AreEqual(true, loaded["handled"]);
+ Assert.AreEqual(doc2["priority"], loaded["priority"]);
+ Assert.AreEqual(doc2["value"], loaded["value"]);
+ }
+
+ [Test]
+ public void TestFindAndModifyReturnNullForNoRecordFound() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document spec = new Document().Append("FirstName", "Noone");
+ Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);
+
+ Assert.IsNull(loaded, "Should return null for no document found");
+ }
+ }
+}
View
389 MongoDB.Net-Tests/TestDocument.cs
@@ -1,168 +1,221 @@
-/*
- * User: scorder
- * Date: 7/8/2009
- */
-
-using System;
-using System.Collections;
-
-using NUnit.Framework;
-
-using MongoDB.Driver;
-
-namespace MongoDB.Driver
-{
- [TestFixture]
- public class TestDocument
- {
- [Test]
- public void TestValuesAdded()
- {
- Document d = new Document();
- d["test"] = 1;
- Assert.AreEqual(1, d["test"]);
- }
-
- [Test]
- public void TestKeyOrderIsPreserved(){
- Document d = new Document();
- d["one"] = 1;
- d.Add("two", 2);
- d["three"] = 3;
- int cnt = 1;
- foreach(String key in d.Keys){
- Assert.AreEqual(cnt, d[key]);
- cnt++;
- }
- }
- [Test]
- public void TestRemove(){
- Document d = new Document();
- d["one"] = 1;
- d.Remove("one");
- Assert.IsFalse(d.Contains("one"));
- }
-
- [Test]
- public void TestKeyOrderPreservedOnRemove(){
- Document d = new Document();
- d["one"] = 1;
- d["onepointfive"] = 1.5;
- d.Add("two", 2);
- d.Add("two.5", 2.5);
- d.Remove("two.5");
- d["three"] = 3;
- d.Remove("onepointfive");
- int cnt = 1;
- foreach(String key in d.Keys){
- Assert.AreEqual(cnt, d[key]);
- cnt++;
- }
- }
-
- [Test]
- public void TestValues(){
- Document d = new Document();
- d["one"] = 1;
- d.Add("two", 2);
- d["three"] = 3;
- ICollection vals = d.Values;
- Assert.AreEqual(3, vals.Count);
-
- }
-
- [Test]
- public void TestClearRemovesAll(){
- Document d = new Document();
- d["one"] = 1;
- d.Add("two", 2);
- d["three"] = 3;
- Assert.AreEqual(3,d.Count);
- d.Clear();
- Assert.AreEqual(0, d.Count);
- Assert.IsNull(d["one"]);
- Assert.IsFalse(d.Contains("one"));
- }
-
- [Test]
- public void TestCopyToCopiesAndPreservesKeyOrderToEmptyDoc(){
- Document d = new Document();
- Document dest = new Document();
- d["one"] = 1;
- d.Add("two", 2);
- d["three"] = 3;
- d.CopyTo(dest);
- int cnt = 1;
- foreach(String key in dest.Keys){
- Assert.AreEqual(cnt, d[key]);
- cnt++;
- }
- }
-
- [Test]
- public void TestCopyToCopiesAndOverwritesKeys(){
- Document d = new Document();
- Document dest = new Document();
- dest["two"] = 200;
- d["one"] = 1;
- d.Add("two", 2);
- d["three"] = 3;
- d.CopyTo(dest);
- Assert.AreEqual(2, dest["two"]);
- }
-
- [Test]
- public void TestTwoDocumentsWithSameContentInSameOrderAreEqual() {
- Document d1 = new Document().Append("k1", "v1").Append("k2", "v2");
- Document d2 = new Document().Append("k1", "v1").Append("k2", "v2");
- AreEqual(d1, d2);
- }
-
- [Test]
- public void TestTwoDocumentsWithSameContentInDifferentOrderAreNotEqual() {
- Document d1 = new Document().Append("k1", "v1").Append("k2", "v2");
- Document d2 = new Document().Append("k2", "v2").Append("k1", "v1");
- AreNotEqual(d1, d2);
- }
-
- [Test]
- public void TestTwoDocumentsWithSameArrayContentAreEqual() {
- Document d1 = new Document().Append("k1", new string[] { "v1", "v2" });
- Document d2 = new Document().Append("k1", new string[] { "v1", "v2" });
- AreEqual(d1, d2);
- }
-
- [Test]
- public void TestTwoDocumentsWithMisorderedArrayContentAreNotEqual() {
- Document d1 = new Document().Append("k1", new string[] { "v1", "v2" });
- Document d2 = new Document().Append("k1", new string[] { "v2", "v1" });
- AreNotEqual(d1, d2);
- }
-
- [Test]
- public void TestTwoDocumentsWithSameDocumentChildTreeAreEqual() {
- Document d1 = new Document().Append("k1", new Document().Append("k2",new Document().Append("k3","foo")));
- Document d2 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "foo")));
- AreEqual(d1, d2);
- }
-
- [Test]
- public void TestTwoDocumentsWithDifferentDocumentChildTreeAreNotEqual() {
- Document d1 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "foo")));
- Document d2 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "bar")));
- AreNotEqual(d1, d2);
- }
-
- private void AreEqual(Document d1, Document d2) {
- if (!d1.Equals(d2)) {
- Assert.Fail(string.Format("Documents don't match\r\nExpected: {0}\r\nActual: {1}", d1, d2));
- }
- }
-
- private void AreNotEqual(Document d1, Document d2) {
- if (d1.Equals(d2)) {
- Assert.Fail(string.Format("Documents match\r\nExpected: not {0}\r\nActual: {1}", d1, d2));
- }
- }
- }
-}
+/*
+ * User: scorder
+ * Date: 7/8/2009
+ */
+
+using System;
+using System.Linq;
+using System.Collections;
+using System.Collections.Generic;
+
+using NUnit.Framework;
+
+using MongoDB.Driver;
+
+namespace MongoDB.Driver
+{
+ [TestFixture]
+ public class TestDocument
+ {
+ [Test]
+ public void TestValuesAdded(){
+ Document d = new Document();
+ d["test"] = 1;
+ Assert.AreEqual(1, d["test"]);
+ }
+
+ [Test]
+ public void TestKeyOrderIsPreserved(){
+ Document d = new Document();
+ d["one"] = 1;
+ d.Add("two", 2);
+ d["three"] = 3;
+ int cnt = 1;
+ foreach(String key in d.Keys){
+ Assert.AreEqual(cnt, d[key]);
+ cnt++;
+ }
+ }
+
+ [Test]
+ public void TestRemove(){
+ Document d = new Document();
+ d["one"] = 1;
+ d.Remove("one");
+ Assert.IsFalse(d.Contains("one"));
+ }
+
+ [Test]
+ public void TestUseOfIComparerForKeys(){
+ var doc = new Document(new ReverseComparer());
+
+ doc.Append("a", 3);
+ doc.Append("b", 2);
+ doc.Append("c", 1);
+
+ Assert.AreEqual("c", doc.Keys.First());
+ }
+
+ [Test]
+ public void TestInsertMaintainsKeyOrder(){
+ Document d = new Document();
+ d["one"] = 1;
+ d.Insert("zero", 0, 0);
+
+ var keysList = d.Keys as IEnumerable<string>;
+ Assert.AreEqual(keysList.First(), "zero");
+ }
+
+ [Test]
+ public void TestMaintainsOrderUsingMultipleMethods(){
+ Document d = new Document(new ReverseComparer());
+ d["one"] = 1;
+ var test = d["one"];
+ d["zero"] = 0;
+
+ var keysList = d.Keys as IEnumerable<string>;
+ Assert.AreEqual(keysList.First(), "zero");
+ }
+
+ [Test]
+ [ExpectedException(ExceptionType = typeof(ArgumentException),
+ ExpectedMessage="Key already exists in Document",
+ MatchType=MessageMatch.Contains)]
+ public void TestInsertWillThrowArgumentExceptionIfKeyAlreadyExists(){
+ Document d = new Document();
+ d["one"] = 1;
+ d.Insert("one", 1, 0);
+ }
+
+ [Test]
+ public void TestKeyOrderPreservedOnRemove(){
+ Document d = new Document();
+ d["one"] = 1;
+ d["onepointfive"] = 1.5;
+ d.Add("two", 2);
+ d.Add("two.5", 2.5);
+ d.Remove("two.5");
+ d["three"] = 3;
+ d.Remove("onepointfive");
+ int cnt = 1;
+ foreach(String key in d.Keys){
+ Assert.AreEqual(cnt, d[key]);
+ cnt++;
+ }
+ }
+
+ [Test]
+ public void TestValues(){
+ Document d = new Document();
+ d["one"] = 1;
+ d.Add("two", 2);
+ d["three"] = 3;
+ ICollection vals = d.Values;
+ Assert.AreEqual(3, vals.Count);
+
+ }
+
+ [Test]
+ public void TestClearRemovesAll(){
+ Document d = new Document();
+ d["one"] = 1;
+ d.Add("two", 2);
+ d["three"] = 3;
+ Assert.AreEqual(3,d.Count);
+ d.Clear();
+ Assert.AreEqual(0, d.Count);
+ Assert.IsNull(d["one"]);
+ Assert.IsFalse(d.Contains("one"));
+ }
+
+ [Test]
+ public void TestCopyToCopiesAndPreservesKeyOrderToEmptyDoc(){
+ Document d = new Document();
+ Document dest = new Document();
+ d["one"] = 1;
+ d.Add("two", 2);
+ d["three"] = 3;
+ d.CopyTo(dest);
+ int cnt = 1;
+ foreach(String key in dest.Keys){
+ Assert.AreEqual(cnt, d[key]);
+ cnt++;
+ }
+ }
+
+ [Test]
+ public void TestCopyToCopiesAndOverwritesKeys(){
+ Document d = new Document();
+ Document dest = new Document();
+ dest["two"] = 200;
+ d["one"] = 1;
+ d.Add("two", 2);
+ d["three"] = 3;
+ d.CopyTo(dest);
+ Assert.AreEqual(2, dest["two"]);
+ }
+
+ [Test]
+ public void TestTwoDocumentsWithSameContentInSameOrderAreEqual() {
+ Document d1 = new Document().Append("k1", "v1").Append("k2", "v2");
+ Document d2 = new Document().Append("k1", "v1").Append("k2", "v2");
+ AreEqual(d1, d2);
+ }
+
+ [Test]
+ public void TestTwoDocumentsWithSameContentInDifferentOrderAreNotEqual() {
+ Document d1 = new Document().Append("k1", "v1").Append("k2", "v2");
+ Document d2 = new Document().Append("k2", "v2").Append("k1", "v1");
+ AreNotEqual(d1, d2);
+ }
+
+ [Test]
+ public void TestTwoDocumentsWithSameArrayContentAreEqual() {
+ Document d1 = new Document().Append("k1", new string[] { "v1", "v2" });
+ Document d2 = new Document().Append("k1", new string[] { "v1", "v2" });
+ AreEqual(d1, d2);
+ }
+
+ [Test]
+ public void TestTwoDocumentsWithMisorderedArrayContentAreNotEqual() {
+ Document d1 = new Document().Append("k1", new string[] { "v1", "v2" });
+ Document d2 = new Document().Append("k1", new string[] { "v2", "v1" });
+ AreNotEqual(d1, d2);
+ }
+
+ [Test]
+ public void TestTwoDocumentsWithSameDocumentChildTreeAreEqual() {
+ Document d1 = new Document().Append("k1", new Document().Append("k2",new Document().Append("k3","foo")));
+ Document d2 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "foo")));
+ AreEqual(d1, d2);
+ }
+
+ [Test]
+ public void TestTwoDocumentsWithDifferentDocumentChildTreeAreNotEqual() {
+ Document d1 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "foo")));
+ Document d2 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "bar")));
+ AreNotEqual(d1, d2);
+ }
+
+ private void AreEqual(Document d1, Document d2) {
+ if (!d1.Equals(d2)) {
+ Assert.Fail(string.Format("Documents don't match\r\nExpected: {0}\r\nActual: {1}", d1, d2));
+ }
+ }
+
+ private void AreNotEqual(Document d1, Document d2) {
+ if (d1.Equals(d2)) {
+ Assert.Fail(string.Format("Documents match\r\nExpected: not {0}\r\nActual: {1}", d1, d2));
+ }
+ }
+ }
+
+ public class ReverseComparer : IComparer<string>
+ {
+
+ public int Compare(string x, string y)
+ {
+ return y.CompareTo(x);
+ }
+ }
+}
View
9 MongoDB.Net-Tests/TestOid.cs
@@ -169,6 +169,13 @@ public class TestOid
var secondOid = new Oid(firstOid.ToString());
Assert.AreEqual(firstOid.ToString(), secondOid.ToString());
- }
+ }
+
+ [Test]
+ public void TestOidEqualityWithNull(){
+ Oid val = null;
+ Oid other = new Oid("5a7067c30a57000000008ecb");
+ Assert.IsFalse(val == other);
+ }
}
}
View
30 MongoDBDriver.sln
@@ -1,7 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
-# SharpDevelop 3.1.0.4890
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver", "MongoDBDriver\MongoDB.Driver.csproj", "{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}"
EndProject
Project("{9344bdbb-3e7f-41fc-a0dd-8665d75ee146}") = "Packages", "Packages.mdproj", "{502F3381-58AA-461B-B9D8-12578A588C61}"
@@ -22,10 +21,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{4345
ProjectSection(SolutionItems) = postProject
EndProjectSection
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple", "examples\Simple\Simple.csproj", "{131BDB5F-5C6F-4AC7-B03E-394B1B75E120}"
-EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "SimpleVB", "examples\SimpleVB\SimpleVB.vbproj", "{1BAAE3D8-7720-4AA5-9335-E59824E7B667}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple", "examples\Simple\Simple.csproj", "{131BDB5F-5C6F-4AC7-B03E-394B1B75E120}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -70,8 +69,10 @@ Global
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}.Release|Any CPU.Build.0 = Release|Any CPU
- {502F3381-58AA-461B-B9D8-12578A588C61}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {502F3381-58AA-461B-B9D8-12578A588C61}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {1BAAE3D8-7720-4AA5-9335-E59824E7B667} = {4345382B-FAA2-46E2-99CF-C90ACA2DD574}
+ {131BDB5F-5C6F-4AC7-B03E-394B1B75E120} = {4345382B-FAA2-46E2-99CF-C90ACA2DD574}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = MongoDBDriver\MongoDB.Driver.csproj
@@ -92,6 +93,21 @@ Global
$3.inheritsScope = text/plain
$3.scope = text/x-csharp
$0.CSharpFormattingPolicy = $4
+ $4.MethodBraceStyle = EndOfLine
+ $4.ConstructorBraceStyle = EndOfLine
+ $4.DestructorBraceStyle = EndOfLine
+ $4.BeforeMethodCallParentheses = False
+ $4.BeforeMethodDeclarationParentheses = False
+ $4.BeforeConstructorDeclarationParentheses = False
+ $4.NewParentheses = False
+ $4.IfParentheses = False
+ $4.WhileParentheses = False
+ $4.ForParentheses = False
+ $4.ForeachParentheses = False
+ $4.CatchParentheses = False
+ $4.SwitchParentheses = False
+ $4.LockParentheses = False
+ $4.UsingParentheses = False
$4.inheritsSet = Mono
$4.inheritsScope = text/x-csharp
$4.scope = text/x-csharp
@@ -105,8 +121,4 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {1BAAE3D8-7720-4AA5-9335-E59824E7B667} = {4345382B-FAA2-46E2-99CF-C90ACA2DD574}
- {131BDB5F-5C6F-4AC7-B03E-394B1B75E120} = {4345382B-FAA2-46E2-99CF-C90ACA2DD574}
- EndGlobalSection
EndGlobal
View
720 MongoDBDriver/Collection.cs
@@ -1,339 +1,381 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using MongoDB.Driver.Connections;
-using MongoDB.Driver.Protocol;
-
-namespace MongoDB.Driver
-{
- public class Collection : IMongoCollection
- {
- private Connection connection;
-
- private string name;
- public string Name {
- get { return name; }
- }
-
- private string dbName;
- public string DbName {
- get { return dbName; }
- }
-
- public string FullName{
- get{ return dbName + "." + name;}
- }
-
- private CollectionMetaData metaData;
- public CollectionMetaData MetaData {
- get {
- if(metaData == null){
- metaData = new CollectionMetaData(this.dbName,this.name, this.connection);
- }
- return metaData;
- }
- }
-
- private Database db;
- private Database Db{
- get{
- if(db == null)
- db = new Database(this.connection, this.dbName);
- return db;
- }
- }
- public Collection(string name, Connection conn, string dbName)
- {
- this.name = name;
- this.connection = conn;
- this.dbName = dbName;
- }
-
- /// <summary>
- /// Finds and returns the first document in a query.
- /// </summary>
- /// <param name="spec">
- /// A <see cref="Document"/> representing the query.
- /// </param>
- /// <returns>
- /// A <see cref="Document"/> from the collection.
- /// </returns>
- public Document FindOne(Document spec){
- ICursor cur = this.Find(spec, -1, 0, null);
- foreach(Document doc in cur.Documents){
- cur.Dispose();
- return doc;
- }
- //FIXME Decide if this should throw a not found exception instead of returning null.
- return null; //this.Find(spec, -1, 0, null)[0];
- }
-
- public ICursor FindAll() {
- Document spec = new Document();
- return this.Find(spec, 0, 0, null);
- }
-
- public ICursor Find(String where){
- Document spec = new Document();
- spec.Append("$where", new Code(where));
- return this.Find(spec, 0, 0, null);
- }
-
- public ICursor Find(Document spec) {
- return this.Find(spec, 0, 0, null);
- }
-
- public ICursor Find(Document spec, int limit, int skip) {
- return this.Find(spec, limit, skip, null);
- }
-
- public ICursor Find(Document spec, int limit, int skip, Document fields) {
- if(spec == null) spec = new Document();
- Cursor cur = new Cursor(connection, this.FullName, spec, limit, skip, fields);
- return cur;
- }
-
- /// <summary>
- /// Entrypoint into executing a map/reduce query against the collection.
- /// </summary>
- /// <returns>
- /// A <see cref="MapReduce"/>
- /// </returns>
- public MapReduce MapReduce(){
- return new MapReduce(this.Db, this.Name);
- }
-
- public MapReduceBuilder MapReduceBuilder(){
- return new MapReduceBuilder(this.MapReduce());
- }
-
-
- /// <summary>
- ///Count all items in the collection.
- /// </summary>
- public long Count(){
- return this.Count(new Document());
- }
-
- /// <summary>
- /// Count all items in a collection that match the query spec.
- /// </summary>
- /// <remarks>
- /// It will return 0 if the collection doesn't exist yet.
- /// </remarks>
- public long Count(Document spec){
- try{
- //Database db = new Database(this.connection, this.dbName);
- Document ret = this.Db.SendCommand(new Document().Append("count",this.Name).Append("query",spec));
- double n = (double)ret["n"];
- return Convert.ToInt64(n);
- }catch(MongoCommandException){
- //FIXME This is an exception condition when the namespace is missing.
- //-1 might be better here but the console returns 0.
- return 0;
- }
-
- }
-
- /// <summary>
- /// Inserts the Document into the collection.
- /// </summary>
- public void Insert (Document doc, bool safemode){
- Insert(doc);
- CheckError(safemode);
- }
-
- public void Insert(Document doc){
- Document[] docs = new Document[]{doc,};
- this.Insert(docs);
- }
-
- public void Insert (IEnumerable<Document> docs, bool safemode){
- if(safemode)this.Db.ResetError();
- this.Insert(docs);
- CheckPreviousError(safemode);
- }
-
- public void Insert(IEnumerable<Document> docs){
- InsertMessage im = new InsertMessage();
- im.FullCollectionName = this.FullName;
- List<Document> idocs = new List<Document>();
- foreach(Document doc in docs){
- if(doc.Contains("_id") == false){
- Oid _id = Oid.NewOid();
- doc.Prepend("_id",_id);
- }
- }
- idocs.AddRange(docs);
- im.Documents = idocs.ToArray();
- try{
- this.connection.SendMessage(im);
- }catch(IOException ioe){
- throw new MongoCommException("Could not insert document, communication failure", this.connection,ioe);
- }
- }
-
- /// <summary>
- /// Deletes documents from the collection according to the spec.
- /// </summary>
- /// <remarks>An empty document will match all documents in the collection and effectively truncate it.
- /// </remarks>
- public void Delete (Document selector, bool safemode){
- Delete(selector);
- CheckError(safemode);
- }
-
- /// <summary>
- /// Deletes documents from the collection according to the spec.
- /// </summary>
- /// <remarks>An empty document will match all documents in the collection and effectively truncate it.
- /// </remarks>
- public void Delete(Document selector){
- DeleteMessage dm = new DeleteMessage();
- dm.FullCollectionName = this.FullName;
- dm.Selector = selector;
- try{
- this.connection.SendMessage(dm);
- }catch(IOException ioe){
- throw new MongoCommException("Could not delete document, communication failure", this.connection,ioe);
- }
- }
-
-
- public void Update (Document doc, bool safemode){
- Update(doc);
- CheckError(safemode);
- }
-
- /// <summary>
- /// Saves a document to the database using an upsert.
- /// </summary>
- /// <remarks>
- /// The document will contain the _id that is saved to the database. This is really just an alias
- /// to Update(Document) to maintain consistency between drivers.
- /// </remarks>
- public void Save(Document doc){
- //Try to generate a selector using _id for an existing document.
- //otherwise just set the upsert flag to 1 to insert and send onward.
- Document selector = new Document();
- int upsert = 0;
- if(doc.Contains("_id") & doc["_id"] != null){
- selector["_id"] = doc["_id"];
- }else{
- //Likely a new document
- Oid id = Oid.NewOid();
- selector["_id"] = id;
- doc.Prepend("_id",id);
- upsert = 1;
- }
- this.Update(doc, selector, upsert);
- }
-
- /// <summary>
- /// Updates a document with the data in doc as found by the selector.
- /// </summary>
- /// <remarks>
- /// _id will be used in the document to create a selector. If it isn't in
- /// the document then it is assumed that the document is new and an upsert is sent to the database
- /// instead.
- /// </remarks>
- [Obsolete("Switch to Save(Document)")]
- public void Update(Document doc){
- Save(doc);
- }
-
- public void Update (Document doc, Document selector, bool safemode){
- Update(doc, selector,0,safemode);
- }
-
- /// <summary>
- /// Updates a document with the data in doc as found by the selector.
- /// </summary>
- public void Update(Document doc, Document selector){
- this.Update(doc, selector, 0);
- }
-
- public void Update (Document doc, Document selector, UpdateFlags flags, bool safemode){
- Update(doc,selector,flags);
- CheckError(safemode);
- }
-
- /// <summary>
- /// Updates a document with the data in doc as found by the selector.
- /// </summary>
- /// <param name="doc">The <see cref="Document"/> to update with
- /// </param>
- /// <param name="selector">
- /// The query spec to find the document to update.
- /// </param>
- /// <param name="flags">
- /// <see cref="UpdateFlags"/>
- /// </param>
- public void Update(Document doc, Document selector, UpdateFlags flags){
- UpdateMessage um = new UpdateMessage();
- um.FullCollectionName = this.FullName;
- um.Selector = selector;
- um.Document = doc;
- um.Flags = (int)flags;
- try{
- this.connection.SendMessage(um);
- }catch(IOException ioe){
- throw new MongoCommException("Could not update document, communication failure", this.connection,ioe);
- }
-
- }
-
- public void Update (Document doc, Document selector, int flags, bool safemode){
- Update(doc,selector,flags);
- CheckError(safemode);
- }
-
- public void Update(Document doc, Document selector, int flags){
- //TODO Update the interface and make a breaking change.
- this.Update(doc,selector,(UpdateFlags)flags);
- }
-
- /// <summary>
- /// Runs a multiple update query against the database. It will wrap any
- /// doc with $set if the passed in doc doesn't contain any '$' ops.
- /// </summary>
- /// <param name="doc"></param>
- /// <param name="selector"></param>
- public void UpdateAll(Document doc, Document selector){
- bool foundOp = false;
- foreach(string key in doc.Keys){
- if(key.IndexOf('$') == 0){
- foundOp = true;
- break;
- }
- }
- if(foundOp == false){
- //wrap document in a $set.
- Document s = new Document().Append("$set", doc);
- doc = s;
- }
- this.Update(doc, selector, UpdateFlags.MultiUpdate);
- }
-
-
- public void UpdateAll (Document doc, Document selector, bool safemode){
- if(safemode)this.Db.ResetError();
- this.UpdateAll(doc, selector);
- CheckPreviousError(safemode);
- }
-
-
- private void CheckError(bool safemode){
- if(safemode){
- Document err = this.Db.GetLastError();
- if(ErrorTranslator.IsError(err)) throw ErrorTranslator.Translate(err);
- }
- }
- private void CheckPreviousError(bool safemode){
- if(safemode){
- Document err = this.Db.GetPreviousError();
- if(ErrorTranslator.IsError(err)) throw ErrorTranslator.Translate(err);
- }
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.IO;
+using MongoDB.Driver.Connections;
+using MongoDB.Driver.Protocol;
+
+namespace MongoDB.Driver
+{
+ public class Collection : IMongoCollection
+ {
+ private Connection connection;
+
+ private string name;
+ public string Name {
+ get { return name; }
+ }
+
+ private string dbName;
+ public string DbName {
+ get { return dbName; }
+ }