
7 changed files with 300 additions and 6 deletions
-
25MongoDBClient/MongoConnectionStringBuilder.cs
-
17MongoDBClient/MongoServerAddress.cs
-
2MongoDBClientTests/.gitignore
-
139MongoDBClientTests/MongoConnectionStringBuilderTests.cs
-
66MongoDBClientTests/MongoDBClientTests.csproj
-
51MongoDBClientTests/Properties/AssemblyInfo.cs
-
6mongo-csharp-driver.sln
@ -0,0 +1,2 @@ |
|||
*.VisualState.xml |
|||
TestResult.xml |
@ -0,0 +1,139 @@ |
|||
/* 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.MongoDBClient; |
|||
|
|||
namespace MongoDB.MongoDBClient.Tests { |
|||
[TestFixture] |
|||
public class MongoConnectionStringBuilderTests { |
|||
[Test] |
|||
public void TestL() { |
|||
string connectionString = "mongodb://localhost"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(1, csb.Servers.Count); |
|||
Assert.AreEqual("localhost", csb.Servers[0].Host); |
|||
Assert.AreEqual(27017, csb.Servers[0].Port); |
|||
Assert.IsNull(csb.Database); |
|||
Assert.IsNull(csb.Username); |
|||
Assert.IsNull(csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestH() { |
|||
string connectionString = "mongodb://mongo.xyz.com"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(1, csb.Servers.Count); |
|||
Assert.AreEqual("mongo.xyz.com", csb.Servers[0].Host); |
|||
Assert.AreEqual(27017, csb.Servers[0].Port); |
|||
Assert.IsNull(csb.Database); |
|||
Assert.IsNull(csb.Username); |
|||
Assert.IsNull(csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestHP() { |
|||
string connectionString = "mongodb://mongo.xyz.com:12345"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(1, csb.Servers.Count); |
|||
Assert.AreEqual("mongo.xyz.com", csb.Servers[0].Host); |
|||
Assert.AreEqual(12345, csb.Servers[0].Port); |
|||
Assert.IsNull(csb.Database); |
|||
Assert.IsNull(csb.Username); |
|||
Assert.IsNull(csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestH1H2() { |
|||
string connectionString = "mongodb://mongo1.xyz.com,mongo2.xyz.com"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(2, csb.Servers.Count); |
|||
Assert.AreEqual("mongo1.xyz.com", csb.Servers[0].Host); |
|||
Assert.AreEqual(27017, csb.Servers[0].Port); |
|||
Assert.AreEqual("mongo2.xyz.com", csb.Servers[1].Host); |
|||
Assert.AreEqual(27017, csb.Servers[1].Port); |
|||
Assert.IsNull(csb.Database); |
|||
Assert.IsNull(csb.Username); |
|||
Assert.IsNull(csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestH1P1H2P2() { |
|||
string connectionString = "mongodb://mongo1.xyz.com:12345,mongo2.xyz.com:23456"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(2, csb.Servers.Count); |
|||
Assert.AreEqual("mongo1.xyz.com", csb.Servers[0].Host); |
|||
Assert.AreEqual(12345, csb.Servers[0].Port); |
|||
Assert.AreEqual("mongo2.xyz.com", csb.Servers[1].Host); |
|||
Assert.AreEqual(23456, csb.Servers[1].Port); |
|||
Assert.IsNull(csb.Database); |
|||
Assert.IsNull(csb.Username); |
|||
Assert.IsNull(csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestUPLD() { |
|||
string connectionString = "mongodb://userx:pwd@localhost/dbname"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(1, csb.Servers.Count); |
|||
Assert.AreEqual("localhost", csb.Servers[0].Host); |
|||
Assert.AreEqual(27017, csb.Servers[0].Port); |
|||
Assert.AreEqual("dbname", csb.Database); |
|||
Assert.AreEqual("userx", csb.Username); |
|||
Assert.AreEqual("pwd", csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestUPH1H2D() { |
|||
string connectionString = "mongodb://userx:pwd@mongo1.xyz.com,mongo2.xyz.com/dbname"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(2, csb.Servers.Count); |
|||
Assert.AreEqual("mongo1.xyz.com", csb.Servers[0].Host); |
|||
Assert.AreEqual(27017, csb.Servers[0].Port); |
|||
Assert.AreEqual("mongo2.xyz.com", csb.Servers[1].Host); |
|||
Assert.AreEqual(27017, csb.Servers[1].Port); |
|||
Assert.AreEqual("dbname", csb.Database); |
|||
Assert.AreEqual("userx", csb.Username); |
|||
Assert.AreEqual("pwd", csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestUPH1P1H2P2D() { |
|||
string connectionString = "mongodb://userx:pwd@mongo1.xyz.com:12345,mongo2.xyz.com:23456/dbname"; |
|||
MongoConnectionStringBuilder csb = new MongoConnectionStringBuilder(connectionString); |
|||
Assert.AreEqual(2, csb.Servers.Count); |
|||
Assert.AreEqual("mongo1.xyz.com", csb.Servers[0].Host); |
|||
Assert.AreEqual(12345, csb.Servers[0].Port); |
|||
Assert.AreEqual("mongo2.xyz.com", csb.Servers[1].Host); |
|||
Assert.AreEqual(23456, csb.Servers[1].Port); |
|||
Assert.AreEqual("dbname", csb.Database); |
|||
Assert.AreEqual("userx", csb.Username); |
|||
Assert.AreEqual("pwd", csb.Password); |
|||
Assert.AreEqual(connectionString, csb.ToString()); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,66 @@ |
|||
<?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>{DBF3A41B-D0EE-4CA5-ADA6-EB1A4DE903E1}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>MongoDB.MongoDBClient.Tests</RootNamespace> |
|||
<AssemblyName>MongoDBClientTests</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.5.10112, 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="MongoConnectionStringBuilderTests.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\MongoDBClient\MongoDBClient.csproj"> |
|||
<Project>{AE5166CD-76B0-4911-BD80-CED9521F37A1}</Project> |
|||
<Name>MongoDBClient</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,51 @@ |
|||
/* 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("MongoDBClientTests")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("Microsoft")] |
|||
[assembly: AssemblyProduct("MongoDBClientTests")] |
|||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] |
|||
[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("d1d7aede-4d9c-407d-959a-118b166fcf3f")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Write
Preview
Loading…
Cancel
Save
Reference in new issue