Exemplo n.º 1
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")));
        }
Exemplo n.º 2
0
 /// <summary>Creates a <see cref="Department"/> model.</summary>
 public static Department CreateDepartment(OpenAirClient.Department department, OpenAirClient.User[] users) =>
 department == null ? null :
 new Department
 {
     OpenAirDepartmentId = department.Id,
     Name  = department.Name,
     Owner = CreateUserReferenceById(department.UserId, users)
 };
Exemplo n.º 3
0
 private static Department CreateDepartment(OpenAirClient.Department department)
 {
     return(new Department
     {
         OpenAirDepartmentId = department.Id,
         Name = department.Name
     });
 }
Exemplo n.º 4
0
        public void OpenAirClientDepartment_ShouldBeSet()
        {
            var dep = new OpenAirClient.Department {
                UserIdAsText = "200", Name = "B"
            };

            Assert.AreEqual(200, dep.UserId);
            Assert.AreEqual("B", dep.Name);
        }
Exemplo n.º 5
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())));
        }