コード例 #1
0
        public void SimpleRegexRulesHttpUpdater_should_not_update_rules_when_remote_file_not_found_real_request()
        {
            // Arrange
            var notFoundUrl   = "https://raw.githubusercontent.com/MakingSense/safe-browsing/resources/notfound";
            var originalRegex = new Regex(".*");
            var rules         = new SimpleRegexRules(new[] { originalRegex });
            var sut           = new SimpleRegexRulesHttpUpdater(notFoundUrl, rules);

            Assert.AreEqual(1, rules.Blacklist.Count);

            // Act
            try
            {
                sut.UpdateAsync().Wait();

                // Assert
                Assert.Fail("Update should throw exception when URL not found");
            }
            catch
            {
                // Assert
                Assert.AreEqual(1, rules.Blacklist.Count);
                Assert.AreEqual(originalRegex, rules.Blacklist.First());
            }
        }
コード例 #2
0
        public void SimpleRegexRulesHttpUpdater_should_not_update_rules_when_remote_file_not_found()
        {
            // Arrange
            var anyUrl     = "http://example.com/notfound";
            var rules      = new SimpleRegexRulesDouble();
            var httpClient = new HttpClientDouble();

#if (!NETSTANDARD1_0)
            httpClient.Setup_GetString(new System.Net.Http.HttpRequestException("404 (Not Found)."));
#else
            httpClient.Setup_GetString(new System.Net.WebException("(404) Not Found."));
#endif
            var sut = new SimpleRegexRulesHttpUpdater(anyUrl, rules, httpClient);

            // Act
            try
            {
                sut.UpdateAsync().Wait();

                // Assert
                Assert.Fail("Update should throw exception when URL not found");
            }
            catch
            {
                // Assert
                Assert.AreEqual(0, rules.Count_Update);
            }
        }