示例#1
0
        public async Task OpenAirConnector_GetUnsubmittedTimesheetsAsync()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set(CreateTimesheetXmlContent((UserId: 3, new DateOnly(2019, 1, 28), Status: 'S', Hours: 40)))
                          .Set(CreateTimesheetXmlContent(
                                   (UserId: 2, new DateOnly(2019, 2, 28), Status: 'A', Hours: 30),
                                   (UserId: 3, new DateOnly(2019, 2, 28), Status: 'S', Hours: 40)));

            var client         = new OpenAirClient(() => handler, options);
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);
            var user           = CreateUser(2, "Test", "Q", "[email protected]");
            var date           = new DateTime(2019, 2, 1);

            storageService.GetAllActiveUsersAsync().ReturnsForAnyArgs(new[] { user });

            // Act
            var timesheets = await connector.GetUnsubmittedTimesheetsAsync(date, date, TimesheetStates.Unsubmitted, "[email protected]", true, string.Empty, null);

            Assert.AreEqual(1, timesheets.Count);
            Assert.AreEqual("Test", timesheets[0].UserName);
            Assert.AreEqual("Q", timesheets[0].DepartmentName);
            Assert.AreEqual(30, timesheets[0].Total);
        }
示例#2
0
        public async Task OpenAirConnector_GetUnsubmittedTimesheetsWithOldDataAsync()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"><Timesheet><status>A</status><userid>397</userid><name>PTO</name><total>8.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes>PTO</notes></Timesheet><Timesheet><status>A</status><userid>283</userid><name>PTO</name><total>8.00</total><starts><Date><month>03</month><day>04</day><year>2019</year></Date></starts><notes>PTO</notes></Timesheet><Timesheet><status>A</status><userid>520</userid><name>PTO</name><total>16.00</total><starts><Date><month>03</month><day>04</day><year>2019</year></Date></starts><notes>PTO</notes></Timesheet><Timesheet><status>A</status><userid>283</userid><name/><total>32.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet><Timesheet><status>A</status><userid>722</userid><name/><total>32.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet><Timesheet><status>A</status><userid>397</userid><name/><total>32.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet><Timesheet><status>A</status><userid>133</userid><name/><total>32.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet><Timesheet><status>A</status><userid>921</userid><name/><total>32.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet><Timesheet><status>A</status><userid>283</userid><name/><total>8.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet><Timesheet><status>A</status><userid>921</userid><name/><total>8.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet><Timesheet><status>A</status><userid>520</userid><name>02/25/19 to 03/03/19</name><total>32.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes></notes></Timesheet><Timesheet><status>A</status><userid>722</userid><name/><total>8.00</total><starts><Date><month>02</month><day>25</day><year>2019</year></Date></starts><notes/></Timesheet></Read ></response>")
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"></Read ></response>")
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"></Read ></response>");

            var client         = new OpenAirClient(() => handler, options);
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);
            var date           = new DateTime(2019, 3, 6);

            storageService
            .GetAllActiveUsersAsync()
            .ReturnsForAnyArgs(new[]
            {
                CreateUser(397, "A", ".NET", "[email protected]"),
                CreateUser(283, "B", ".NET", "[email protected]"),
                CreateUser(520, "C", ".NET", "[email protected]"),
                CreateUser(722, "D", ".NET", "[email protected]"),
                CreateUser(133, "E", ".NET", "[email protected]"),
                CreateUser(921, "F", ".NET", "[email protected]"),
            });

            // Act
            var timesheets = await connector.GetUnsubmittedTimesheetsAsync(date, date, TimesheetStates.Unsubmitted, "[email protected]", true, string.Empty, null);

            Assert.AreEqual(6, timesheets.Count);
        }
