Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }