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