static void GenerateQR(IBarcodeApi api, string fileName) { using (Stream generated = api.GetBarcodeGenerate( new GetBarcodeGenerateRequest( EncodeBarcodeType.QR.ToString(), "QR code text", textLocation: "None", format: "png")) ) { using (FileStream stream = File.Create(fileName)) { generated.CopyTo(stream); } } }
public void GetBarcodeGenerateTest() { // Arrange var request = new GetBarcodeGenerateRequest( text: "Very sample text", type: EncodeBarcodeType.Code128.ToString(), format: "png" ); // Act using Stream response = _api.GetBarcodeGenerate(request); // Assert Assert.IsTrue(response.Length > 0); using FileStream savedFileStream = File.Create(TestFilePath("Test_GetBarcodeGenerate.png")); response.CopyTo(savedFileStream); }
public void GenerateAndThenRecognizeTest() { Stream generated = _api.GetBarcodeGenerate(new GetBarcodeGenerateRequest( EncodeBarcodeType.QR.ToString(), "Test")); BarcodeResponseList recognized = _api.PostBarcodeRecognizeFromUrlOrContent( new PostBarcodeRecognizeFromUrlOrContentRequest( image: generated )); Assert.AreEqual(1, recognized.Barcodes.Count); Assert.AreEqual(DecodeBarcodeType.QR.ToString(), recognized.Barcodes.First().Type); Assert.AreEqual("Test", recognized.Barcodes.First().BarcodeValue); Assert.AreEqual( "{\"barcodes\":[{" + "\"barcodeValue\":\"Test\"," + "\"type\":\"QR\"," + "\"region\":[{\"x\":7,\"y\":7},{\"x\":49,\"y\":7},{\"x\":49,\"y\":49},{\"x\":7,\"y\":49}]," + "\"checksum\":null}]}", recognized.ToString() ); }