示例#3
0
        public async Task OpenAirConnector_GetUnsubmittedTimesheetsAsync()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler
            {
                ResponseContent = "<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth><Read status=\"0\"><Timesheet><status>A</status><userid>2</userid><name>A</name><total>30.00</total><starts><Date><month>02</month><day>28</day><year>2019</year></Date></starts><notes>PTO</notes></Timesheet><Timesheet><status>S</status><userid>3</userid><name></name><total>40.00</total><starts><Date><month>01</month><day>28</day><year>2019</year></Date></starts><notes></notes></Timesheet></Read ></response>"
            };

            var client         = new OpenAirClient(() => handler, options);
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);
            var user           = new User {
                Name = "Test", Department = new Department {
                    Name = "Q"
                }, OpenAirUserId = 2
            };
            var date = new DateTime(2019, 2, 1);

            storageService.GetUsersByIdList(null).ReturnsForAnyArgs(new[] { user });

            // Act
            var timesheets = await connector.GetUnsubmittedTimesheetsAsync(date);

            var content = Encoding.UTF8.GetString(handler.Content);

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>R</user><password>P</password></Login></Auth><Read type=\"Timesheet\" filter=\"newer-than,older-than\" field=\"starts,starts\" method=\"all\" limit=\"1000\"><Date><month>1</month><day>20</day><year>2019</year></Date><Date><month>2</month><day>2</day><year>2019</year></Date><_Return><status/><name /><total/><notes /><userid /><starts /></_Return></Read></request>", content);
            Assert.AreEqual(1, timesheets.Count);
            Assert.AreEqual("Test", timesheets[0].UserName);
            Assert.AreEqual("A", timesheets[0].Name);
            Assert.AreEqual("Q", timesheets[0].DepartmentName);
            Assert.AreEqual(30, timesheets[0].Total);
        }
示例#4
0
        public async Task OpenAirShouldSyncUsersAndUpdateDepartmentName()
        {
            var client         = Substitute.For <IOpenAirClient>();
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);
            var options        = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var user           = new OpenAirClient.User
            {
                Id           = 1000,
                Name         = "A",
                DepartmentId = 2000,
                Active       = true,
                Address      = new[]
                {
                    new OpenAirClient.Address {
                        Email = "*****@*****.**"
                    }
                },
                ManagerId = 1010
            };
            var userManager = new OpenAirClient.User
            {
                Id           = 1010,
                Name         = "B",
                DepartmentId = 2000,
                Active       = true,
                Address      = new[]
                {
                    new OpenAirClient.Address {
                        Email = "*****@*****.**"
                    }
                }
            };

            var dep = new OpenAirClient.Department
            {
                Id     = 2000,
                Name   = "Test",
                UserId = 1010
            };

            client.GetAllUsersAsync().Returns(new[] { user, userManager });
            client.GetAllDepartmentsAsync().Returns(new[] { dep });
            client.GetAllActiveCustomersAsync().Returns(new OpenAirClient.Customer[0]);
            client.GetAllActiveBookingsAsync(DateTime.MinValue).ReturnsForAnyArgs(new OpenAirClient.Booking[0]);
            storageService
            .GetAllUsersAsync()
            .ReturnsForAnyArgs(new[]
            {
                CreateUser(1000, "A", "OldDep", "*****@*****.**", 2000, 1010, 1010),
                CreateUser(1010, "B", "Test", null, 2000, 0, 1010)
            });

            // Act
            await connector.SyncUsersAsync();

            storageService.Received().UpdateUsersAsync(Arg.Is <IReadOnlyList <User> >(list =>
                                                                                      list.Any(u => u.OpenAirUserId == 1000 && u.Department.Name == "Test")));
        }
示例#5
0
        public async Task OpenAirClientGetUsersByActiveAsync_ShouldParseResult()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<response><Auth status=\"0\"></Auth ><Read status=\"0\"><User></User></Read ></response>");

            var client = new OpenAirClient(() => handler, options);
            var user   = await client.GetAllUsersAsync();

            var content = Encoding.UTF8.GetString(handler[0].RequestContent);

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>R</user><password>P</password></Login></Auth><Read type=\"User\" method=\"all\" limit=\"0,1000\"><_Return><id /><name /><addr /><departmentid /><active /><line_managerid /><user_locationid /><usr_start_date__c/></_Return></Read></request>", content);
        }
示例#6
0
        public async Task OpenAirClientGetTimesheetsByStatus_ShouldParseResult()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"></Read ></response>");

            var client  = new OpenAirClient(() => handler, options);
            var date    = new DateTime(2000, 10, 10);
            var results = await client.GetTimesheetsByStatusAsync(date, date, "A");

            var content = Encoding.UTF8.GetString(handler[0].RequestContent);

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>R</user><password>P</password></Login></Auth><Read type=\"Timesheet\" filter=\"newer-than,older-than\" field=\"starts,starts\" method=\"equal to\" limit=\"0,1000\"><Date><month>10</month><day>10</day><year>2000</year></Date><Date><month>10</month><day>10</day><year>2000</year></Date><Timesheet><status>A</status></Timesheet><_Return><status/><name /><total/><notes /><userid /><starts /></_Return></Read></request>", content);
        }
