예제 #1
0
        public async Task ServerSendPrimaryRangetoFindNumbers_ExpectPrimaryArray(int beginNo, int count, int[] primes, int[] expected)
        {
            //arrange
            _factory.CreateClient().Should().NotBeNull();
            var server = _factory.Server;

            //arrange client
            Func <string, Uri>   uriBuilder        = endpoint => new Uri($"ws://localhost{endpoint}");
            Func <HubConnection> hubConnectionFact = () => new HubConnectionBuilder()
                                                     .WithAutomaticReconnect()
                                                     .WithUrl(uriBuilder(HubConnectionConst.PrimesNoEndpoint),
                                                              async options =>
            {
                options.HttpMessageHandlerFactory = _ => server.CreateHandler();
            })
                                                     .Build();
            var primeHubConnection = new PrimeHubConnectionClient(hubConnectionFact, new EventAggregator(),
                                                                  new Logger <PrimeHubConnectionClient>(new LoggerFactory()));

            //arrange server
            Func <PrimeNumbersPersistance> primeNumberFactoryFunc = () => new PrimeNumbersPersistance(beginNo, count, primes);
            var primeNumberService = ActivatorUtilities.CreateInstance <PrimeNumberBackgroundService>(server.Services, primeNumberFactoryFunc);
            await primeHubConnection.StartAsync();

            //act
            await primeHubConnection.RegisterUserIdAsync(Guid.NewGuid().ToString()).ConfigureAwait(false);

            await Task.Delay(100);

            //assert
            primeNumberService.PrimeNumbersPersist.PrimeNumbersArr.Should().BeEquivalentTo(expected);
        }
예제 #2
0
 protected override async Task OnInitializedAsync()
 {
     EventAggregator.SubscribeOnPublishedThread(this);
     await PrimeHubConnectionClient.RegisterUserIdAsync(Guid.NewGuid().ToString());
 }