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 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); }
private void WriteExportFile(BarcodeProfileBase prf, MBarcode bc, MBarcode param) { string csvLine = String.Format("=\"{0}\",=\"{1}\",\"{2}\",\"{3}\",\"{4}\"", bc.SerialNumber, bc.Pin, bc.PayloadUrl, param.Barcode, prf.CompanyWebSite); string txtLine = String.Format("{0},{1},{2},{3},{4}", bc.SerialNumber, bc.Pin, bc.PayloadUrl, param.Barcode, prf.CompanyWebSite); LogUtils.LogInformation(logger, txtLine); txtStream.WriteLine(txtLine); csvStream.WriteLine(csvLine); }
protected override void ValidateActivation(MRegistration dat, MBarcode bc, string barcode) { if (bc.IsActivated) { return; } string msg = PostData(dat, barcode, "FAILED", "Serial number and PIN has not been registered yet [{0}]"); throw (new ArgumentException(msg)); }
private bool IsBarcodeExisting(string serialNumber, string pin) { string bcPath = BarcodeUtils.BuildBarcodePath("barcodes", serialNumber, pin); MBarcode bc = ctx.GetObjectByKey <MBarcode>(bcPath); if (bc != null) { return(true); } return(false); }
public override MemoryStream RenderToStream(BaseModel data) { MBarcode bc = (MBarcode)data; string tmpFile = string.Format("{0}_{1}.png", bc.SerialNumber, bc.Pin); string qrFile = CreateQR(tmpFile, bc.PayloadUrl); var ms = ParseTemplate(htmlConverter, templateLines, bc, qrFile); return(ms); }
protected override void ValidateActivation(MRegistration dat, MBarcode bc, string barcode) { if (!bc.IsActivated) { return; } string msgTemplate = string.Format("Serial number and PIN has already been registered [{0}] since [{1}]", "{0}", bc.ActivatedDate); string msg = PostData(dat, barcode, "FAILED", msgTemplate); throw (new ArgumentException(msg)); }
public IActionResult WebCheck(MBarcode form) { form.SerialNumber = StringUtils.StripTagsRegex(form.SerialNumber); form.Pin = StringUtils.StripTagsRegex(form.Pin); MRegistration param = new MRegistration(); param.IP = RemoteUtils.GetRemoteIPAddress(ControllerContext); param.Pin = form.Pin; param.SerialNumber = form.SerialNumber; return(VerifyProduct(param)); }
private void BarcodeGenerateProgressUpdate(MBarcode bc, string dir) { generatedCount++; string fileName = string.Format("{0}/{1}-{2}.png", dir, bc.SerialNumber, bc.Pin); bool isExist = File.Exists(fileName); if (imgGenerateFlag) { Assert.AreEqual(true, isExist, "File not found [{0}] !!!", fileName); } else { Assert.AreEqual(false, isExist, "File should not be created [{0}] !!!", fileName); } }
private void CreateExportFile(string profile, MBarcode param, string outputPath, string timeStamp) { string exportFile = string.Format("{0}_{1}_{2}", profile, param.BatchNo, timeStamp); string[] paths = { outputPath, exportFile }; string exportPath = Path.Combine(paths); string csvFile = String.Format("{0}.csv", exportPath); string txtFile = String.Format("{0}.txt", exportPath); txtStream = new StreamWriter(txtFile); txtStream.WriteLine("Serial, PIN, QR (Url), Barcode, Web Site"); csvStream = new StreamWriter(csvFile); csvStream.WriteLine("Serial, PIN, QR (Url), Barcode, Web Site"); }
public void CreateRegistrationWithCodeNotFoundTest(bool barcodeFound, bool isActivated, string keyword) { MockedNoSqlContext ctx = new MockedNoSqlContext(); FactoryBusinessOperation.SetNoSqlContext(ctx); if (barcodeFound) { MBarcode bc = new MBarcode(); bc.IsActivated = isActivated; ctx.SetReturnObjectByKey(bc); } var opt = (IBusinessOperationManipulate <MRegistration>)FactoryBusinessOperation.CreateBusinessOperationObject("CreateRegistration"); MRegistration rg = new MRegistration(); rg.Pin = "9999999999"; rg.SerialNumber = "ABCDEFGHIJKLM"; rg.IP = "192.168.0.1"; bool shouldThrow = !barcodeFound || isActivated; if (shouldThrow) { try { opt.Apply(rg); Assert.Fail("Exception should be thrown here!!!"); } catch (Exception ex) { string msg = ex.Message; bool foundKeyword = msg.Contains(keyword); Assert.AreEqual(true, foundKeyword, "Should get [{0}] error!!!", keyword); } } else { //Found barcode and not yet activated opt.Apply(rg); //Status wrote back to input parameter Assert.AreEqual("SUCCESS", rg.Status); } }
public void CreateBarcodeWithMigrationModeTest(string serial, string pin, string payload) { INoSqlContext ctx = new Mock <INoSqlContext>().Object; FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationGetInfo <MBarcode>)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode"); MBarcode bc = new MBarcode(); bc.SerialNumber = serial; bc.Pin = pin; bc.PayloadUrl = payload; MBarcode barcode1 = opt.Apply(bc); Assert.AreEqual(serial, barcode1.SerialNumber, "SerialNumber must be the same!!!"); Assert.AreEqual(pin, barcode1.Pin, "Pin must be the same!!!"); Assert.AreEqual(payload, barcode1.PayloadUrl, "Payload URL must be the same!!!"); }
public void RegisterWebSuccess(String serial, String pin) { mockOpr.Setup(foo => foo.Apply(It.IsAny <MRegistration>())).Returns(0); MBarcode form = new MBarcode(); form.SerialNumber = serial; form.Pin = pin; ViewResult result = (ViewResult)controller.WebCheck(form); List <object> keys = new List <object>(result.ViewData.Keys); List <object> values = new List <object>(result.ViewData.Values); Assert.AreEqual(keys[0], "Serial"); Assert.AreEqual(keys[1], "PIN"); Assert.AreEqual(values[0], serial); Assert.AreEqual(values[1], pin); Assert.AreEqual(result.ViewName, "Success"); }
public void ResetBarcodeTest(string appName, bool IsActivated) { ResetBarcodeApplication app = (ResetBarcodeApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName); OptionSet opt = app.CreateOptionSet(); opt.Parse(args); MockedNoSqlContext ctx = new MockedNoSqlContext(); MBarcode barcode = new MBarcode(); barcode.IsActivated = IsActivated; ctx.SetReturnObjectByKey(barcode); app.SetNoSqlContext(ctx); //To cover test coverage app.GetLogger(); app.Run(); Assert.True(true); }
public int Apply(MRegistration dat) { ValidateRegistration(dat); string barcode = string.Format("{0}-{1}", dat.SerialNumber, dat.Pin); MBarcode bc = null; string bcPath = null; var ctx = GetNoSqlContext(); if ((dat.SerialNumber.Length > 3) && (dat.Pin.Length > 3)) { bcPath = BarcodeUtils.BuildBarcodePath("barcodes", dat.SerialNumber, dat.Pin); bc = ctx.GetObjectByKey <MBarcode>(bcPath); } if (bc == null) { string msg = PostData(dat, barcode, "NOTFOUND", "Serial number and PIN not found [{0}]"); throw (new ArgumentException(msg)); } dat.RegistrationDate = DateTime.Now; dat.LastMaintDate = DateTime.Now; ValidateActivation(dat, bc, barcode); //Update status back to barcode bc.IsActivated = GetActivateFlag(); bc.ActivatedDate = DateTime.Now; bc.LastMaintDate = DateTime.Now; ctx.PutData(bcPath, bc.Key, bc); PerformRegistrationAction(dat, barcode); return(0); }
public void CreateBarcodeWithRandomStringTest() { INoSqlContext ctx = new Mock <INoSqlContext>().Object; FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationGetInfo <MBarcode>)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode"); MBarcode bc = new MBarcode(); bc.Url = "http://this_is_fake_url"; bc.Path = "this/is/faked/path"; MBarcode barcode1 = opt.Apply(bc); string playLoad1 = string.Format("{0}/verification/{1}/{2}/{3}", bc.Url, bc.Path, barcode1.SerialNumber, barcode1.Pin); MBarcode barcode2 = opt.Apply(bc); string playLoad2 = string.Format("{0}/verification/{1}/{2}/{3}", bc.Url, bc.Path, barcode2.SerialNumber, barcode2.Pin); Assert.AreNotEqual(barcode1.SerialNumber, barcode2.SerialNumber, "SerialNumber must be different!!!"); Assert.AreNotEqual(barcode1.Pin, barcode2.Pin, "PIN must be different!!!"); Assert.AreEqual(playLoad1, barcode1.PayloadUrl, "Payload URL incorrect!!!"); Assert.AreEqual(playLoad2, barcode2.PayloadUrl, "Payload URL incorrect!!!"); }
protected abstract void ValidateActivation(MRegistration dat, MBarcode bc, string barcode);
public void WriteBarcode(PointF origin, float height, int horAlign, int verAlign, string text) { _assertPage(); origin.Y += _currentPage.OriginY; MBarcode barcode = new MBarcode(_currentPage, origin, height, horAlign, verAlign, text); _currentPage.Content.Add(barcode); }
public virtual MBarcode InsertData(MBarcode bc) { CreateBarcode opr = GetCreateBarcodeOperation(); return(opr.Apply(bc)); }
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); }
protected override void TemplateParsing(BaseModel data, string qrImageFile) { currentData = (MBarcode)data; currentQRfile = qrImageFile; }
private void BarcodeGenerateProgressUpdate(MBarcode bc, string dir) { //Put any progress update here }