blob: d15b1c7a9d36d79b2f123be5f3ed9453531d01fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tango.DAL.Entities;
using Tango.DAL.Mongo;
using System.Linq;
namespace Tango.UnitTests.DAL
{
[TestClass]
public class Mongo
{
[TestMethod]
public void Simple_Operations()
{
MongoRepository<OrganizationEntity> repo = new MongoRepository<OrganizationEntity>(new MongoDataBaseSettings()
{
Address = "mongodb://localhost:27017",
DatabaseName = "TEST"
});
repo.DeleteAsync(x => true).GetAwaiter().GetResult();
OrganizationEntity org1 = new OrganizationEntity();
org1.Name = "Org 1";
repo.Insert(org1).GetAwaiter().GetResult();
OrganizationEntity orgDuplicate = new OrganizationEntity();
orgDuplicate.Name = org1.Name;
Assert.ThrowsException<MongoDB.Driver.MongoWriteException>(() =>
{
repo.Insert(orgDuplicate).GetAwaiter().GetResult();
});
Assert.IsNotNull(org1.ID);
var org2 = repo.GetAsync(x => x.ID == org1.ID).GetAwaiter().GetResult().FirstOrDefault();
Assert.IsNotNull(org2);
Assert.AreEqual(org1.Name, org2.Name);
long count = repo.DeleteAsync(x => x.ID == org1.ID).GetAwaiter().GetResult();
Assert.AreEqual(count, 1);
count = repo.Count().GetAwaiter().GetResult();
Assert.AreEqual(count, 0);
}
}
}
|