Ejemplo n.º 1
0
        public async Task CanImportBitmapImageResource()
        {
            var script = @"
import imageData from 'resources/alias.bmp';

export default class Builder {
    build(model) {
        return [imageData.width, imageData.height, imageData.data.length, imageData.data[0], imageData.data[1], imageData.data[2], imageData.data[3]];
    }
}";

            using var bitmap = new Bitmap(2, 2);
            using var stream = new MemoryStream();
            bitmap.SetPixel(0, 0, Color.FromArgb(red: 1, green: 2, blue: 3, alpha: 255));
            bitmap.Save(stream, ImageFormat.Bmp);

            var resources = new DictionaryResourceManager()
            {
                ["alias.bmp"] = stream.ToArray()
            };

            var result = await _generator.GenerateDocumentAsync(script, null, resources);

            Assert.Equal(2, result.Content[0]);
            Assert.Equal(2, result.Content[1]);
            Assert.Equal(16, result.Content[2]);
            Assert.Equal(1, result.Content[3]);
            Assert.Equal(2, result.Content[4]);
            Assert.Equal(3, result.Content[5]);
            Assert.Equal(255, result.Content[6]);
        }
Ejemplo n.º 2
0
        public async Task CanImportLargeBitmapImageResource(int asyncLoadDelay)
        {
            var script = @"
import imageData from 'resources/havnebakken.bmp';

export default class Builder {
    build(model) {
        return JSON.stringify([imageData.width, imageData.height, imageData.data.length]);
    }
}";

            var resources = new DictionaryResourceManager()
            {
                ["havnebakken.bmp"] = File.ReadAllBytes("havnebakken.bmp")
            };

            resources.AsyncLoadDelay = TimeSpan.FromMilliseconds(asyncLoadDelay);

            var result = await _generator.GenerateDocumentAsync(script, null, resources);

            var array = JsonSerializer.Deserialize <int[]>(Encoding.UTF8.GetString(result.Content));

            Assert.Equal(350, array[0]);
            Assert.Equal(260, array[1]);
            Assert.Equal(350 * 260 * 4, array[2]);
        }
        public async Task Receipt_New(int asyncLoadDelay)
        {
            var model = new ReceiptModel()
            {
                vendorDataResource = "havnebakken.json",
                slipId             = 317579,
                @case = new CaseModel()
                {
                    id                    = 1538006,
                    packageId             = 1,
                    itemId                = 1,
                    createdByEmployeeName = "Malene",
                    note                  = null,
                    arrived               = new DateTime(2020, 3, 20, 19, 31, 0).ToString("o"),
                    departed              = null,
                },
                lines =
                {
                    new ReceiptModel.Line()
                    {
                        name = "Fish and chips UAH", quantity = 1, unitPrice = 55, discount = 0
                    }
                },
                itemName = " 6",
                printedByEmployeeName = "Malene",
                grossTotal            = 55,
                discountTotal         = 0,
                netTotal     = 55,
                netTaxTotal  = 11,
                netEuroTotal = 7.53m,
                printed      = new DateTime(2020, 3, 20, 19, 31, 0).ToString("o"),
            };

            var resources = new DictionaryResourceManager()
            {
                ["havnebakken.json"] = JsonSerializer.SerializeToUtf8Bytes(new
                {
                    logoResource   = "havnebakken.bmp",
                    address        = "Havnebakken 12",
                    postalCode     = 9940,
                    city           = "Læsø",
                    phone          = 98499009,
                    cvr            = 20041846,
                    email          = "*****@*****.**",
                    logoOffsetLeft = 100
                }),
                ["havnebakken.bmp"] = File.ReadAllBytes("havnebakken.bmp")
            };

            resources.AsyncLoadDelay = TimeSpan.FromMilliseconds(asyncLoadDelay);

            var result = await _generator.GenerateDocumentAsync(_script, model, resources);

            var expected = File.ReadAllBytes(Path.Combine("Expected", "ReceiptStarLinePointOfSaleTypeScriptGeneratorTests.Receipt_New.bin"));

            Assert.Equal(BitConverter.ToString(expected), BitConverter.ToString(result.Content));
        }
