Exemplo n.º 1
0
        public void Multiple_senders_should_not_match()
        {
            var parser  = new SendgridEmailParser();
            var request = EmailRequest.Parse(Load("mail.txt"), parser);

            var config = GetConfig();

            config.Rules[0].Filters = new[]
            {
                new EmailFilter
                {
                    Type  = "!sender contains",
                    AllOf = new[]
                    {
                        "*****@*****.**",
                        "*****@*****.**"
                    }
                }
            };

            request.Email.From.Email = "*****@*****.**";
            var actions = EmailService.ActionsToPerform(request.Email, config);

            actions.Select(a => a.Id).Should().BeEmpty();

            request.Email.From.Name = request.Email.From.Email = "*****@*****.**";
            actions = EmailService.ActionsToPerform(request.Email, config);
            actions.Select(a => a.Id).Should().ContainInOrder("forward-all", "notify-all");
        }
Exemplo n.º 2
0
        public void Subject_filter_should_match()
        {
            var parser  = new SendgridEmailParser();
            var request = EmailRequest.Parse(Load("mail.txt"), parser);

            var config = GetConfig();

            config.Rules[0].Filters = new[]
            {
                new EmailFilter
                {
                    Type  = "subject contains",
                    OneOf = new[]
                    {
                        "Test 1",
                        "not found"
                    }
                },
                new EmailFilter
                {
                    Type  = "sender contains",
                    OneOf = new[]
                    {
                        "not found",
                        "sender@"
                    }
                }
            };

            var actions = EmailService.ActionsToPerform(request.Email, config);

            actions.Select(a => a.Id).Should().ContainInOrder("forward-all", "notify-all");
        }
Exemplo n.º 3
0
        public void No_action_filter_should_return_all()
        {
            var parser  = new SendgridEmailParser();
            var request = EmailRequest.Parse(Load("mail.txt"), parser);

            var config = GetConfig();

            var actions = EmailService.ActionsToPerform(request.Email, config);

            actions.Select(a => a.Id).Should().ContainInOrder("forward-all", "notify-all");
        }
Exemplo n.º 4
0
        public void Unmatched_action_filter_should_ignore_all()
        {
            var parser  = new SendgridEmailParser();
            var request = EmailRequest.Parse(Load("mail.txt"), parser);

            var config = GetConfig();

            config.Rules[0].Filters = new[]
            {
                new EmailFilter
                {
                    Type  = "subject contains",
                    OneOf = new[]
                    {
                        "not found"
                    }
                }
            };

            var actions = EmailService.ActionsToPerform(request.Email, config);

            actions.Should().BeEmpty();
        }
Exemplo n.º 5
0
        public void Subject_filter_should_match_only_its_actions(string rule, string match, string sender, string recipient, string subject, string body, bool shouldMatch)
        {
            var parser  = new SendgridEmailParser();
            var request = EmailRequest.Parse(Load("mail.txt"), parser);

            request.Email.From.Email  = sender;
            request.Email.To[0].Email = recipient;
            request.Email.Subject     = subject;
            request.Email.Text        = request.Email.Html = body;

            var config = GetConfig();

            config.Rules = new[]
            {
                new EmailRule
                {
                    Filters = new[]
                    {
                        new EmailFilter
                        {
                            Type  = rule,
                            OneOf = new[]
                            {
                                match,
                                "not found"
                            }
                        }
                    },
                    Actions = new[]
                    {
                        new EmailAction
                        {
                            Id         = "notify-all",
                            Type       = ActionType.Webhook,
                            Properties = JObject.FromObject(new
                            {
                                webhook = new
                                {
                                    secretName = "Webhook2"
                                },
                                subject = "You've got mail!",
                                body    = "%subject%"
                            })
                        }
                    }
                }
            };

            if (rule.StartsWith("!"))
            {
                config.Rules[0].Filters[0].AllOf = config.Rules[0].Filters[0].OneOf;
                config.Rules[0].Filters[0].OneOf = null;
            }

            var actions = EmailService.ActionsToPerform(request.Email, config);

            if (shouldMatch)
            {
                actions.Select(a => a.Id).Should().ContainInOrder("notify-all");
            }
            else
            {
                actions.Should().BeEmpty();
            }
        }