public void CopyContextsTest() { ILogger logger1 = new Mock <ILogger>().Object; IStorageContext storageCtx1 = new Mock <IStorageContext>().Object; INoSqlContext noSqlCtx1 = new Mock <INoSqlContext>().Object; ISmtpContext smtpCtx1 = new Mock <ISmtpContext>().Object; BusinessOperationMocked opr1 = new BusinessOperationMocked(); opr1.SetLogger(logger1); opr1.SetNoSqlContext(noSqlCtx1); opr1.SetStorageContext(storageCtx1); opr1.SetSmtpContext(smtpCtx1); BusinessOperationMocked opr2 = new BusinessOperationMocked(); opr2.CopyContexts(opr1); ILogger logger2 = opr2.GetLogger(); Assert.AreSame(logger1, logger2, "Setter and Getter should return the same thing!!!"); IStorageContext storageCtx2 = opr2.GetStorageContext(); Assert.AreSame(storageCtx1, storageCtx2, "Setter and Getter should return the same thing!!!"); INoSqlContext noSqlCtx2 = opr2.GetNoSqlContext(); Assert.AreSame(noSqlCtx1, noSqlCtx2, "Setter and Getter should return the same thing!!!"); ISmtpContext noSmtpCtx2 = opr2.GetSmtpContext(); Assert.AreSame(noSqlCtx1, noSqlCtx2, "Setter and Getter should return the same thing!!!"); }
public virtual SmtpCommandResult Execute(ISmtpContext context, string request) { this.Context = context; var parts = request.Split(' '); var command = parts[0].ToUpper().Trim(); if (GetMatchCommands().IfNullEmpty().Any(c => c.Equals(command, StringComparison.OrdinalIgnoreCase))) { if ((Session?.RequiresAuthentication ?? false) && string.IsNullOrEmpty(Session?.Username) && this.RequiresAuthentication) { Connection.SendLine("530 Authentication is required").Wait(); } else { Run(command, parts.Skip(1).ToArray()); } return(SmtpCommandResult.Done); } return(SmtpCommandResult.Continue); }
public void ContextWithNoProfileContextGetterSetterTest() { IStorageContext storageCtx1 = new Mock <IStorageContext>().Object; FactoryBusinessOperation.SetStorageContext(storageCtx1); IStorageContext storageCtx2 = FactoryBusinessOperation.GetStorageContext(); Assert.AreSame(storageCtx1, storageCtx2, "Setter and Getter should return the same thing!!!"); INoSqlContext noSqlCtx1 = new Mock <INoSqlContext>().Object; FactoryBusinessOperation.SetNoSqlContext(noSqlCtx1); INoSqlContext noSqlCtx2 = FactoryBusinessOperation.GetNoSqlContext(); Assert.AreSame(noSqlCtx1, noSqlCtx2, "Setter and Getter should return the same thing!!!"); ISmtpContext noSmtpCtx1 = new Mock <ISmtpContext>().Object; FactoryBusinessOperation.SetSmtpContext(noSmtpCtx1); ISmtpContext noSmtpCtx2 = FactoryBusinessOperation.GetSmtpContext(); Assert.AreSame(noSqlCtx1, noSqlCtx2, "Setter and Getter should return the same thing!!!"); BaseDbContext databaseCtx1 = new Mock <BaseDbContext>(null).Object; FactoryBusinessOperation.SetDatabaseContext(databaseCtx1); BaseDbContext databaseCtx2 = FactoryBusinessOperation.GetDatabaseContext(); Assert.AreSame(databaseCtx1, databaseCtx2, "Setter and Getter should return the same thing!!!"); }
public void KnownNameTest(string apiName) { FactorySmtpContext.SetLoggerFactory(new Mock <ILoggerFactory>().Object); ISmtpContext opt = FactorySmtpContext.CreateSmtpObject(apiName); opt.GetLogger(); Assert.IsNotNull(opt, "Object must not be null!!!"); }
public void UnknownApiNameTest(string apiName) { try { ISmtpContext opt = FactorySmtpContext.CreateSmtpObject(apiName); Assert.True(false, "Exception shoud be throw for unknow API!!!"); } catch (Exception e) { Assert.True(true, e.Message); } }
public virtual SmtpCommandResult Execute(ISmtpContext context, string request) { this.Context = context; var parts = request.Split(' '); var command = parts[0].ToUpper().Trim(); if (GetMatchCommands().IfNullEmpty().Any(c => c.Equals(command, StringComparison.OrdinalIgnoreCase))) { Run(command, parts.Skip(1).ToArray()); return SmtpCommandResult.Done; } return SmtpCommandResult.Continue; }
public virtual SmtpCommandResult Execute(ISmtpContext context, string request) { this.Context = context; var parts = request.Split(' '); var command = parts[0].ToUpper().Trim(); if (GetMatchCommands().IfNullEmpty().Any(c => c.Equals(command, StringComparison.OrdinalIgnoreCase))) { Run(command, parts.Skip(1).ToArray()); return(SmtpCommandResult.Done); } return(SmtpCommandResult.Continue); }
public static ISmtpContext CreateSmtpObject(string name) { string className = (string)classMaps[name]; if (className == null) { throw new ArgumentNullException(String.Format("Class not found [{0}]", name)); } Assembly asm = Assembly.GetExecutingAssembly(); ISmtpContext obj = (ISmtpContext)asm.CreateInstance(className); if (loggerFactory != null) { Type t = obj.GetType(); ILogger logger = loggerFactory.CreateLogger(t); obj.SetLogger(logger); } return(obj); }
public virtual bool SendEmail(MContactUs form, string captchaToken) { bool result = false; string emailTo = GetEmailTo(); if (emailTo != null) { Mail m = new Mail(); m.From = "*****@*****.**"; m.FromName = form.Name; m.To = emailTo; m.Subject = form.Subject; m.IsHtmlContent = true; m.Body = form.Email + ", " + form.Message; m.BCC = ""; m.CC = ""; ISmtpContext smtpContext = GetSmtpContext(); smtpContext.Send(m); Log.Logger.Information("Email sent to [{0}]", emailTo); result = true; string shortToken = captchaToken.Substring(0, 10); LineNotification line = new LineNotification(); string token = Environment.GetEnvironmentVariable("MAGNUM_LINE_TOKEN"); line.SetNotificationToken(token); string lineMsg = String.Format( "\nMagnumWeb ContactUs\nFrom:{0}\nSubject:{1}\nMessage:{2}\nCaptcha:{3}", form.Email, form.Subject, form.Message, shortToken); line.Send(lineMsg); } else { Log.Logger.Information("Env variable MAGNUM_EMAIL_TO not set!!!"); } return(result); }
public void GetterSetterTest() { BusinessOperationMocked opr = new BusinessOperationMocked(); ILogger logger1 = new Mock <ILogger>().Object; opr.SetLogger(logger1); ILogger logger2 = opr.GetLogger(); Assert.AreSame(logger1, logger2, "Setter and Getter should return the same thing!!!"); IStorageContext storageCtx1 = new Mock <IStorageContext>().Object; opr.SetStorageContext(storageCtx1); IStorageContext storageCtx2 = opr.GetStorageContext(); Assert.AreSame(storageCtx1, storageCtx2, "Setter and Getter should return the same thing!!!"); INoSqlContext noSqlCtx1 = new Mock <INoSqlContext>().Object; opr.SetNoSqlContext(noSqlCtx1); INoSqlContext noSqlCtx2 = opr.GetNoSqlContext(); Assert.AreSame(noSqlCtx1, noSqlCtx2, "Setter and Getter should return the same thing!!!"); ISmtpContext noSmtpCtx1 = new Mock <ISmtpContext>().Object; opr.SetSmtpContext(noSmtpCtx1); ISmtpContext noSmtpCtx2 = opr.GetSmtpContext(); Assert.AreSame(noSqlCtx1, noSqlCtx2, "Setter and Getter should return the same thing!!!"); opr.SetAutoCommit(false); bool autoCommit = opr.GetAutoCommit(); Assert.AreEqual(false, autoCommit, "Setter and Getter should return the same thing!!!"); }
public static void SetSmtpContext(string profile, ISmtpContext ctx) { ContextGroup grp = GetContextGroup(profile); grp.SmtpContext = ctx; }
public static void SetSmtpContext(ISmtpContext ctx) { ContextGroup grp = GetContextGroup(FactoryContextUtils.DefaultProfileName); grp.SmtpContext = ctx; }
public void SetSmtpContext(ISmtpContext context) { smtpContext = context; }