public async Task <IActionResult> ExportDevicesReport([FromQuery] string query, [FromBody] List <ColumnMappingModel> columnMapping)
        {
            var deviceList = new DeviceListApiModel(await this.devices.GetListAsync(query, null));

            var stream = new MemoryStream();

            using (SpreadsheetDocument package = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook))
            {
                this.CreatePartsForExcel(package, deviceList.Items, columnMapping);
            }

            stream.Position = 0;
            string excelName = $"DeploymentReport-{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";

            return(this.File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName));
        }
Esempio n. 2
0
        public async Task GetListAsyncTest()
        {
            var conditions = Enumerable.Range(0, rand.Next(3, 10)).Select(i => new DeviceGroupConditionApiModel
            {
                Key      = rand.NextString(),
                Operator = rand.NextString(),
                Value    = rand.NextString()
            }).ToList();
            var query = JsonConvert.SerializeObject(conditions);

            var deviceList = Enumerable.Range(0, rand.Next(3, 10)).Select(i => new DeviceApiModel
            {
                Id = rand.NextString()
            }).ToList();
            var model = new DeviceListApiModel
            {
                Items = deviceList
            };

            mockHttpClient
            .Setup(x => x.GetAsync <DeviceListApiModel>(
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <bool>()))
            .ReturnsAsync(model);

            var result = await devices.GetListAsync(conditions);

            Assert.True(result.OrderBy(id => id).SequenceEqual(deviceList.Select(d => d.Id).OrderBy(id => id)));

            mockHttpClient
            .Verify(x => x.GetAsync <DeviceListApiModel>(
                        It.Is <string>(s => s == $"{config.DevicesUrl}/devices?query={query}"),
                        It.IsAny <string>(),
                        It.Is <bool>(b => !b)),
                    Times.Once);
        }