public async Task Should_Distribute_Push_Request()
        {
            //Arrange
            var guid = _generator.Create();

            _store.GetRequestOrNullAsync(Arg.Any <Guid>()).ReturnsForAnyArgs(CreatePushRequest());
            _store.GetSubscriptionsAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .ReturnsForAnyArgs(new List <PushRequestSubscription> {
                CreatePushRequestSubscription()
            });

            //Act
            await _distributor.DistributeAsync(guid);

            //Assert
            await _store.Received().GetRequestOrNullAsync(Arg.Any <Guid>());

            await _store.Received().DeleteRequestAsync(Arg.Is <Guid>(n => n.Equals(guid)));
        }
Ejemplo n.º 2
0
        public virtual async Task DistributeAsync(Guid pushRequestId)
        {
            PushRequest pushRequest = null;

            // set tenantId = null, because push request only store in host side
            using (UnitOfWorkManager.Current.SetTenantId(null))
            {
                pushRequest = await RequestStore.GetRequestOrNullAsync(pushRequestId);

                if (pushRequest == null)
                {
                    Logger.WarnFormat("PushRequestDistributionJob can not continue since could not found push request by id: {0} ", pushRequestId);
                    return;
                }
            }

            // TODO: change GetUsers() to GetDevices()
            var users = await GetUsers(pushRequest);

            if (users.IsNullOrEmpty())
            {
                Logger.WarnFormat("Push Request with id: {0} does not have any target user", pushRequest.Id);
            }

            try
            {
                foreach (var providerInfo in Configuration.ServiceProviders)
                {
                    // TODO: allow PushRequest to store target providers
                    using (var provider = CreateProvider(providerInfo.Name))
                    {
                        await provider.Object.PushAsync(users, pushRequest);
                    }
                }

                await RequestStore.DeleteRequestAsync(pushRequest.Id);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
            }
        }