Browse Source

Added initial version of DriverOnlineTests project. These tests differ from the tests in DriverUnitTests because they connect to localhost to test against a live database.

pull/10/head
rstam 15 years ago
parent
commit
668110faf6
  1. 4
      .gitignore
  2. 2
      BsonUnitTests/.gitignore
  3. 6
      CSharpDriver.sln
  4. 2
      Driver/Core/MongoDatabase.cs
  5. 67
      DriverOnlineTests/Core/MongoCollectionTests.cs
  6. 58
      DriverOnlineTests/Core/MongoDatabaseTests.cs
  7. 85
      DriverOnlineTests/Core/MongoServerTests.cs
  8. 72
      DriverOnlineTests/DriverOnlineTests.csproj
  9. 50
      DriverOnlineTests/Properties/AssemblyInfo.cs
  10. 2
      DriverSetup/.gitignore
  11. 2
      DriverUnitTests/.gitignore
  12. 40
      DriverUnitTests/Core/MongoServerTests.cs
  13. 1
      DriverUnitTests/DriverUnitTests.csproj
  14. 4
      DriverUnitTests/Properties/AssemblyInfo.cs

4
.gitignore

@ -1,7 +1,7 @@
bin
obj
Debug
Release
*.user
*.suo
*.vsp
*.csproj.VisualState.xml
TestResult.xml

2
BsonUnitTests/.gitignore

@ -1,2 +0,0 @@
*.VisualState.xml
TestResult.xml

6
CSharpDriver.sln

@ -11,6 +11,8 @@ Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "DriverSetup", "DriverSetup\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DriverUnitTests", "DriverUnitTests\DriverUnitTests.csproj", "{DBF3A41B-D0EE-4CA5-ADA6-EB1A4DE903E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DriverOnlineTests", "DriverOnlineTests\DriverOnlineTests.csproj", "{FBBF0D71-107F-49C4-8858-B3A4DC24AA33}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -35,6 +37,10 @@ Global
{DBF3A41B-D0EE-4CA5-ADA6-EB1A4DE903E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBF3A41B-D0EE-4CA5-ADA6-EB1A4DE903E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBF3A41B-D0EE-4CA5-ADA6-EB1A4DE903E1}.Release|Any CPU.Build.0 = Release|Any CPU
{FBBF0D71-107F-49C4-8858-B3A4DC24AA33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBBF0D71-107F-49C4-8858-B3A4DC24AA33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBBF0D71-107F-49C4-8858-B3A4DC24AA33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBBF0D71-107F-49C4-8858-B3A4DC24AA33}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

2
Driver/Core/MongoDatabase.cs

@ -300,7 +300,7 @@ namespace MongoDB.Driver {
}
if (!result["ok"].ToBoolean()) {
string errmsg = result["errmsg"].AsString;
string errorMessage = string.Format("Command failed: {1}", errmsg);
string errorMessage = string.Format("Command failed: {0}", errmsg);
throw new MongoCommandException(errorMessage);
}
return result;

67
DriverOnlineTests/Core/MongoCollectionTests.cs

@ -0,0 +1,67 @@
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using MongoDB.Bson;
using MongoDB.Driver;
namespace MongoDB.DriverOnlineTests {
[TestFixture]
public class MongoCollectionTests {
private MongoServer server;
private MongoDatabase database;
private MongoCollection<BsonDocument> collection;
[TestFixtureSetUp]
public void Setup() {
server = MongoServer.Create();
server.Connect();
database = server["onlinetests"];
collection = database["testcollection"];
}
// TODO: more tests for MongoCollection
[Test]
public void TestCountZero() {
collection.RemoveAll();
var count = collection.Count();
Assert.AreEqual(0, count);
}
[Test]
public void TestCountOne() {
collection.RemoveAll();
collection.Insert(new BsonDocument());
var count = collection.Count();
Assert.AreEqual(1, count);
}
[Test]
public void TestSetFields() {
collection.RemoveAll();
collection.Insert(new BsonDocument { { "x", 1 }, { "y", 2 } });
var result = collection.FindAll().SetFields("x").FirstOrDefault();
Assert.AreEqual(2, result.Count);
Assert.AreEqual("_id", result.GetElement(0).Name);
Assert.AreEqual("x", result.GetElement(1).Name);
}
}
}

58
DriverOnlineTests/Core/MongoDatabaseTests.cs

@ -0,0 +1,58 @@
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using MongoDB.Bson;
using MongoDB.Driver;
namespace MongoDB.DriverOnlineTests {
[TestFixture]
public class MongoDatabaseTests {
private MongoServer server;
private MongoDatabase database;
[TestFixtureSetUp]
public void Setup() {
server = MongoServer.Create();
server.Connect();
database = server["onlinetests"];
}
// TODO: more tests for MongoDatabase
[Test]
public void TestDropCollection() {
var collectionName = "testdropcollection";
var collection = database[collectionName];
collection.Insert(new BsonDocument());
var collectionNames = database.GetCollectionNames();
Assert.IsTrue(collectionNames.Contains(collection.FullName));
database.DropCollection(collectionName);
collectionNames = database.GetCollectionNames();
Assert.IsFalse(collectionNames.Contains(collection.FullName));
}
[Test]
public void TestGetCollectionNames() {
var collectionNames = database.GetCollectionNames();
}
}
}

85
DriverOnlineTests/Core/MongoServerTests.cs

