private static bool UserNeedUpdate(User storedUser, OpenAirClient.User openAirUser, UserReference manager, Department department, Customer[] openAirCustomers) => storedUser.Active != openAirUser.Active || storedUser.Department?.OpenAirDepartmentId != openAirUser.DepartmentId || storedUser.Department?.Owner?.OpenAirUserId != department?.Owner?.OpenAirUserId || storedUser.Manager?.OpenAirUserId != manager?.OpenAirUserId || storedUser.Customers?.Length != openAirCustomers.Length || openAirCustomers.Any(it => !storedUser.Customers.Contains(it));
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 void OpenAirClientUser_ShouldBeSet() { var user = new OpenAirClient.User { IdAsText = "3", ManagerIdAsText = "4", DepartmentIdAsText = "5", ActiveAsText = "1", LocationIdAsText = "6" }; Assert.AreEqual(3, user.Id); Assert.AreEqual(4, user.ManagerId); Assert.AreEqual(5, user.DepartmentId); Assert.AreEqual(6, user.LocationId); Assert.IsTrue(user.Active.Value); }
private static User CreateUser(OpenAirClient.User user) { return(new User { OpenAirUserId = user.Id, Name = user.Name, Email = user.Address.FirstOrDefault()?.Email, Department = new Department { OpenAirDepartmentId = user.DepartmentId } }); }
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()))); }