コード例 #1
0
        public void IsBot_ShouldBeFalse_IfHpInputNameIsInFormAndEmpty()
        {
            // Arrang
            Honeypot.InputNames.Clear();
            Honeypot.CustomRules.Clear();
            var worker = new HoneypotWorker();
            var token = new HoneypotData(HoneypotData.DefaultFieldName);
            var serializer = new HoneypotDataSerializer();
            var form = new NameValueCollection {
                { "FirstName", "Jon" }, {
                    HoneypotData.FormKeyFieldName,
                    serializer.Serialize(token)
                },
                {token.InputNameValue, ""}
            };

            // Act
            bool isBot = worker.IsBot(MvcHelper.GetHttpContext(form));

            // Assert
            Assert.False(isBot);
        }
コード例 #2
0
        public void IsBot_ShouldReturnTrue_WhenValidateRulesReturnsFalse()
        {
            // Arrang
            Honeypot.InputNames.Clear();
            var worker = new HoneypotWorker();
            Honeypot.CustomRules.Clear();

            var token = new HoneypotData(HoneypotData.DefaultFieldName);
            var serializer = new HoneypotDataSerializer();
            var form = new NameValueCollection {
                { "FirstName", "Jon" }, {
                    HoneypotData.FormKeyFieldName,
                    serializer.Serialize(token)
                },
                {token.InputNameValue, ""}
            };
            Func<NameValueCollection, bool> failingRule = (f) => true;
            Honeypot.CustomRules.Add(failingRule);

            // Act
            bool isBot = worker.IsBot(MvcHelper.GetHttpContext(form));

            // Assert
            Assert.True(isBot);
        }
コード例 #3
0
        public void IsBot_ShouldBeTrue_IfTokenInputIsNotInForm()
        {
            // Arrang
            var worker = new HoneypotWorker();
            var form = new NameValueCollection { { "FirstName", "Jon" } };

            // Act
            bool isBot = worker.IsBot(MvcHelper.GetHttpContext(form));

            // Assert
            Assert.True(isBot);
        }