示例#7
0
        public async Task OpenAirClientGetCustomers_ShouldParseResult()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"><Customer><id>1000</id><name>A</name></Customer><Customer><id>1001</id><name>B</name></Customer></Read ></response>");

            var client  = new OpenAirClient(() => handler, options);
            var date    = new DateTime(2000, 10, 10);
            var results = await client.GetAllActiveCustomersAsync();

            var content = Encoding.UTF8.GetString(handler[0].RequestContent);

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>R</user><password>P</password></Login></Auth><Read type=\"Customer\" method=\"equal to\" limit=\"0,1000\"><Customer><active>1</active></Customer><_Return><id/><name /></_Return></Read></request>", content);
            Assert.AreEqual(2, results.Count);
        }
示例#8
0
        public async Task OpenAirClientGetAllUsers_ShouldParseInvalidStartDate()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var record  =
                "<User><departmentid>2</departmentid><name>Oniyide, Temitope</name><id>1623</id><active>1</active>" +
                "<usr_start_date__c>0000-00-00</usr_start_date__c></User>";
            var handler = new MockHttpMessageHandler()
                          .Set($"<response><Auth status=\"0\"></Auth ><Read status=\"0\">{record}</Read ></response>");

            var client = new OpenAirClient(() => handler, options);

            var results = await client.GetAllUsersAsync();

            Assert.IsNull(results.Single().StartDate);
        }
 /// <summary>Creates the request body.</summary>
 public static Request CreateRequest(OpenAirOptions options, string username, string password) =>
 new Request
 {
     Client = options.OpenAirCompany,
     Key    = options.OpenAirApiKey,
     Auth   = new Auth
     {
         Login = new Login
         {
             Company  = options.OpenAirCompany,
             User     = username,
             Password = password
         }
     }
 };
示例#10
0
        public async Task OpenAirClientGetAllActiveBookings_ShouldParseResult()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"><Booking><userid>257</userid><booking_typeid>9</booking_typeid><id>95603</id><ownerid>265</ownerid><projectid>3410</projectid><customerid>10</customerid></Booking></Read ></response>");

            var client   = new OpenAirClient(() => handler, options);
            var bookings = await client.GetAllActiveBookingsAsync(new DateTime(2019, 1, 1));

            var content = Encoding.UTF8.GetString(handler[0].RequestContent);

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>R</user><password>P</password></Login></Auth><Read type=\"Booking\" filter=\"newer-than,older-than\" field=\"enddate,startdate\" method=\"equal to\" limit=\"0,1000\"><Date><month>12</month><day>31</day><year>2018</year></Date><Date><month>1</month><day>2</day><year>2019</year></Date><Booking><approval_status>A</approval_status></Booking><_Return><id/><userid/><ownerid /><projectid /><customerid /><booking_typeid /></_Return></Read></request>", content);
            Assert.AreEqual(257, bookings[0].UserId);
            Assert.AreEqual(10, bookings[0].CustomerId);
        }
示例#11
0
        public async Task OpenAirClientGetAllDepartments_ShouldParseResult()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "U", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"><Department><userid>1</userid><name>.NET</name><id>101</id></Department></Read ></response>");

            var client      = new OpenAirClient(() => handler, options);
            var departments = await client.GetAllDepartmentsAsync();

            var content    = Encoding.UTF8.GetString(handler[0].RequestContent);
            var department = departments.First();

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>U</user><password>P</password></Login></Auth><Read type=\"Department\" method=\"all\" limit=\"0,1000\"><_Return><id /><name /><userid /></_Return></Read></request>", content);
            Assert.AreEqual(101, department.Id);
            Assert.AreEqual(".NET", department.Name);
            Assert.AreEqual(1, department.UserId);
        }
