public void CreateClient_Works()
        {
            var factory = new ProxyHttpClientFactory(Mock <ILogger <ProxyHttpClientFactory> >().Object);

            var actual1 = factory.CreateClient(new ProxyHttpClientContext());
            var actual2 = factory.CreateClient(new ProxyHttpClientContext());

            Assert.NotNull(actual1);
            Assert.NotNull(actual2);
            Assert.NotSame(actual2, actual1);
        }
示例#2
0
        public void CreateUpgradableClient_Works()
        {
            // Arrange
            var factory = new ProxyHttpClientFactory();

            // Act
            var actual1 = factory.CreateUpgradableClient();
            var actual2 = factory.CreateUpgradableClient();

            // Assert
            Assert.NotNull(actual1);
            Assert.NotNull(actual2);
            Assert.NotSame(actual2, actual1);
        }
示例#3
0
        public void CreateUpgradableClient_Works()
        {
            // Arrange
            var factory = new ProxyHttpClientFactory();

            // Act
            var actual1 = factory.CreateUpgradableClient();
            var actual2 = factory.CreateUpgradableClient();

            // Assert
            actual1.Should().NotBeNull();
            actual2.Should().NotBeNull();
            actual1.Should().NotBeSameAs(actual2);
        }
示例#4
0
        public void CreateClient_ApplyDangerousAcceptAnyServerCertificate_Success()
        {
            var factory = new ProxyHttpClientFactory(Mock <ILogger <ProxyHttpClientFactory> >().Object);
            var options = new ProxyHttpClientOptions {
                DangerousAcceptAnyServerCertificate = true
            };
            var client = factory.CreateClient(new ProxyHttpClientContext {
                NewOptions = options
            });

            var handler = GetHandler(client);

            Assert.NotNull(handler);
            Assert.NotNull(handler.SslOptions.RemoteCertificateValidationCallback);
            Assert.True(handler.SslOptions.RemoteCertificateValidationCallback(default, default, default, default));
示例#5
0
        public void SendFcmMessageUsingProxyTest()
        {
            // This needs to be a valid Service Account Credentials File. Can't mock it away:
            var settings = FileBasedFcmClientSettings.CreateFromFile("your_project_id", @"D:\serviceAccountKey.json");

            // Define the Proxy URI to be used:
            var proxy = new Uri("http://localhost:8888");

            // Define the Username and Password ("1", because I am using Fiddler for Testing):
            var credentials = new NetworkCredential("1", "1");

            // Build the HTTP Client Factory:
            var httpClientFactory = new ProxyHttpClientFactory(proxy, credentials);

            // Initialize a new FcmHttpClient to send to localhost:
            var fcmHttpClient = new FcmHttpClient(settings, httpClientFactory);

            // Construct the Firebase Client:
            using (var client = new FcmClient(settings, fcmHttpClient))
            {
                // Construct the Notification Payload to send:
                var notification = new Notification
                {
                    Title = "Title Text",
                    Body  = "Notification Body Text"
                };

                // The Message should be sent to the News Topic:
                var message = new FcmMessage()
                {
                    ValidateOnly = false,
                    Message      = new Message
                    {
                        Topic        = "news",
                        Notification = notification
                    }
                };

                // Finally send the Message and wait for the Result:
                CancellationTokenSource cts = new CancellationTokenSource();

                // Send the Message and wait synchronously:
                var result = client.SendAsync(message, cts.Token).GetAwaiter().GetResult();

                Console.WriteLine(result);
            }
        }
示例#6
0
        public void CreateClient_ApplySslProtocols_Success()
        {
            var factory = new ProxyHttpClientFactory(Mock <ILogger <ProxyHttpClientFactory> >().Object);
            var options = new ProxyHttpClientOptions
            {
                SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13,
            };
            var client = factory.CreateClient(new ProxyHttpClientContext {
                NewOptions = options
            });

            var handler = GetHandler(client);

            Assert.NotNull(handler);
            Assert.Equal(SslProtocols.Tls12 | SslProtocols.Tls13, handler.SslOptions.EnabledSslProtocols);
            VerifyDefaultValues(handler, "SslProtocols");
        }
 public void CreateClient_ApplySslProtocols_Success()
 {
     var factory = new ProxyHttpClientFactory(Mock <ILogger <ProxyHttpClientFactory> >().Object);
     var options = new ClusterProxyHttpClientOptions(SslProtocols.Tls12 | SslProtocols.Tls13, default, default, default);
 public UdmApiFactory()
 {
     ProxyHttpClientFactory.Create(Arg.Any <bool>()).Returns(UdmServerHttpClient);
 }