Esempio n. 1
0
        public async Task TestNewTopicAsyncSuccess()
        {
            var responses = new[] { new Topic {
                                        Name = MockedTopicName
                                    } };
            PubsubService service = GetMockedService(
                (PubsubService s) => s.Projects,
                p => p.Topics,
                t => t.Create(It.IsAny <Topic>(), It.IsAny <string>()),
                responses);
            var sourceUnderTest = new PubsubDataSource(service, ProjectName);

            var topic = await sourceUnderTest.NewTopicAsync(TopicName);

            Assert.AreEqual(MockedTopicName, topic.Name);
            var topicMock = Mock.Get(service.Projects.Topics);

            topicMock.Verify(t => t.Create(It.IsAny <Topic>(), TopicFullName), Times.Once);
            topicMock.Verify(t => t.Create(It.IsAny <Topic>(), It.IsNotIn(TopicFullName)), Times.Never);
        }
Esempio n. 2
0
        public async Task TestNewTopicAsyncException()
        {
            var           responses = new Topic[0];
            PubsubService service   = GetMockedService(
                (PubsubService s) => s.Projects,
                p => p.Topics,
                t => t.Create(It.IsAny <Topic>(), It.IsAny <string>()),
                responses);
            var sourceUnderTest = new PubsubDataSource(service, ProjectName);

            try
            {
                await sourceUnderTest.NewTopicAsync(TopicName);

                Assert.Fail();
            }
            finally
            {
                var topicMock = Mock.Get(service.Projects.Topics);
                topicMock.Verify(t => t.Create(It.IsAny <Topic>(), TopicFullName), Times.Once);
                topicMock.Verify(t => t.Create(It.IsAny <Topic>(), It.IsNotIn(TopicFullName)), Times.Never);
            }
        }