Ejemplo n.º 4
0
        public async Task CanDynamicImportJsonResource()
        {
            var script = @"
export default class Builder {
    async build(model) {
        let { default: obj } = await import('resources/alias.json');
        return obj.name;
    }
}";

            var resources = new DictionaryResourceManager()
            {
                ["alias.json"] = JsonSerializer.SerializeToUtf8Bytes(new { name = "Rasmus" })
            };

            var result = await _generator.GenerateDocumentAsync(script, null, resources);

            Assert.Equal("Rasmus", Encoding.UTF8.GetString(result.Content));
        }
Ejemplo n.º 5
0
        public async Task CanImportBinaryResource()
        {
            var script = @"
import array from 'resources/alias.bin';

export default class Builder {
    build(model) {
        return [array.length, array[0]];
    }
}";

            var resources = new DictionaryResourceManager()
            {
                ["alias.bin"] = new byte[] { 0xA0 }
            };

            var result = await _generator.GenerateDocumentAsync(script, null, resources);

            Assert.Equal(1, result.Content[0]);
            Assert.Equal(0xA0, result.Content[1]);
        }
Ejemplo n.º 6
0
        public async Task ThrowsIfDynamicImportOfInvalidResource()
        {
            var script = @"
export default class Builder {
    async build(model) {
        const { default: obj } = await import('resources/invalid.json');
        return obj.name;
    }
}";

            var resources = new DictionaryResourceManager()
            {
            };

            await Assert.ThrowsAsync <JavaScriptScriptException>(async() =>
            {
                var result = await _generator.GenerateDocumentAsync(script, null, resources);

                Assert.Equal("Rasmus", Encoding.UTF8.GetString(result.Content));
            });
        }
Ejemplo n.º 7
0
        public async Task Receipt_New(int asyncLoadDelay)
        {
            var model = new ReceiptModel()
            {
                vendorDataResource = "laesoecamping.json",
                slipId             = 60558,
                @case = new CaseModel()
                {
                    id                    = 1028947,
                    packageId             = 1,
                    itemId                = 1,
                    createdByEmployeeName = "Karina",
                    note                  = null,
                    arrived               = new DateTime(2016, 5, 8, 8, 27, 0).ToString("o"),
                    departed              = null,
                },
                lines =
                {
                    new ReceiptModel.Line()
                    {
                        name = "Varesalg Butik", quantity = 1, unitPrice = 10, discount = 0
                    },
                    new ReceiptModel.Line()
                    {
                        name = "0,5 Sodavand", quantity = 1, unitPrice = 20, discount = 0
                    },
                    new ReceiptModel.Line()
                    {
                        name = "0,5 Sodavand", quantity = 1, unitPrice = 20, discount = 0
                    },
                    new ReceiptModel.Line()
                    {
                        name = "Varesalg Butik", quantity = 1, unitPrice = 45, discount = 0
                    }
                },
                itemName = "Kasse",
                printedByEmployeeName = "Karina",
                grossTotal            = 95,
                discountTotal         = 0,
                netTotal     = 95,
                netTaxTotal  = 19,
                netEuroTotal = 12.84m,
                printed      = new DateTime(2016, 5, 8, 10, 14, 0).ToString("o"),
            };

            var resources = new DictionaryResourceManager()
            {
                ["laesoecamping.json"] = JsonSerializer.SerializeToUtf8Bytes(new
                {
                    logoResource   = "laesoecamping.bmp",
                    address        = "Agersigen 18a",
                    postalCode     = 9940,
                    city           = "Læsø",
                    phone          = 98499495,
                    cvr            = 31840902,
                    email          = "*****@*****.**",
                    logoOffsetLeft = 100
                }),
                ["laesoecamping.bmp"] = File.ReadAllBytes("laesoecamping.bmp")
            };

            resources.AsyncLoadDelay = TimeSpan.FromMilliseconds(asyncLoadDelay);

            var result = await _generator.GenerateDocumentAsync(_script, model, resources);

            var expected = File.ReadAllBytes(Path.Combine("Expected", "ReceiptEpsonPointOfSaleTypeScriptGeneratorTests.Receipt_New.bin"));

            Assert.Equal(BitConverter.ToString(expected), BitConverter.ToString(result.Content));
        }