Beispiel #1
0
        static public Node Evaluate(
            string hl,
            MockSmtpClient smtp = null,
            MockPop3Client pop3 = null)
        {
            var services = Initialize(smtp, pop3);
            var lambda   = HyperlambdaParser.Parse(hl);
            var signaler = services.GetService(typeof(ISignaler)) as ISignaler;

            signaler.Signal("eval", lambda);
            return(lambda);
        }
Beispiel #2
0
        static public async Task <Node> EvaluateAsync(
            string hl,
            MockSmtpClient smtp,
            MockPop3Client pop3 = null)
        {
            var services = Initialize(smtp, pop3);
            var lambda   = HyperlambdaParser.Parse(hl);
            var signaler = services.GetService(typeof(ISignaler)) as ISignaler;
            await signaler.SignalAsync("eval", lambda);

            return(lambda);
        }
Beispiel #3
0
        static IServiceProvider Initialize(MockSmtpClient smtp, MockPop3Client pop3)
        {
            var services = new ServiceCollection();

            services.AddTransient <ISignaler, Signaler>();
            services.AddTransient <IRootResolver, RootResolver>();
            if (smtp != null)
            {
                services.AddTransient <ISmtpClient>((svc) => smtp);
            }
            if (pop3 != null)
            {
                services.AddTransient <IPop3Client>((svc) => pop3);
            }

            var types = new SignalsProvider(InstantiateAllTypes <ISlot>(services));

            services.AddTransient <ISignalsProvider>((svc) => types);
            services.AddTransient <IStreamService, StreamService>();
            services.AddTransient <IFileService, FileService>();
            services.AddTransient <ConnectionSettingsSmtp>((svc) => new ConnectionSettingsSmtp
            {
                Host     = "foo2.com",
                Port     = 321,
                Secure   = false,
                Username = "******",
                Password = "******",
                From     = new Sender
                {
                    Name    = "Foo Bar",
                    Address = "*****@*****.**",
                }
            });
            services.AddTransient <ConnectionSettingsPop3>((svc) => new ConnectionSettingsPop3
            {
                Host     = "foo2.com",
                Port     = 321,
                Secure   = false,
                Username = "******",
                Password = "******"
            });

            return(services.BuildServiceProvider());
        }
Beispiel #4
0
        static IServiceProvider Initialize(MockSmtpClient smtp, MockPop3Client pop3)
        {
            var services = new ServiceCollection();

            services.AddTransient <ISignaler, Signaler>();
            var mockConfiguration = new Mock <IConfiguration>();

            if (smtp != null)
            {
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:smtp:host")]).Returns("foo2.com");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:smtp:port")]).Returns("321");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:smtp:secure")]).Returns("false");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:smtp:username")]).Returns("xxx2");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:smtp:password")]).Returns("yyy2");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:smtp:from:name")]).Returns("Foo Bar");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:smtp:from:address")]).Returns("*****@*****.**");
                services.AddTransient <ISmtpClient>((svc) => smtp);
            }
            if (pop3 != null)
            {
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:pop3:host")]).Returns("foo2.com");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:pop3:port")]).Returns("321");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:pop3:secure")]).Returns("false");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:pop3:username")]).Returns("xxx2");
                mockConfiguration.SetupGet(x => x[It.Is <string>(y => y == "magic:pop3:password")]).Returns("yyy2");
                services.AddTransient <IPop3Client>((svc) => pop3);
            }
            services.AddTransient((svc) => mockConfiguration.Object);

            var types = new SignalsProvider(InstantiateAllTypes <ISlot>(services));

            services.AddTransient <ISignalsProvider>((svc) => types);
            var provider = services.BuildServiceProvider();

            return(provider);
        }
Beispiel #5
0
        static public ISignaler GetSignaler(MockSmtpClient smtp, MockPop3Client pop3)
        {
            var services = Initialize(smtp, pop3);

            return(services.GetService(typeof(ISignaler)) as ISignaler);
        }