@ -0,0 +1,85 @@
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using MongoDB.Bson;
using MongoDB.Driver;
namespace MongoDB.DriverOnlineTests {
[TestFixture]
public class MongoServerTests {
private MongoServer server;
private MongoDatabase database;
[TestFixtureSetUp]
public void Setup() {
server = MongoServer.Create();
server.Connect();
database = server["onlinetests"];
}
// TODO: more tests for MongoServer
[Test]
public void TestDropDatabase() {
var databaseName = "onlinetests-temp";
var database = server[databaseName];
var test = database["test"];
test.Insert(new BsonDocument());
var databaseNames = server.GetDatabaseNames();
Assert.IsTrue(databaseNames.Contains(databaseName));
var result = server.DropDatabase(databaseName);
databaseNames = server.GetDatabaseNames();
Assert.IsFalse(databaseNames.Contains(databaseName));
}
[Test]
public void TestGetDatabaseNames() {
var databaseNames = server.GetDatabaseNames();
}
[Test]
public void TestReconnect() {
server.Reconnect();
Assert.AreEqual(MongoServerState.Connected, server.State);
}
[Test]
public void TestRenameCollection() {
var collectionNames = database.GetCollectionNames();
if (collectionNames.Contains("testrenamecollection1")) { database.DropCollection("testrenamecollection1"); }
if (collectionNames.Contains("testrenamecollection2")) { database.DropCollection("testrenamecollection2"); }
var collection1 = database["testrenamecollection1"];
collection1.Insert(new BsonDocument("x", 1));
collectionNames = database.GetCollectionNames();
Assert.IsTrue(collectionNames.Contains("onlinetests.testrenamecollection1"));
Assert.IsFalse(collectionNames.Contains("onlinetests.testrenamecollection2"));
server.RenameCollection("onlinetests.testrenamecollection1", "onlinetests.testrenamecollection2");
collectionNames = database.GetCollectionNames();
Assert.IsFalse(collectionNames.Contains("onlinetests.testrenamecollection1"));
Assert.IsTrue(collectionNames.Contains("onlinetests.testrenamecollection2"));
database.DropCollection("testrenamecollection2");
}
}
}

72
DriverOnlineTests/DriverOnlineTests.csproj

@ -0,0 +1,72 @@
<?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>{FBBF0D71-107F-49C4-8858-B3A4DC24AA33}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MongoDB.DriverOnlineTests</RootNamespace>
<AssemblyName>MongoDB.DriverOnlineTests</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="nunit.framework, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
<Reference Include="System" />
<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="Core\MongoCollectionTests.cs" />
<Compile Include="Core\MongoDatabaseTests.cs" />
<Compile Include="Core\MongoServerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bson\Bson.csproj">
<Project>{0E9A3A2A-49CD-4F6C-847C-DC79B4B65CE6}</Project>
<Name>Bson</Name>
</ProjectReference>
<ProjectReference Include="..\Driver\Driver.csproj">
<Project>{AE5166CD-76B0-4911-BD80-CED9521F37A1}</Project>
<Name>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>

50
DriverOnlineTests/Properties/AssemblyInfo.cs

@ -0,0 +1,50 @@
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.DriverOnlineTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("10gen Inc.")]
[assembly: AssemblyProduct("MongoDB.DriverOnlineTests")]
[assembly: AssemblyCopyright("Copyright © 2010 10gen Inc.")]
[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("1c95faac-3afd-4038-bd5e-5cbd65377453")]
// 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("0.5.0.*")]

2
DriverSetup/.gitignore

@ -0,0 +1,2 @@
Debug
Release

2
DriverUnitTests/.gitignore

@ -1,2 +0,0 @@
*.VisualState.xml
TestResult.xml

40
DriverUnitTests/Core/MongoServerTests.cs

@ -0,0 +1,40 @@
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using MongoDB.Driver;
namespace MongoDB.DriverUnitTests {
[TestFixture]
public class MongoServerTests {
[Test]
public void TestCreateNoArgs() {
var server = MongoServer.Create();
var expectedSeedList = new[] { new MongoServerAddress("localhost") };
Assert.IsNull(server.AdminCredentials);
Assert.IsNull(server.DefaultCredentials);
Assert.IsNull(server.ReplicaSet);
Assert.AreEqual(SafeMode.False, server.SafeMode);
Assert.AreEqual(false, server.SlaveOk);
Assert.AreEqual(MongoServerState.Disconnected, server.State);
Assert.IsTrue(expectedSeedList.SequenceEqual(server.SeedList));
}
}
}

1
DriverUnitTests/DriverUnitTests.csproj

@ -52,6 +52,7 @@
<Compile Include="Builders\IndexOptionsBuilderTests.cs" />
<Compile Include="Builders\MapReduceOptionsBuilderTests.cs" />
<Compile Include="Builders\UpdateBuilderTests.cs" />
<Compile Include="Core\MongoServerTests.cs" />
<Compile Include="Core\MongoUrlTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Builders\QueryBuilderTests.cs" />

4
DriverUnitTests/Properties/AssemblyInfo.cs

@ -20,11 +20,11 @@ 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.Driver.UnitTests")]
[assembly: AssemblyTitle("MongoDB.DriverUnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("10gen Inc.")]
[assembly: AssemblyProduct("MongoDB.Driver.UnitTests")]
[assembly: AssemblyProduct("MongoDB.DriverUnitTests")]
[assembly: AssemblyCopyright("Copyright © 2010 10gen Inc.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Loading…
Cancel
Save