public void TestLoop()
 {
     var options = new BookDetailLookup.Options();
     options.SubscriptionName += "-test";
     options.TopicName += "-test";
     BookDetailLookup bookDetailLookup =
         new BookDetailLookup(_projectId, new LoggerFactory(), options);
     bookDetailLookup.CreateTopicAndSubscription();
     var cancel = new CancellationTokenSource();
     var pullTask = bookDetailLookup.StartPullLoop(new FakeBookStore(), cancel.Token);
     cancel.CancelAfter(100);
     pullTask.Wait();
 }
 public static void AddBookDetailLookup(this IServiceCollection services, string projectId,
     Action<BookDetailLookup.Options> optionSetter = null)
 {
     services.AddSingleton<BookDetailLookup>(provider =>
     {
         var options = new BookDetailLookup.Options();
         if (optionSetter != null) optionSetter(options);
         var bookDetailLookup = new BookDetailLookup(
             projectId, provider.GetService<ILoggerFactory>(), options);
         bookDetailLookup.CreateTopicAndSubscription();
         return bookDetailLookup;
     });
 }
 public void TestPubsub()
 {
     var options = new BookDetailLookup.Options();
     options.SubscriptionName += "-test";
     options.TopicName += "-test";
     BookDetailLookup bookDetailLookup =
         new BookDetailLookup(_projectId, new LoggerFactory(), options);
     bookDetailLookup.CreateTopicAndSubscription();
     bookDetailLookup.EnqueueBook(45);
     var cancel = new CancellationTokenSource();
     var pullTask = Task.Factory.StartNew(() => bookDetailLookup.PullLoop((long bookId) =>
     {
         Assert.Equal(45, bookId);
         cancel.Cancel();
     }, cancel.Token));
     pullTask.Wait();
 }