示例#12
0
        public async Task OpenAirClientGetUserByIdAsync_ShouldParseResult()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler
            {
                ResponseContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"><User><departmentid>2</departmentid><timezone>+0200</timezone><name>Doe, Jhon</name><id>100</id><addr><Address><salutation/><mobile/><state/><email>[email protected]</email><addr2/><city>City</city><fax/><contact_id/><addr1/><id>-1</id><middle/><country/><first>Jhon</first><last>Doe</last><phone/><addr4/><zip/><addr3/></Address></addr></User></Read ></response>"
            };

            var client = new OpenAirClient(() => handler, options);
            var user   = await client.GetUserByIdAsync(100);

            var content = Encoding.UTF8.GetString(handler.Content);

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>R</user><password>P</password></Login></Auth><Read type=\"User\" method=\"equal to\" limit=\"1\"><User><id>100</id></User><_Return><id /><name /><timezone/><addr /><departmentid /></_Return></Read></request>", content);
            Assert.AreEqual(100, user.Id);
            Assert.AreEqual("Doe, Jhon", user.Name);
            Assert.AreEqual(2, user.DepartmentId);
            Assert.AreEqual("*****@*****.**", user.Address.First().Email);
        }
示例#13
0
        public async Task OpenAirConnector_GetUnsubmittedTimesheetsForEndOfMonthAsync()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set(CreateTimesheetXmlContent(
                                   (UserId: 3, new DateOnly(2020, 03, 23), Status: 'S', Hours: 40)))
                          .Set(CreateTimesheetXmlContent(
                                   (UserId: 2, new DateOnly(2020, 03, 30), Status: 'A', Hours: 16),
                                   (UserId: 1, new DateOnly(2020, 03, 30), Status: 'S', Hours: 40),
                                   (UserId: 4, new DateOnly(2020, 03, 30), Status: 'A', Hours: 12),
                                   (UserId: 3, new DateOnly(2020, 03, 30), Status: 'S', Hours: 8)));

            var client         = new OpenAirClient(() => handler, options);
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);
            var user1          = CreateUser(1, "Test 1", "Q", "[email protected]");
            var user2          = CreateUser(2, "Test 2", "Q", "[email protected]");
            var user3          = CreateUser(3, "Test 3", "Q", "[email protected]");
            var user4          = CreateUser(4, "Test 4", "Q", "[email protected]");
            var date           = new DateTime(2020, 3, 31);

            var user4HourValue = new Functions.Models.Domains.Plugins.PluginPropertyValue
            {
                Key   = "Hour",
                Value = 30
            };

            user4.Properties = new Dictionary <string, Functions.Models.Domains.Plugins.PluginPropertyValue[][]>
            {
                { "OpenAir", new [] { new[] { user4HourValue } } }
            };

            storageService.GetAllActiveUsersAsync().ReturnsForAnyArgs(new[] { user1, user2, user3, user4 });

            // Act
            var timesheets = await connector.GetUnsubmittedTimesheetsAsync(date, date, TimesheetStates.Unsubmitted, "[email protected]", true, "Hour", null);

            Assert.AreEqual(1, timesheets.Count);
            Assert.AreEqual("Test 3", timesheets[0].UserName);
            Assert.AreEqual(8, timesheets[0].Total);
        }
示例#14
0
        public async Task OpenAirClientGetAllUsers_ShouldParseRecord()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var record  =
                "<User><departmentid>2</departmentid><name>Oniyide, Temitope</name><id>1623</id><active>1</active>" +
                "<user_locationid>3</user_locationid><line_managerid>317</line_managerid><addr><Address>" +
                "<email>[email protected]</email><first>Temitope</first><last>Oniyide</last></Address></addr>" +
                "<usr_start_date__c>2021-11-11</usr_start_date__c></User>";
            var handler = new MockHttpMessageHandler()
                          .Set($"<response><Auth status=\"0\"></Auth ><Read status=\"0\">{record}</Read ></response>");

            var client = new OpenAirClient(() => handler, options);

            var results = await client.GetAllUsersAsync();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(2, results.Single().DepartmentId);
            Assert.AreEqual(3, results.Single().LocationId);
            Assert.AreEqual(317, results.Single().ManagerId);
            Assert.AreEqual("*****@*****.**", results.Single().Address.Single().Email);
            Assert.AreEqual("11/11/2021 00:00", results.Single().StartDate.Value.ToString("g", CultureInfo.InvariantCulture));
        }
