public async Task SynchronizeBricksetPrimaryUsersSets(string username = null)
        {
            _messageHub.Publish(new UserSynchronizationServiceStart {
                UserType = BricksetUserType.Primary
            });

            try
            {
                var apiKey = await _onboardingService.GetBricksetApiKey();

                if (string.IsNullOrWhiteSpace(apiKey))
                {
                    return;
                }

                if (string.IsNullOrWhiteSpace(username))
                {
                    var tasks = new List <Task>();

                    _bricksetUserRepository
                    .GetAllUsernames(BricksetUserType.Primary)
                    .ToList()
                    .ForEach(bricksetUsername => tasks.Add(SynchronizeBricksetPrimaryUser(apiKey, bricksetUsername)));

                    _messageHub.Publish(new UsersAcquired {
                        UserType = BricksetUserType.Primary, Count = tasks.Count
                    });

                    await Task.WhenAll(tasks);
                }
                else if (_bricksetUserRepository.Exists(username))
                {
                    _messageHub.Publish(new UsersAcquired {
                        UserType = BricksetUserType.Primary, Count = 1
                    });

                    await SynchronizeBricksetPrimaryUser(apiKey, username);
                }
                else
                {
                    throw new ArgumentException("Parameter was not found the list of primary users", nameof(username));
                }
            }
            catch (AggregateException aggEx)
            {
                _messageHub.Publish(new UserSynchronizationServiceException {
                    UserType = BricksetUserType.Primary, Exceptions = aggEx.InnerExceptions
                });
            }
            catch (Exception ex)
            {
                _messageHub.Publish(new UserSynchronizationServiceException {
                    UserType = BricksetUserType.Primary, Exceptions = new[] { ex }
                });
            }

            _messageHub.Publish(new UserSynchronizationServiceEnd {
                UserType = BricksetUserType.Primary
            });
        }
Exemplo n.º 2
0
        public void GetAllUsernames_BricksetUserTypeDoesNotExist_ReturnsEmptyList()
        {
            var bricksetUser = ModelsSetup.GetBricksetUserUnderTest();

            InsertData(bricksetUser);

            var usernameList = _bricksetUserRepository.GetAllUsernames(BricksetUserType.Friend);

            Check.That(usernameList).IsEmpty();
        }