Пример #1
0
        public void get_all()
        {
            // ARRANGE
            var cookies = new CookieContainer();

            cookies.Add(new Cookie("name1", "value1", "/", "domain1.com"));
            cookies.Add(new Cookie("name2", "value2", "/", "domain1.com"));
            cookies.Add(new Cookie("name3", "value3", "/", "domain2.com"));

            // ACT
            var hashTable = cookies.ReflectOverAllCookies();

            // ASSERT
            hashTable.Keys.Count.Should().Be(2);
            var keys = hashTable.Keys.Cast <string>().ToList();

            keys.Should().BeEquivalentTo(".domain1.com", ".domain2.com");
            keys.Should().BeEquivalentTo(".domain2.com", ".domain1.com");

            var collection1 = cookies.GetCookies(new Uri("http://domain1.com/"));

            collection1.Count.Should().Be(2);

            var collection1CookieNames = collection1.Cast <Cookie>().Select(c => c.Name).ToList();

            collection1CookieNames.Should().BeEquivalentTo("name1", "name2");

            var cookie1_1 = collection1["name1"];

            cookie1_1.Name.Should().Be("name1");
            cookie1_1.Value.Should().Be("value1");
            cookie1_1.Domain.Should().Be("domain1.com");

            var cookie1_2 = collection1["name2"];

            cookie1_2.Name.Should().Be("name2");
            cookie1_2.Value.Should().Be("value2");
            cookie1_2.Domain.Should().Be("domain1.com");

            var collection2 = cookies.GetCookies(new Uri("http://domain2.com/"));

            collection2.Count.Should().Be(1);

            var collection2CookieNames = collection2.Cast <Cookie>().Select(c => c.Name).ToList();

            collection2CookieNames.Should().BeEquivalentTo("name3");

            var cookie2_1 = collection2[0];

            cookie2_1.Name.Should().Be("name3");
            cookie2_1.Value.Should().Be("value3");
            cookie2_1.Domain.Should().Be("domain2.com");
        }