Exemple #1
0
        public void Test_ShouldWebsiteBeBlocked_NullCheck()
        {
            //Arrange
            var service = new WebsiteBlockerService();

            //Act
            service.ShouldWebsiteBeBlocked("https://google.com", null);
        }
Exemple #2
0
        public void Test_ShouldWebsiteBeBlocked_NullUrl()
        {
            //Arrange
            var service = new WebsiteBlockerService();

            //Act
            service.ShouldWebsiteBeBlocked(null);
        }
Exemple #3
0
        public bool ShouldWebsiteBeBlocked(WebsiteBlockerRequestDto request)
        {
            if (request.Url == null)
            {
                throw new ArgumentNullException();
            }

            var checks = WebsiteBlockerCheckFactory.CreateWebsiteBlockerChecks(request.BlacklistedSites, request.WhitelistedSites, request.BlacklistedWords);

            return(WebsiteBlockerService.ShouldWebsiteBeBlocked(request.Url, checks.ToArray()));
        }
Exemple #4
0
        public void Test_ShouldWebsiteBeBlocked_AllFalse()
        {
            //Arrange
            var url     = "https://google.com";
            var service = new WebsiteBlockerService();

            var checks = CreatedMockedWebsiteChecks(url, false, 3);

            //Act
            var result = service.ShouldWebsiteBeBlocked(url, checks.ToArray());

            //Assert
            Assert.IsFalse(result);
        }
Exemple #5
0
        public void Test_ShouldWebsiteBeBlocked_OneTrue()
        {
            //Arrange
            var url     = "https://google.com";
            var service = new WebsiteBlockerService();

            var checks = CreatedMockedWebsiteChecks(url, false, 2);

            checks.Add(CreateMockedCheck(url, true));

            //Act
            var result = service.ShouldWebsiteBeBlocked(url, checks.ToArray());

            //Assert
            Assert.IsTrue(result);
        }
Exemple #6
0
        public void Test_ShouldWebsiteBeBlocked_NotWhitelisted_ShouldNotBlock()
        {
            //Arrange
            var url     = "https://google.com";
            var service = new WebsiteBlockerService();

            var checks = new List <IWebsiteBlockerCheck>();

            var whitelistedCheck = new Mock <WhitelistedSiteCheck>(new List <string>());

            whitelistedCheck.Setup(x => x.ValidateUrl(url)).Returns(true);
            checks.Add(whitelistedCheck.Object);

            CreateMockedCheck(url, false);

            //Act
            var result = service.ShouldWebsiteBeBlocked(url, checks.ToArray());

            //Assert
            Assert.IsFalse(result);
        }