示例#15
0
        public async Task OpenAirClientGetTimesheets_ShouldParseResult()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth ><Read status=\"0\"><Timesheet><status>A</status><userid>722</userid><name>02/25/19 to 03/03/19 PTO</name><total>8.00</total><starts><Date><hour/><minute/><timezone/><second/><month>02</month><day>25</day><year>2019</year></Date></starts><notes>PTO</notes></Timesheet></Read ></response>");

            var client  = new OpenAirClient(() => handler, options);
            var date    = new DateTime(2000, 10, 10);
            var results = await client.GetTimesheetsAsync(date, date);

            var content = Encoding.UTF8.GetString(handler[0].RequestContent);

            Assert.AreEqual("<request API_version=\"1.0\" client=\"MM\" client_ver=\"1.0\" namespace=\"default\" key=\"K\"><Auth><Login><company>MM</company><user>R</user><password>P</password></Login></Auth><Read type=\"Timesheet\" filter=\"newer-than,older-than\" field=\"starts,starts\" method=\"all\" limit=\"0,1000\"><Date><month>10</month><day>10</day><year>2000</year></Date><Date><month>10</month><day>10</day><year>2000</year></Date><_Return><status/><name /><total/><notes /><userid /><starts /></_Return></Read></request>", content);
            Assert.AreEqual(1, results.Count);

            var first = results.First();

            Assert.AreEqual(722, first.UserId);
            Assert.AreEqual(2, first.StartDate.Date.Month);
            Assert.AreEqual(25, first.StartDate.Date.Day);
            Assert.AreEqual(2019, first.StartDate.Date.Year);
        }
示例#16
0
        public async Task OpenAirConnector_GetUnsubmittedTimesheetsShouldFilterNotStartedUsersAsync()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set(CreateTimesheetXmlContent(
                                   (UserId: 1, new DateOnly(2022, 1, 28), Status: 'S', Hours: 40),
                                   (UserId: 6, new DateOnly(2022, 1, 28), Status: 'S', Hours: 8)))
                          .Set(CreateTimesheetXmlContent(
                                   (UserId: 2, new DateOnly(2022, 1, 28), Status: 'A', Hours: 8),
                                   (UserId: 3, new DateOnly(2022, 1, 28), Status: 'A', Hours: 16),
                                   (UserId: 5, new DateOnly(2022, 1, 28), Status: 'A', Hours: 16)));

            var client         = new OpenAirClient(() => handler, options);
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);
            var user1          = CreateUser(1, "Test 1", "Q", "[email protected]");
            var user2          = CreateUser(2, "Test 2", "Q", "[email protected]");
            var user3          = CreateUser(3, "Test 3", "Q", "[email protected]", startDate: new DateTime(2022, 1, 27));
            var user4          = CreateUser(4, "Test 4", "Q", "[email protected]", startDate: new DateTime(2022, 1, 31));
            var user5          = CreateUser(5, "Test 5", "Q", "[email protected]", startDate: new DateTime(2022, 1, 25));
            var user6          = CreateUser(6, "Test 6", "Q", "[email protected]", startDate: new DateTime(2022, 1, 27));
            var date           = new DateTime(2022, 1, 28);

            user5.Properties = CreateUserHoursProperty(20);
            user6.Properties = CreateUserHoursProperty(40);
            storageService.GetAllActiveUsersAsync().ReturnsForAnyArgs(new[] { user1, user2, user3, user4, user5, user6 });

            // Act
            var timesheets = await connector.GetUnsubmittedTimesheetsAsync(date, date, TimesheetStates.Unsubmitted, "[email protected]", true, "Hour", null);

            Assert.AreEqual(2, timesheets.Count);
            Assert.AreEqual("Test 2", timesheets[0].UserName);
            Assert.AreEqual(40, timesheets[0].UtilizationInHours);
            Assert.AreEqual(8, timesheets[0].Total);
            Assert.AreEqual("Test 6", timesheets[1].UserName);
            Assert.AreEqual(16, timesheets[1].UtilizationInHours);
            Assert.AreEqual(8, timesheets[1].Total);
        }
        public async Task OpenAirConnector_GetUnsubmittedTimesheetsAsync()
        {
            var options = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var handler = new MockHttpMessageHandler()
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth><Read status=\"0\"><Timesheet><status>S</status><userid>3</userid><name></name><total>40.00</total><starts><Date><month>01</month><day>28</day><year>2019</year></Date></starts><notes></notes></Timesheet></Read ></response>")
                          .Set("<?xml version=\"1.0\" standalone=\"yes\"?><response><Auth status=\"0\"></Auth><Read status=\"0\"><Timesheet><status>A</status><userid>2</userid><name>A</name><total>30.00</total><starts><Date><month>02</month><day>28</day><year>2019</year></Date></starts><notes>PTO</notes></Timesheet></Read ></response>");

            var client         = new OpenAirClient(() => handler, options);
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);
            var user           = CreateUser(2, "Test", "Q", "[email protected]");
            var date           = new DateTime(2019, 2, 1);

            storageService.GetAllActiveUsersAsync().ReturnsForAnyArgs(new[] { user });

            // Act
            var timesheets = await connector.GetUnsubmittedTimesheetsAsync(date, TimesheetStates.Unsubmitted, "[email protected]", null);

            Assert.AreEqual(1, timesheets.Count);
            Assert.AreEqual("Test", timesheets[0].UserName);
            Assert.AreEqual("A", timesheets[0].Name);
            Assert.AreEqual("Q", timesheets[0].DepartmentName);
            Assert.AreEqual(30, timesheets[0].Total);
        }
