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!!!"); }
protected override int Execute() { Hashtable args = GetArguments(); string serial = args["serial"].ToString(); string pin = args["pin"].ToString(); string ip = args["ip"].ToString(); INoSqlContext ctx = GetNoSqlContextWithAuthen("firebase"); FactoryBusinessOperation.SetNoSqlContext(ctx); FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory()); CreateRegistration opr = (CreateRegistration)FactoryBusinessOperation.CreateBusinessOperationObject("CreateRegistration"); MRegistration param = new MRegistration(); param.IP = ip; param.Pin = pin; param.SerialNumber = serial; try { opr.Apply(param); Console.WriteLine("Done register barcode [{0}] [{1}]", serial, pin); } catch (Exception e) { Console.WriteLine("Error : {0}", e.Message); } return(0); }
public void ExecuteTest() { ConsoleAppBase app = (ConsoleAppBase)FactoryConsoleApplication.CreateConsoleApplicationObject("BarcodeMigrate"); MBarcode existingData = new MBarcode(); Mock <INoSqlContext> mockCtx = new Mock <INoSqlContext>(); mockCtx.Setup(foo => foo.GetObjectByKey <MBarcode>("barcodes/8/0/5/2/1/5/8059699639/2154237147")).Returns(existingData); INoSqlContext ctx = mockCtx.Object; app.SetNoSqlContext(ctx); ILogger logger = new Mock <ILogger>().Object; app.SetLogger(logger); OptionSet opt = app.CreateOptionSet(); opt.Parse(args); createInputFile((String)h["infile"]); int result = app.Run(); Assert.AreEqual(0, result); }
public void ExecuteExceptionTest() { Mock <BarcodeMigrateApplication> mockApp = new Mock <BarcodeMigrateApplication>() { CallBase = true };; mockApp.Setup(foo => foo.InsertData(It.IsAny <MBarcode>())).Throws(new Exception()); BarcodeMigrateApplication app = mockApp.Object; MBarcode existingData = new MBarcode(); Mock <INoSqlContext> mockCtx = new Mock <INoSqlContext>(); INoSqlContext ctx = mockCtx.Object; app.SetNoSqlContext(ctx); ILogger logger = new Mock <ILogger>().Object; app.SetLogger(logger); OptionSet opt = app.CreateOptionSet(); opt.Parse(args); createInputFile((String)h["infile"]); int result = app.Run(); Assert.AreEqual(1, result); }
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 void KnownNameTest(string name) { FactoryNoSqlContext.SetLoggerFactory(new Mock <ILoggerFactory>().Object); INoSqlContext opt = FactoryNoSqlContext.CreateNoSqlObject(name); Assert.IsNotNull(opt, "Object must not be null!!!"); }
protected INoSqlContext GetNoSqlContext(string provider, string host, string key, string user, string password) { INoSqlContext ctx = null; ctx = FactoryNoSqlContext.CreateNoSqlObject(provider); ctx.Authenticate(host, key, user, password); return(ctx); }
public void UnknownApiNameTest(string name) { try { INoSqlContext opt = FactoryNoSqlContext.CreateNoSqlObject(name); Assert.True(false, "Exception shoud be throw for unknow name!!!"); } catch (Exception e) { Assert.True(true, e.Message); } }
private void Authen(INoSqlContext ctx) { string host = Environment.GetEnvironmentVariable("ONIX_FIREBASE_DATABASE"); string key = Environment.GetEnvironmentVariable("ONIX_FIREBASE_KEY"); string username = Environment.GetEnvironmentVariable("ONIX_FIREBASE_USERNAME"); string password = Environment.GetEnvironmentVariable("ONIX_FIREBASE_PASSWORD"); //This is for unit testing only, DO NOT put any production data in this DB ctx.Authenticate(host, key, username, password); }
public INoSqlContext GetNoSqlContextWithAuthen(string provider) { INoSqlContext ctx = context; if (context == null) { string host = (string)arguments["host"]; string key = (string)arguments["key"]; string user = (string)arguments["user"]; string password = (string)arguments["password"]; ctx = GetNoSqlContext(provider, host, key, user, password); } return(ctx); }
protected override int Execute() { ILogger logger = GetLogger(); CTable t = XmlToCTable(); INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext"); FactoryBusinessOperation.SetNoSqlContext(ctx); SaveContent opr = (SaveContent)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContent"); try { ArrayList types = t.GetChildArray("Contents"); foreach (CTable pt in types) { MContent mc = new MContent(); mc.Name = pt.GetFieldValue("Name"); mc.Type = pt.GetFieldValue("Type"); mc.LastMaintDate = DateTime.Now; ArrayList values = pt.GetChildArray("Values"); foreach (CTable value in values) { mc.Values = new Dictionary <string, string>(); foreach (CField field in value.GetTableFields()) { mc.Values[field.GetName()] = field.GetValue(); } LogUtils.LogInformation(logger, "Adding content : [{0}][{1}]", mc.Type, mc.Name); } opr.Apply(mc); } } catch (Exception e) { Console.WriteLine("Error : {0}", e); } return(0); }
protected override int Execute() { ILogger logger = GetLogger(); CTable t = XmlToCTable(); INoSqlContext ctx = GetNoSqlContextWithAuthen("firebase"); FactoryBusinessOperation.SetNoSqlContext(ctx); SaveProductType opr = (SaveProductType)FactoryBusinessOperation.CreateBusinessOperationObject("SaveProductType"); try { ArrayList types = t.GetChildArray("ProductTypes"); foreach (CTable pt in types) { MProductType mpt = new MProductType(); mpt.Code = pt.GetFieldValue("Code"); ArrayList descs = pt.GetChildArray("Descriptions"); foreach (CTable desc in descs) { MGenericDescription mdc = new MGenericDescription(); mdc.Language = desc.GetFieldValue("Language"); mdc.Name = desc.GetFieldValue("Name"); mdc.ShortDescription = desc.GetFieldValue("ShortDescription"); mdc.LongDescription1 = desc.GetFieldValue("LongDescription"); mpt.Descriptions.Add(mdc.Language, mdc); LogUtils.LogInformation(logger, "Adding product type : [{0}] [{1}]", mpt.Code, mdc.Name); } opr.Apply(mpt); } } catch (Exception e) { Console.WriteLine("Error : {0}", e.Message); } return(0); }
protected override int Execute() { INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext"); FactoryBusinessOperation.SetNoSqlContext(ctx); IStorageContext storageCtx = GetStorageContextWithAuthen("FirebaseStorageContext"); FactoryBusinessOperation.SetStorageContext(storageCtx); try { processAll(); } catch (Exception e) { Console.WriteLine("Error : {0}", e.StackTrace); } return(0); }
public static INoSqlContext CreateNoSqlObject(string name) { string className = (string)classMaps[name]; if (className == null) { throw new ArgumentNullException(String.Format("Class not found [{0}]", name)); } Assembly asm = Assembly.GetExecutingAssembly(); INoSqlContext obj = (INoSqlContext)asm.CreateInstance(className); if (loggerFactory != null) { Type t = obj.GetType(); ILogger logger = loggerFactory.CreateLogger(t); obj.SetLogger(logger); } return(obj); }
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!!!"); }
protected MongoGenericRepository(INoSqlContext context) { _context = context; }
/// <summary> /// Construtor /// </summary> public StateSearchBase(INoSqlContext _context, QueryProducerBase <State, StateDTO, StateFilter> _queryProducer) : base(_context) { queryProducer = _queryProducer; }
public void SetNoSqlContext(INoSqlContext context) { this.context = context; }
protected override int Execute() { int result = 0; logger = GetLogger(); ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext"); Hashtable args = GetArguments(); string inputFile = args["infile"].ToString(); string url = args["url"].ToString(); string batch = "0000"; string chunk = "0000"; string prof = "MIGRATE"; System.IO.StreamReader file = new System.IO.StreamReader(inputFile); string text; string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmss"); while ((text = file.ReadLine()) != null) { if (!"".Equals(text.Trim()) && !text.Trim().StartsWith("Serial") ) { logger.LogInformation("Migrating: " + text); string[] barcodeData = text.Split(","); string serialNumber = barcodeData[0]; string pin = barcodeData[1]; if (IsBarcodeExisting(serialNumber, pin)) { logger.LogWarning("The barcode is existing. [" + serialNumber + "][" + pin + "]"); logger.LogWarning("Result: SKIP"); } else { MBarcode bc = new MBarcode(); bc.BatchNo = batch; bc.Url = url; bc.GeneratedDate = DateTime.Now; bc.IsActivated = false; bc.Path = string.Format("{0}_{1}_{2}/{3}", prof, batch, timeStamp, chunk); bc.SerialNumber = serialNumber; bc.Pin = pin; bc.PayloadUrl = barcodeData[2]; bc.Barcode = barcodeData[3]; bc.Product = barcodeData[3]; bc.CompanyWebSite = barcodeData[4]; bc.GeneratedDate = DateTime.Now; bc.IsActivated = false; try { InsertData(bc); logger.LogInformation("Result: SUCCESS"); } catch (Exception e) { logger.LogError(e.StackTrace); logger.LogError("Result: FAIL"); result = 1; } } } } file.Dispose(); return(result); }
protected override int Execute() { logger = GetLogger(); Hashtable args = GetArguments(); string payloadUrl = args["url"].ToString(); string batch = args["batch"].ToString(); string prof = args["profile"].ToString(); string outputPath = args["outpath"].ToString(); string generate = (string)args["generate"]; if (generate == null) { generate = ""; } bool imageGenerate = generate.Equals("Y"); BarcodeProfileBase prf = (BarcodeProfileBase)BarcodeProfileFactory.CreateBarcodeProfileObject(prof); INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext"); FactoryBusinessOperation.SetNoSqlContext(ctx); FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory()); CreateBarcode opr = (CreateBarcode)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode"); int quantity = Int32.Parse(args["quantity"].ToString()); MBarcode param = new MBarcode(); param.BatchNo = batch; param.Url = payloadUrl; string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmss"); generator.TemplateFile = prf.TemplateFile; generator.Setup(); CreateExportFile(prof, param, outputPath, timeStamp); for (int i = 1; i <= quantity; i++) { string chunk = ((i - 1) / imgPerFolder).ToString().PadLeft(6, '0'); string urlPath = string.Format("{0}_{1}_{2}/{3}", prof, param.BatchNo, timeStamp, chunk); string dir = string.Format("{0}/{1}", outputPath, urlPath); if (!Directory.Exists(dir) && imageGenerate) { Directory.CreateDirectory(dir); } param.Path = urlPath; param.CompanyWebSite = prf.CompanyWebSite; param.Barcode = prf.Barcode; param.Product = prf.Product; MBarcode bc = opr.Apply(param); string fileName = string.Format("{0}/{1}-{2}.png", dir, bc.SerialNumber, bc.Pin); if (imageGenerate) { generator.RenderToFile(bc, fileName); } progressFunc(bc, dir); WriteExportFile(prf, bc, param); if ((i % progressPerImage) == 0) { int remain = quantity - i; LogUtils.LogInformation(logger, "Generated {0} barcodes, {1} barcodes to go...", i, remain); } } CloseExportFiles(); generator.Cleanup(); LogUtils.LogInformation(logger, "Done generating {0} barcodes.", quantity); int shipped = UpdateTotalShipped(quantity); LogUtils.LogInformation(logger, "Updated shipped number to {0}.", shipped); return(0); }
/// <summary> /// Construtor /// </summary> protected QueryProducerBase(INoSqlContext _context) { context = _context; }
/// <summary> /// Construtor /// </summary> public StateQueryProducer(INoSqlContext _context) : base(_context) { }
public void SetNoSqlContext(INoSqlContext context) { noSqlContext = context; }
/// <summary> /// /// </summary> protected QueryProducerDefault(INoSqlContext _context) : base(_context) { }
public static void SetNoSqlContext(string profile, INoSqlContext ctx) { ContextGroup grp = GetContextGroup(profile); grp.NoSqlContext = ctx; }
public static void SetNoSqlContext(INoSqlContext ctx) { ContextGroup grp = GetContextGroup(FactoryContextUtils.DefaultProfileName); grp.NoSqlContext = ctx; }
/// <summary> /// Construtor /// </summary> public StateFindAllNoPage(INoSqlContext _context, QueryProducerDefault <State, StateDTO, StateFilter> _queryProducer) : base(_context, _queryProducer) { }
/// <summary> /// Construtor /// </summary> protected BaseRepo(INoSqlContext _context) { context = _context; }