public void AddingSpCharsInUserAgent()
        {
            string sampleProd    = "SampleProdName";
            string newSampleProd = "NewSampleProdName";
            string spChars       = "*()!@#$%^&";
            string sampleVersion = "1.*.0.*";

            string concatProdName  = string.Concat(sampleProd, spChars);
            string cleanedProdName = string.Concat(sampleProd, ".");

            FakeServiceClient fakeClient = new FakeServiceClient(new FakeHttpHandler());

            fakeClient.SetUserAgent(concatProdName);
            HttpHeaderValueCollection <ProductInfoHeaderValue> userAgentValueCollection = fakeClient.HttpClient.DefaultRequestHeaders.UserAgent;

            Assert.Equal(5, userAgentValueCollection.Count);

            var retrievedProdInfo = userAgentValueCollection.Where <ProductInfoHeaderValue>((p) => p.Product.Name.Equals(cleanedProdName)).FirstOrDefault <ProductInfoHeaderValue>();

            Assert.Equal(retrievedProdInfo?.Product?.Name, cleanedProdName);

            fakeClient.SetUserAgent(newSampleProd, sampleVersion);
            HttpHeaderValueCollection <ProductInfoHeaderValue> userAgentVersion = fakeClient.HttpClient.DefaultRequestHeaders.UserAgent;
            var retrievedVersion = userAgentVersion.Where <ProductInfoHeaderValue>((p) => p.Product.Name.Equals(newSampleProd)).FirstOrDefault <ProductInfoHeaderValue>();

            Assert.Equal(retrievedVersion?.Product?.Version, "1.0.");
        }
        public void AddDuplicateUserAgentInfo()
        {
            // FullNetFx -- Default (3) + 1 (TestClient) + 1 added below = 5
            string defaultProductName = "FxVersion";
            string testProductName    = "TestProduct";
            string testProductVersion = "1.0.0.0";

            FakeServiceClient fakeClient = new FakeServiceClient(new FakeHttpHandler());

            fakeClient.SetUserAgent(testProductName, testProductVersion);

            Assert.Equal(5, fakeClient.HttpClient.DefaultRequestHeaders.UserAgent.Count);
            fakeClient.SetUserAgent(testProductName, testProductVersion);
            Assert.Equal(5, fakeClient.HttpClient.DefaultRequestHeaders.UserAgent.Count);
        }
        public void VerifyDifferentUserAgentStrings()
        {
            Dictionary <string, string> spChars = new Dictionary <string, string>()
            {
                { "p1", @"Linux4.4.0-93-generic11614.04.1-UbuntuSMPMonAug1416:07:05UTC2017" },
                { "p2", @"Linux4.4.0-93-generic;11614" },
                { "p3", @"Linux4.4.0-93-generic=11614" },
                { "p4", @"©Linux4" },
                { "p5", @"Linux4    generic" },
                { "p6", @"Linux4 " +
                  "generic" },
                { "p7", @"Linux4\r\ngeneric" },
                { "p8", @"Linux4\rgeneric" },
                { "p9", @"Linux4\ngeneric" },
                { "p10", @"Linux4\generic" },
                { "p11", @"Darwin17.7.0DarwinKernelVersion17.7.0ThuJun21225314PDT2018rootxnu-4570.71.21/RELEASE_X86_64" }
            };

            FakeServiceClient fakeClient = new FakeServiceClient(new FakeHttpHandler());

            foreach (KeyValuePair <string, string> kv in spChars)
            {
                fakeClient.SetUserAgent(kv.Key, kv.Value);
            }

            // If we get an exception, meaning user agent string is not compatible.
        }
Esempio n. 4
0
        public void AddUserAgentInfoWithVersion()
        {
            string  defaultProductName = "FxVersion";
            string  testProductName = "TestProduct";
            string  testProductVersion = "1.0.0.0";
            Version defaultProductVer, testProductVer;

            FakeServiceClient fakeClient = new FakeServiceClient(new FakeHttpHandler());

            fakeClient.SetUserAgent(testProductName, testProductVersion);
            HttpResponseMessage response = fakeClient.DoStuffSync();
            HttpHeaderValueCollection <ProductInfoHeaderValue> userAgentValueCollection = fakeClient.HttpClient.DefaultRequestHeaders.UserAgent;

            var defaultProduct = userAgentValueCollection.Where <ProductInfoHeaderValue>((p) => p.Product.Name.Equals(defaultProductName)).FirstOrDefault <ProductInfoHeaderValue>();
            var testProduct    = userAgentValueCollection.Where <ProductInfoHeaderValue>((p) => p.Product.Name.Equals(testProductName)).FirstOrDefault <ProductInfoHeaderValue>();

            Version.TryParse(defaultProduct.Product.Version, out defaultProductVer);
            Version.TryParse(testProduct.Product.Version, out testProductVer);

            Assert.True(defaultProduct.Product.Name.Equals(defaultProductName));
            Assert.NotNull(defaultProductVer);

            Assert.True(testProduct.Product.Name.Equals(testProductName));
            Assert.True(testProduct.Product.Version.Equals(testProductVersion));
        }
        public void ClientEmptyProductHeaderValuesTest()
        {
            var fakeClient = new FakeServiceClient(new HttpClientHandler(), new BadResponseDelegatingHandler());

            fakeClient.SetUserAgent("MySpecialHeader", string.Empty);
            var arr = fakeClient.HttpClient.DefaultRequestHeaders.UserAgent.Where(pihv => (pihv.Product.Name == "MySpecialHeader")).ToArray();

            Assert.Empty(arr);
        }
        private async Task <FakeServiceClient> CreateClient(HttpClient hc, string userAgentProdName, string userAgentProdVersion, ManualResetEvent resetEvent)
        {
//            resetEvent.WaitOne();
            return(await Task.Run <FakeServiceClient>(() =>
            {
                FakeServiceClient fakeClient = new FakeServiceClient(hc);
                fakeClient.SetUserAgent(userAgentProdName, userAgentProdVersion);
                return fakeClient;
            }));
        }
Esempio n. 7
0
        public void AddUserAgentInfoWithVersion()
        {
            string defaultProductName = "FxVersion";
            string testProductName = "TestProduct";
            string testProductVersion = "1.0.0.0";
            Version defaultProductVer, testProductVer;

            FakeServiceClient fakeClient = new FakeServiceClient(new FakeHttpHandler());
            fakeClient.SetUserAgent(testProductName, testProductVersion);
            HttpResponseMessage response = fakeClient.DoStuffSync();
            HttpHeaderValueCollection<ProductInfoHeaderValue> userAgentValueCollection = fakeClient.HttpClient.DefaultRequestHeaders.UserAgent;

            var defaultProduct = userAgentValueCollection.Where<ProductInfoHeaderValue>((p) => p.Product.Name.Equals(defaultProductName)).FirstOrDefault<ProductInfoHeaderValue>();
            var testProduct = userAgentValueCollection.Where<ProductInfoHeaderValue>((p) => p.Product.Name.Equals(testProductName)).FirstOrDefault<ProductInfoHeaderValue>();

            Version.TryParse(defaultProduct.Product.Version, out defaultProductVer);
            Version.TryParse(testProduct.Product.Version, out testProductVer);

            Assert.True(defaultProduct.Product.Name.Equals(defaultProductName));
            Assert.NotNull(defaultProductVer);

            Assert.True(testProduct.Product.Name.Equals(testProductName));
            Assert.True(testProduct.Product.Version.Equals(testProductVersion));
        }