Example #1
0
        public async Task RunAsync_ShouldSaveInDb()
        {
            var documentClientService = Substitute.For <IDocumentClientService>();
            var document            = Substitute.For <IDocument <Message> >();
            var hangoutsChatService = Substitute.For <IHangoutsChatService>();
            var options             = new GoogleCloudOptions("AAA", "B", "C", "D");
            var logger         = Substitute.For <Microsoft.Extensions.Logging.ILogger>();
            var requestMessage = new HttpRequestMessage {
                Content = new StringContent(FullMsg)
            };
            var message = new Message();

            ServiceLocator.DefaultInstance.BuildServiceProviderWithDescriptors(
                new ServiceDescriptor(typeof(IDocumentClientService), documentClientService),
                new ServiceDescriptor(typeof(IHangoutsChatService), hangoutsChatService),
                new ServiceDescriptor(typeof(GoogleCloudOptions), options));

            documentClientService.IsConnected.Returns(true);
            documentClientService.Get <Message>("mentorbot", "messages").Returns(document);
            hangoutsChatService.BasicAsync(null).ReturnsForAnyArgs(message);

            await HangoutChatEvent.RunAsync(requestMessage, logger);

            document.Received().AddAsync(message);
        }
Example #2
0
        public async Task RunAsync_ShouldCallService()
        {
            var documentClientService = Substitute.For <IDocumentClientService>();
            var document            = Substitute.For <IDocument <Message> >();
            var hangoutsChatService = Substitute.For <IHangoutsChatService>();
            var options             = new GoogleCloudOptions("AAA", "B", "C", "D");
            var logger         = Substitute.For <Microsoft.Extensions.Logging.ILogger>();
            var requestMessage = new HttpRequestMessage {
                Content = new StringContent(FullMsg)
            };
            var message = new Message {
                Output = new ChatEventResult("OK")
            };

            ServiceLocator.DefaultInstance.BuildServiceProviderWithDescriptors(
                new ServiceDescriptor(typeof(IDocumentClientService), documentClientService),
                new ServiceDescriptor(typeof(IHangoutsChatService), hangoutsChatService),
                new ServiceDescriptor(typeof(GoogleCloudOptions), options));

            hangoutsChatService
            .BasicAsync(Arg.Is <ChatEvent>(it =>
                                           it.Message.Text == "What is this?" &&
                                           it.Message.Name == "spaces/q/messages/y"))
            .Returns(message);

            var result = await HangoutChatEvent.RunAsync(requestMessage, logger);

            var resultOutput = (result as JsonResult).Value as ChatEventResult;

            Assert.AreEqual(resultOutput.Text, "OK");
        }
Example #3
0
#pragma warning restore CS4014

        private FunctionContext BuildTestCase()
        {
            var storageService      = Substitute.For <IStorageService>();
            var hangoutsChatService = Substitute.For <IHangoutsChatService>();
            var options             = new GoogleCloudOptions("AAA", "B", "C", "D");
            var context             = MockFunction.GetContext(
                new ServiceDescriptor(typeof(IStorageService), storageService),
                new ServiceDescriptor(typeof(IHangoutsChatService), hangoutsChatService),
                new ServiceDescriptor(typeof(GoogleCloudOptions), options));

            return(context);
        }
        private static HangoutsChatService CreateService(GoogleCloudOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(new HangoutsChatService(
                       new BaseClientService.Initializer
            {
                ApplicationName = options.GoogleCloudApplicationName,
                ApiKey = options.GoogleCloudApiKey
            }));
        }
Example #5
0
        public void CreateInitializer_InitsByApiKay()
        {
            var configuration = Substitute.For <IConfiguration>();

            configuration["GoogleCloudApiKey"].Returns("ABC");
            configuration["GoogleCloudApplicationName"].Returns("EFG");

            var options = new GoogleCloudOptions(configuration);

            var result = GoogleBaseService <BaseClientService> .InitByKey(options);

            Assert.AreEqual("ABC", result.ApiKey);
            Assert.AreEqual("EFG", result.ApplicationName);
        }
Example #6
0
#pragma warning restore CS4014

        private void BuildTestCase(string requestContent, out ILogger logger, out HttpRequestMessage requestMessage)
        {
            var storageService      = Substitute.For <IStorageService>();
            var hangoutsChatService = Substitute.For <IHangoutsChatService>();
            var options             = new GoogleCloudOptions("AAA", "B", "C", "D");

            ServiceLocator.DefaultInstance.BuildServiceProviderWithDescriptors(
                new ServiceDescriptor(typeof(IStorageService), storageService),
                new ServiceDescriptor(typeof(IHangoutsChatService), hangoutsChatService),
                new ServiceDescriptor(typeof(GoogleCloudOptions), options));

            logger         = Substitute.For <Microsoft.Extensions.Logging.ILogger>();
            requestMessage = new HttpRequestMessage {
                Content = new StringContent(requestContent)
            };
        }
Example #7
0
        public async Task RunAsync_ShouldCheckToken()
        {
            var documentClientService = Substitute.For <IDocumentClientService>();
            var document            = Substitute.For <IDocument <Message> >();
            var hangoutsChatService = Substitute.For <IHangoutsChatService>();
            var options             = new GoogleCloudOptions("А", "B", "C", "D");
            var logger  = Substitute.For <Microsoft.Extensions.Logging.ILogger>();
            var message = new HttpRequestMessage {
                Content = new StringContent(EmptyMsg)
            };

            ServiceLocator.DefaultInstance.BuildServiceProviderWithDescriptors(
                new ServiceDescriptor(typeof(IDocumentClientService), documentClientService),
                new ServiceDescriptor(typeof(IHangoutsChatService), hangoutsChatService),
                new ServiceDescriptor(typeof(GoogleCloudOptions), options));

            var result = await HangoutChatEvent.RunAsync(message, logger);

            Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));
        }
 /// <summary>Initializes a new instance of the <see cref="GoogleServiceAccountCredential"/> class.</summary>
 public GoogleServiceAccountCredential(GoogleCloudOptions options, IBlobStorageConnector storageConnector)
 {
     _storageConnector = storageConnector;
     _options          = options;
 }
 /// <summary>Creates the base client service initializer by api key.</summary>
 public static BaseClientService.Initializer InitByKey(GoogleCloudOptions options) =>
 new BaseClientService.Initializer
 {
     ApplicationName = options.GoogleCloudApplicationName,
     ApiKey          = options.GoogleCloudApiKey
 };
 /// <summary>Initializes a new instance of the <see cref="HangoutsChatConnector"/> class.</summary>
 public HangoutsChatConnector(GoogleCloudOptions options)
     : this(new Lazy <HangoutsChatService>(() => CreateService(options)))
 {
 }
 public void TestInitialize()
 {
     _options           = new GoogleCloudOptions(null, "ABC", null, "QZ/XY");
     _storageConnector  = Substitute.For <IBlobStorageConnector>();
     _accountCredential = new GoogleServiceAccountCredential(_options, _storageConnector);
 }