Exemple #1
0
        public async Task TestGetTopicListAsyncMultiPage()
        {
            var responses = new[]
            {
                new ListTopicsResponse
                {
                    NextPageToken = "Token",
                    Topics        = new List <Topic> {
                        new Topic {
                            Name = FirstName
                        }
                    }
                },
                new ListTopicsResponse
                {
                    Topics = new List <Topic> {
                        new Topic {
                            Name = SecondName
                        }
                    }
                }
            };
            PubsubService service = GetMockedService(
                (PubsubService s) => s.Projects,
                p => p.Topics,
                t => t.List(It.IsAny <string>()),
                responses);

            var           sourceUnderTest = new PubsubDataSource(service, ProjectName);
            IList <Topic> topics          = await sourceUnderTest.GetTopicListAsync();

            Assert.AreEqual(2, topics.Count);
            Assert.AreEqual(FirstName, topics[0].Name);
            Assert.AreEqual(SecondName, topics[1].Name);
            var topicsMock = Mock.Get(service.Projects.Topics);

            topicsMock.Verify(t => t.List(ProjectResourceName), Times.AtLeastOnce);
            topicsMock.Verify(t => t.List(It.IsNotIn(ProjectResourceName)), Times.Never);
        }
Exemple #2
0
        public async Task TestGetTopicListAsyncException()
        {
            var           responses = new ListTopicsResponse[0];
            PubsubService service   = GetMockedService(
                (PubsubService s) => s.Projects,
                p => p.Topics,
                t => t.List(It.IsAny <string>()),
                responses);
            var sourceUnderTest = new PubsubDataSource(service, ProjectName);

            try
            {
                await sourceUnderTest.GetTopicListAsync();

                Assert.Fail();
            }
            finally
            {
                var topicsMock = Mock.Get(service.Projects.Topics);
                topicsMock.Verify(t => t.List(ProjectResourceName), Times.AtLeastOnce);
                topicsMock.Verify(t => t.List(It.IsNotIn(ProjectResourceName)), Times.Never);
            }
        }