Beispiel #1
0
        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 GetBarcodeGenerateTestThrows()
        {
            // Arrange
            var api     = new BarcodeApi(clientId: "client id", clientSecret: "client secret");
            var request = new GetBarcodeGenerateRequest(
                text: "Very sample text",
                type: EncodeBarcodeType.Code128.ToString(),
                format: "png"
                );

            // Act
            var ex = Assert.Throws <ApiException>(
                () => { api.GetBarcodeGenerate(request); });

            Assert.AreEqual(400, ex.ErrorCode);
            Assert.AreEqual("Bad Request", ex.Message);
        }
        /// <summary>
        ///     Generate barcode.
        /// </summary>
        /// <param name="request">Request. <see cref="GetBarcodeGenerateRequest" /></param>
        /// <returns>
        ///     <see cref="System.IO.Stream" />
        /// </returns>
        public System.IO.Stream GetBarcodeGenerate(GetBarcodeGenerateRequest request)
        {
            // verify the required parameter 'type' is set
            if (request.Type == null)
            {
                throw new ApiException(400, "Missing required parameter 'type' when calling GetBarcodeGenerate");
            }
            // verify the required parameter 'text' is set
            if (request.Text == null)
            {
                throw new ApiException(400, "Missing required parameter 'text' when calling GetBarcodeGenerate");
            }
            // create path and map variables
            string resourcePath = _configuration.GetApiRootUrl() + "/barcode/generate";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "type", request.Type);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "text", request.Text);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "twoDDisplayText", request.TwoDDisplayText);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "textLocation", request.TextLocation);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "textAlignment", request.TextAlignment);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "textColor", request.TextColor);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "fontSizeMode", request.FontSizeMode);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "noWrap", request.NoWrap);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "resolution", request.Resolution);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "resolutionX", request.ResolutionX);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "resolutionY", request.ResolutionY);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "dimensionX", request.DimensionX);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "textSpace", request.TextSpace);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "units", request.Units);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "sizeMode", request.SizeMode);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "barHeight", request.BarHeight);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "imageHeight", request.ImageHeight);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "imageWidth", request.ImageWidth);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "rotationAngle", request.RotationAngle);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "backColor", request.BackColor);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "barColor", request.BarColor);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "borderColor", request.BorderColor);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "borderWidth", request.BorderWidth);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "borderDashStyle", request.BorderDashStyle);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "borderVisible", request.BorderVisible);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "enableChecksum", request.EnableChecksum);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "enableEscape", request.EnableEscape);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "filledBars", request.FilledBars);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "alwaysShowChecksum", request.AlwaysShowChecksum);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "wideNarrowRatio", request.WideNarrowRatio);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "validateText", request.ValidateText);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "supplementData", request.SupplementData);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "supplementSpace", request.SupplementSpace);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "barWidthReduction", request.BarWidthReduction);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "format", request.format);


            return(_apiInvoker.InvokeBinaryApi(
                       resourcePath,
                       "GET",
                       null,
                       null,
                       null));
        }