aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio_v2/Tango.UnitTests/BLL/Services/OrganizationsService_TST.cs
blob: 4db1af5c4f22bec38e5595f70a1af6f907677d65 (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
54
55
56
57
58
59
60
61
62
63
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BLL.Objects;
using Tango.BLL.Services;
using Tango.DAL.Entities;
using Tango.DAL.Mongo;

namespace Tango.UnitTests.BLL.Services
{
    [TestClass]
    [TestCategory("BLL.OrganizationsService")]
    public class OrganizationsService_TST
    {
        [TestMethod]
        public void Simple_Operations()
        {
            OrganizationsService service = new OrganizationsService(new MongoRepository<OrganizationEntity>(new MongoDataBaseSettings()
            {
                Address = "mongodb://localhost:27017",
                DatabaseName = "TEST"
            }));

            service.DeleteAllOrganizations().GetAwaiter().GetResult();

            Organization org1 = new Organization();
            org1.Name = "Org 1";
            org1.Address.AddressString = "Yohana 7 a";
            org1.Address.City = "Gan Yavne";
            org1.Address.State = "Israel";
            org1.Contact.Email = "roy@twine-s.com";
            org1.Contact.FirstName = "Roy";
            org1.Contact.LastName = "Ben Shabat";

            service.AddOrganization(org1).GetAwaiter().GetResult();

            Assert.IsNotNull(org1.ID);

            Organization orgDuplicate = new Organization();
            orgDuplicate.Name = org1.Name;

            Assert.ThrowsException<MongoDB.Driver.MongoWriteException>(() =>
            {
                service.AddOrganization(orgDuplicate).GetAwaiter().GetResult();
            });

            var org2 = service.GetOrganizationByID(org1.ID).GetAwaiter().GetResult();

            Assert.AreEqual(org1.Name, org2.Name);

            long count = service.DeleteOrganizationByID(org1.ID).GetAwaiter().GetResult();

            Assert.AreEqual(count, 1);

            count = service.Count().GetAwaiter().GetResult();

            Assert.AreEqual(count, 0);
        }
    }
}