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
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

14 changed files with 386 additions and 9 deletions
-
4.gitignore
-
2BsonUnitTests/.gitignore
-
6CSharpDriver.sln
-
2Driver/Core/MongoDatabase.cs
-
67DriverOnlineTests/Core/MongoCollectionTests.cs
-
58DriverOnlineTests/Core/MongoDatabaseTests.cs
-
85DriverOnlineTests/Core/MongoServerTests.cs
-
72DriverOnlineTests/DriverOnlineTests.csproj
-
50DriverOnlineTests/Properties/AssemblyInfo.cs
-
2DriverSetup/.gitignore
-
2DriverUnitTests/.gitignore
-
40DriverUnitTests/Core/MongoServerTests.cs
-
1DriverUnitTests/DriverUnitTests.csproj
-
4DriverUnitTests/Properties/AssemblyInfo.cs
@ -1,7 +1,7 @@ |
|||
bin |
|||
obj |
|||
Debug |
|||
Release |
|||
*.user |
|||
*.suo |
|||
*.vsp |
|||
*.csproj.VisualState.xml |
|||
TestResult.xml |
@ -1,2 +0,0 @@ |
|||
*.VisualState.xml |
|||
TestResult.xml |
@ -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); |
|||
} |
|||
} |
|||
} |
@ -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(); |
|||
} |
|||
} |
|||
} |
@ -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"); |
|||
} |
|||
} |
|||
} |
@ -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> |
@ -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.*")] |
@ -0,0 +1,2 @@ |
|||
Debug |
|||
Release |
@ -1,2 +0,0 @@ |
|||
*.VisualState.xml |
|||
TestResult.xml |
@ -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)); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue