Skip to content

Commit c9be46a

Browse files
committed
MongoDB test console app works
1 parent 5e7d768 commit c9be46a

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ Tools/xunit.runner.console
6363
src/MongoDB.Bson/project.lock.json
6464
src/MongoDB.Driver.Core/project.lock.json
6565
src/MongoDB.Driver/project.lock.json
66+
samples/MongoDB.Tests.ConsoleApp/project.lock.json

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"projects": [ "src" ]
3+
}

mongo-csharp-driver.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Driver.Core", "src\
1616
EndProject
1717
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Driver", "src\MongoDB.Driver\MongoDB.Driver.xproj", "{22C3CF35-4EEE-40DE-A313-33E2CFAC1F08}"
1818
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{EF7A690C-F868-4E61-8ED7-3D05AC39D209}"
20+
EndProject
21+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Tests.ConsoleApp", "samples\MongoDB.Tests.ConsoleApp\MongoDB.Tests.ConsoleApp.xproj", "{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}"
22+
EndProject
1923
Global
2024
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2125
Debug|Any CPU = Debug|Any CPU
@@ -34,6 +38,10 @@ Global
3438
{22C3CF35-4EEE-40DE-A313-33E2CFAC1F08}.Debug|Any CPU.Build.0 = Debug|Any CPU
3539
{22C3CF35-4EEE-40DE-A313-33E2CFAC1F08}.Release|Any CPU.ActiveCfg = Release|Any CPU
3640
{22C3CF35-4EEE-40DE-A313-33E2CFAC1F08}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}.Release|Any CPU.Build.0 = Release|Any CPU
3745
EndGlobalSection
3846
GlobalSection(SolutionProperties) = preSolution
3947
HideSolutionNode = FALSE
@@ -42,5 +50,6 @@ Global
4250
{E6B739E6-DDD8-4BA5-8595-FD59A0783153} = {B4E459B4-5B8C-4933-BECC-AEB36CEC84F6}
4351
{B86DE81A-6CAB-458D-852C-358114C146DB} = {B4E459B4-5B8C-4933-BECC-AEB36CEC84F6}
4452
{22C3CF35-4EEE-40DE-A313-33E2CFAC1F08} = {B4E459B4-5B8C-4933-BECC-AEB36CEC84F6}
53+
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2} = {EF7A690C-F868-4E61-8ED7-3D05AC39D209}
4554
EndGlobalSection
4655
EndGlobal
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>ccd9b0ee-086a-46f4-8307-9e46e50c57c2</ProjectGuid>
11+
<RootNamespace>MongoDB.Tests.ConsoleApp</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
using MongoDB.Bson;
7+
using MongoDB.Driver;
8+
9+
namespace MongoDB.Tests.ConsoleApp
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
Test1().GetAwaiter().GetResult();
16+
Test2().GetAwaiter().GetResult();
17+
Console.Read();
18+
}
19+
20+
public static async Task Test1()
21+
{
22+
var client = new MongoClient("mongodb://localhost:27017");
23+
var database = client.GetDatabase("foo");
24+
var collection = database.GetCollection<BsonDocument>("bar");
25+
26+
await collection.InsertOneAsync(new BsonDocument("Name", "Jack"));
27+
28+
var list = await collection.Find(new BsonDocument("Name", "Jack"))
29+
.ToListAsync();
30+
31+
foreach (var document in list)
32+
{
33+
Console.WriteLine(document["Name"]);
34+
}
35+
}
36+
37+
public class Person
38+
{
39+
public ObjectId Id { get; set; }
40+
public string Name { get; set; }
41+
}
42+
43+
public static async Task Test2()
44+
{
45+
var client = new MongoClient("mongodb://localhost:27017");
46+
var database = client.GetDatabase("foo");
47+
var collection = database.GetCollection<Person>("bar");
48+
49+
await collection.InsertOneAsync(new Person { Name = "Jack" });
50+
51+
var list = await collection.Find(x => x.Name == "Jack")
52+
.ToListAsync();
53+
54+
foreach (var person in list)
55+
{
56+
Console.WriteLine(person.Name);
57+
}
58+
}
59+
}
60+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("MongoDB.Tests.ConsoleApp")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("ccd9b0ee-086a-46f4-8307-9e46e50c57c2")]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "1.0.0-*",
3+
"buildOptions": {
4+
"emitEntryPoint": true
5+
},
6+
7+
"dependencies": {
8+
"Microsoft.NETCore.App": {
9+
"type": "platform",
10+
"version": "1.0.0-rc2-3002702"
11+
},
12+
"MongoDB.Bson": "2.2.4-*",
13+
"MongoDB.Driver": "2.2.4-*"
14+
},
15+
16+
"frameworks": {
17+
"netcoreapp1.0": {
18+
"imports": [ "dnxcore50", "portable-net451+win8" ]
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)