aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs
blob: 8a2314858499fa374b8600cc60bad5e55ab4881b (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
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();

            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);
        }
    }
}