Пример #1
0
        public void Binding_UsesNameResolver()
        {
            ParameterInfo     parameter = GetType().GetMethod("TestMethod", BindingFlags.Static | BindingFlags.NonPublic).GetParameters().First();
            SendGridAttribute attribute = new SendGridAttribute
            {
                To      = "%param1%",
                From    = "%param2%",
                Subject = "%param3%",
                Text    = "%param4%"
            };
            SendGridConfiguration config = new SendGridConfiguration
            {
                ApiKey = "12345"
            };

            Dictionary <string, Type> contract = new Dictionary <string, Type>();
            BindingProviderContext    context  = new BindingProviderContext(parameter, contract, CancellationToken.None);

            var nameResolver = new TestNameResolver();

            nameResolver.Values.Add("param1", "*****@*****.**");
            nameResolver.Values.Add("param2", "*****@*****.**");
            nameResolver.Values.Add("param3", "Value3");
            nameResolver.Values.Add("param4", "Value4");

            SendGridBinding             binding     = new SendGridBinding(parameter, attribute, config, nameResolver, context);
            Dictionary <string, object> bindingData = new Dictionary <string, object>();
            SendGridMessage             message     = binding.CreateDefaultMessage(bindingData);

            Assert.Equal("*****@*****.**", message.To.Single().Address);
            Assert.Equal("*****@*****.**", message.From.Address);
            Assert.Equal("Value3", message.Subject);
            Assert.Equal("Value4", message.Text);
        }
        public void ParseFromAddress_Failure(string value)
        {
            MailAddress address = null;
            bool        result  = SendGridBinding.ParseFromAddress(value, out address);

            Assert.False(result);
            Assert.Null(address);
        }
Пример #3
0
        /// <inheritdoc/>
        public override bool TryCreate(ScriptBindingContext context, out ScriptBinding binding)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            binding = null;

            if (string.Compare(context.Type, "sendGrid", StringComparison.OrdinalIgnoreCase) == 0)
            {
                binding = new SendGridBinding(context);
            }

            return(binding != null);
        }
Пример #4
0
        public void CreateDefaultMessage_CreatesExpectedMessage()
        {
            ParameterInfo     parameter = GetType().GetMethod("TestMethod", BindingFlags.Static | BindingFlags.NonPublic).GetParameters().First();
            SendGridAttribute attribute = new SendGridAttribute
            {
                To      = "{Param1}",
                Subject = "Test {Param2}",
                Text    = "Test {Param3}"
            };
            SendGridConfiguration config = new SendGridConfiguration
            {
                ApiKey      = "12345",
                FromAddress = new MailAddress("*****@*****.**", "Test2"),
                ToAddress   = "*****@*****.**"
            };
            Dictionary <string, Type> contract = new Dictionary <string, Type>();

            contract.Add("Param1", typeof(string));
            contract.Add("Param2", typeof(string));
            contract.Add("Param3", typeof(string));
            BindingProviderContext context = new BindingProviderContext(parameter, contract, CancellationToken.None);

            var                         nameResolver = new TestNameResolver();
            SendGridBinding             binding      = new SendGridBinding(parameter, attribute, config, nameResolver, context);
            Dictionary <string, object> bindingData  = new Dictionary <string, object>();

            bindingData.Add("Param1", "*****@*****.**");
            bindingData.Add("Param2", "Value2");
            bindingData.Add("Param3", "Value3");
            SendGridMessage message = binding.CreateDefaultMessage(bindingData);

            Assert.Same(config.FromAddress, message.From);
            Assert.Equal("*****@*****.**", message.To.Single().Address);
            Assert.Equal("Test Value2", message.Subject);
            Assert.Equal("Test Value3", message.Text);

            // If no To value specified, verify it is defaulted from config
            attribute = new SendGridAttribute
            {
                Subject = "Test {Param2}",
                Text    = "Test {Param3}"
            };
            binding = new SendGridBinding(parameter, attribute, config, nameResolver, context);
            message = binding.CreateDefaultMessage(bindingData);
            Assert.Equal("*****@*****.**", message.To.Single().Address);
        }
        public void ParseFromAddress_Success()
        {
            MailAddress address = null;

            SendGridBinding.ParseFromAddress("*****@*****.**", out address);
            Assert.Equal("*****@*****.**", address.Address);
            Assert.Equal(string.Empty, address.DisplayName);

            address = null;
            SendGridBinding.ParseFromAddress("[email protected]:Test Account", out address);
            Assert.Equal("*****@*****.**", address.Address);
            Assert.Equal("Test Account", address.DisplayName);

            address = null;
            SendGridBinding.ParseFromAddress("[email protected]:Test Acco:unt", out address);
            Assert.Equal("*****@*****.**", address.Address);
            Assert.Equal("Test Acco:unt", address.DisplayName);
        }