示例#18
0
        public async Task OpenAirShouldSyncUsersAndReturnNamesToLower()
        {
            var user1 = new OpenAirClient.User
            {
                Id           = 1000,
                Name         = "A",
                DepartmentId = 2000,
                Active       = true,
                Address      = new[]
                {
                    new OpenAirClient.Address {
                        Email = "*****@*****.**"
                    }
                },
                ManagerId = 1010
            };
            var user2 = new OpenAirClient.User
            {
                Id           = 1010,
                Name         = "B",
                DepartmentId = 2000,
                Active       = true,
                Address      = new[]
                {
                    new OpenAirClient.Address {
                        Email = "*****@*****.**"
                    }
                }
            };
            var dep = new OpenAirClient.Department
            {
                Id     = 2000,
                Name   = "QA",
                UserId = 1010
            };
            var customer = new OpenAirClient.Customer
            {
                Id   = 3000,
                Name = "MM"
            };
            var booking = new OpenAirClient.Booking
            {
                Id         = 4000,
                UserId     = 1000,
                CustomerId = 3000,
                ProjectId  = 6000,
                OwnerId    = 1010
            };
            var client = Substitute.For <IOpenAirClient>();

            client.GetAllUsersAsync().Returns(new[] { user1, user2 });
            client.GetAllDepartmentsAsync().Returns(new[] { dep });
            client.GetAllActiveCustomersAsync().Returns(new[] { customer });
            client.GetAllActiveBookingsAsync(DateTime.MinValue).ReturnsForAnyArgs(new[] { booking });

            var options        = new OpenAirOptions("http://localhost/", "MM", "K", "R", "P");
            var storageService = Substitute.For <IStorageService>();
            var connector      = new OpenAirConnector(client, storageService);

            storageService
            .GetAllUsersAsync()
            .ReturnsForAnyArgs(new[]
            {
                CreateUser(1000, "A", ".NET", "*****@*****.**", 1),
                CreateUser(1011, "B", ".NET", "*****@*****.**", 2)
            });

            // Act
            await connector.SyncUsersAsync();

            storageService
            .Received()
            .UpdateUsersAsync(Arg.Is <IReadOnlyList <User> >(it =>
                                                             it.All(user => user.Email == user.Email.ToLower())));
        }
 /// <summary>Initializes a new instance of the <see cref="OpenAirClient"/> class.</summary>
 public OpenAirClient(OpenAirOptions options)
     : this(() => new HttpClientHandler(), options)
 {
 }
 /// <summary>Initializes a new instance of the <see cref="OpenAirClient"/> class.</summary>
 public OpenAirClient(Func <HttpMessageHandler> messageHandlerFactory, OpenAirOptions options)
 {
     _messageHandlerFactory = messageHandlerFactory;
     _options = options;
 }