예제 #1
0
        ///<inheritdoc/>
        public async Task SynchronizeForAddingPeopleAsync()
        {
            _logger.LogInformation(PeopleSynchronizationService.StartSynchronizationForAdditionPeople);

            var cloudPeople = await _cloudManager.GetUsers().ToListAsync();

            var applicationPeople = (await _personManager.GetPeopleWithoutTrackingAsync()).ToList();

            var cloudPeopleIds       = cloudPeople.Select(p => p.Id).ToList();
            var applicationPeopleIds = applicationPeople.Select(p => p.CloudId).ToList();

            var idsForSync = cloudPeopleIds.Except(applicationPeopleIds);

            var peopleForSync = cloudPeople.Join(idsForSync,    //Join method selects persons which exists in the cloud but not exists in the application.
                                                 cloudPerson => cloudPerson.Id,
                                                 newId => newId,
                                                 (cloudPerson, newId) => cloudPerson); // return a new selection consisting of persons(=> cloudPerson) in which cloudPerson.Id matches newId(idsForSync).

            if (peopleForSync.Any())
            {
                foreach (var user in peopleForSync)
                {
                    var personDto = new PersonDto
                    {
                        CloudId = user.Id,
                        Name    = user.Name,
                        Email   = user.Email
                    };

                    await _personManager.CreatePersonAsync(personDto);
                }
            }

            _logger.LogInformation(PeopleSynchronizationService.EndSynchronizationForAdditionPeople);
        }
        public void GetUsers_WhenEmptyContext_ReturnsEmptyList()
        {
            // Arrange
            var usersCount = _cloudDbContext.Users.Count();

            // Act
            var users = _cloudManager.GetUsers().ToList();

            // Assert
            Assert.Empty(users);
            Assert.Equal(users.Count, usersCount);
        }
        /// <inheritdoc/>
        public async Task AddAsync()
        {
            _logger.LogInformation(SyncMessage.PersonAddStart);

            var peopleCloud = await _cloudManager.GetUsers().ToListAsync();

            var peopleApp = (await _personManager.GetAllAsync()).ToList();

            var peopleCloudIds = peopleCloud.Select(p => p.Id);
            var peopleAppIds   = peopleApp.Select(p => p.CloudId);

            var newIds = peopleCloudIds.Except(peopleAppIds);

            var people = peopleCloud.Join(
                newIds,
                personCloud => personCloud.Id,
                id => id,
                (personCloud, id) => personCloud);

            if (people.Any())
            {
                foreach (var user in people)
                {
                    var personDto = new PersonDto
                    {
                        CloudId = user.Id,
                        Name    = user.Name,
                        Email   = user.Email
                    };

                    await _personManager.CreateAsync(personDto);
                }
            }

            _logger.LogInformation(SyncMessage.PersonAddEnd);
        }