public void SamopalDISeeCommentsIntTest05()
        {
            var di = new SamopalDI();

            di.BindDefault <IClass5>((args) => new Class5((string)args[0]));

            di.BindDefault <IClass2, Class2>();
            di.BindDefault <IClass3, Class3>();
            di.BindDefault <IClass4>((args) =>
            {
                IClass5 c5 = di.GetDefault <IClass5>(args);
                return(new Class4(c5));
            });

            di.BindDefault <IClass1>((args) =>
            {
                IClass2 c2 = di.GetDefault <IClass2>();
                IClass4 c4 = di.GetDefault <IClass4>(args);

                return(new Class1(c2, c4));
            });

            object[] arrayOfArgs = new object[] { "Hello, Test!" };

            Type    expected = typeof(Class1);
            IClass1 variable = di.GetDefault <IClass1>(arrayOfArgs);
            Type    actual   = variable.GetType();

            Assert.AreEqual(expected, actual);
            Assert.AreEqual("Hello, Test!", variable.Class4.Class5.SomeString);
            Assert.IsNotNull(variable.Class2.Class3);
        }
        public void SamopalDISeeCommentsIntTest02()
        {
            var di = new SamopalDI();

            di.BindDefault <IClass3, Class3>();
            di.BindExample <IClass2>(1, (args) => new Class2(di.GetDefault <IClass3>()));

            IClass2 class2WithClass3 = di.GetExample <IClass2>(1, null);

            di.BindDefault <IClass3, AnotherClass3>();
            di.BindExample <IClass2>(1, (args) => new AnotherClass2(di.GetDefault <IClass3>()));

            IClass2 class2WithAnotherClass3 = di.GetExample <IClass2>(1, null);
        }
        public void SamopalDISeeCommentsIntTest14()
        {
            var di = new SamopalDI();

            di.BindDefault <IClass5>((args) => new Class5((string)args[0]));

            Assert.ThrowsException <NullReferenceException>(() => di.GetDefault <IClass5>());
        }
        public void SamopalDISeeCommentsIntTest13()
        {
            var di = new SamopalDI();

            di.BindDefault <IClass1>((args) => new Class3());

            Assert.ThrowsException <InvalidDelegateReturnTypeException>(() => di.GetDefault <IClass1>());
        }
        public void SamopalDISeeCommentsIntTest10()
        {
            var di = new SamopalDI(LateBindingOptions.DefaultCtor);

            di.BindDefault <IClass1, Class1>();

            Assert.ThrowsException <LateBindingException>(() => di.GetDefault <IClass1>());
        }
        public void SamopalDISeeCommentsIntTest01()
        {
            var di = new SamopalDI();

            // There wasn't Default Bind
            Assert.ThrowsException <ArgumentException>(() => di.GetDefault <IClass1>());

            // And there wasn't Example 1 Bind
            Assert.ThrowsException <ArgumentException>(() => di.GetExample <IClass1>(1));
        }
        public void SamopalDISeeCommentsIntTest11()
        {
            var di = new SamopalDI(LateBindingOptions.DefaultOrMinCtor);

            di.BindDefault <IClass1, Class1>();
            di.BindDefault <IClass2, Class2>();

            var class1 = di.GetDefault <IClass1>();

            Assert.IsNull(class1.Class4);
        }
        public void SamopalDISeeCommentsIntTest12()
        {
            var di = new SamopalDI(LateBindingOptions.DefaultOrMaxCtor);

            di.BindDefault <IClass1, Class1>();
            di.BindDefault <IClass2, Class2>();
            di.BindDefault <IClass3, Class3>();
            di.BindDefault <IClass4, Class4>();
            di.BindDefault <IClass5>((args) => new Class5(null));

            var class1 = di.GetDefault <IClass1>();

            Assert.IsNotNull(class1.Class4);
        }
        public void SamopalDISeeCommentsIntTest03()
        {
            var di = new SamopalDI();

            di.BindDefault <IClass5>((args) => new Class5("Hello, Test!"));

            di.BindDefault <IClass2, Class2>();
            di.BindDefault <IClass3, Class3>();
            di.BindDefault <IClass4, Class4>();

            di.BindDefault <IClass1, Class1>();

            Type    expected = typeof(Class1);
            IClass1 variable = di.GetDefault <IClass1>();
            Type    actual   = variable.GetType();

            Assert.AreEqual(expected, actual);
            Assert.AreEqual("Hello, Test!", variable.Class4.Class5.SomeString);
        }
Exemple #10
0
        private static IFileHandler InstantiateDefaultFileHandlerBySamopalDI()
        {
            var di = new SamopalDI();

            di.BindDefault <AppSettingsReader>();

            di.BindDefault <ISmtpHandler>((args) =>
            {
                AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>();

                string mail = (string)appSettingsReader.GetValue("OurMailAddress", typeof(string));
                string host = (string)appSettingsReader.GetValue("Host", typeof(string));
                int port    = (int)appSettingsReader.GetValue("Port", typeof(int));
                SmtpDeliveryMethod method = (SmtpDeliveryMethod)appSettingsReader.GetValue("SMTPDeliveryMethod", typeof(int));
                string ourMailPassword    = (string)appSettingsReader.GetValue("OurMailPassword", typeof(string));
                bool enableSsl            = (bool)appSettingsReader.GetValue("EnableSSL", typeof(bool));

                return(new SmtpHandler(host, port, method, new NetworkCredential(mail, ourMailPassword), enableSsl));
            });

            di.BindDefault <ISendingFileFactory, SendingFileFactory>();

            di.BindDefault <IFileSender>((args) =>
            {
                AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>();

                string ourMail    = (string)appSettingsReader.GetValue("OurMailAddress", typeof(string));
                string targetMail = (string)appSettingsReader.GetValue("TargetMailAddress", typeof(string));

                return(new FileSender(ourMail, targetMail, di.GetDefault <ISmtpHandler>(), di.GetDefault <ISendingFileFactory>()));
            });

            di.BindDefault <IFileManipulator, FileManipulator>();

            di.BindDefault <IFileWatcher>((args) =>
            {
                AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>();

                string mailToSendFolderPath = (string)appSettingsReader.GetValue("MailToSendFP", typeof(string));
                NotifyFilters notifyFilter  = (NotifyFilters)appSettingsReader.GetValue("NotifyFilter", typeof(int));
                string filter = (string)appSettingsReader.GetValue("Filter", typeof(string));

                return(new FileWatcher(mailToSendFolderPath, filter, notifyFilter, di.GetDefault <IFileManipulator>()));
            });

            di.BindDefault <ILog>((args) => LogManager.GetLogger(typeof(FileHandler)));

            di.BindDefault <IFileHandler>((args) =>
            {
                AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>();

                string mailToSendFolderPath  = (string)appSettingsReader.GetValue("MailToSendFP", typeof(string));
                string invalidMailFolderPath = (string)appSettingsReader.GetValue("InvalidMailFP", typeof(string));

                return(new FileHandler(
                           mailToSendFolderPath,
                           invalidMailFolderPath,
                           di.GetDefault <IFileWatcher>(),
                           di.GetDefault <IFileManipulator>(),
                           di.GetDefault <IFileSender>(),
                           di.GetDefault <ILog>()));
            });

            return(di.GetDefault <IFileHandler>());
        }