public async Task AssertPropertiesConfigured()
        {
            var ingest = new Mock <IKustoIngestClient>();
            KustoIngestionProperties props = null;

            ingest.Setup(i => i.IngestFromStreamAsync(
                             It.IsAny <Stream>(),
                             It.IsAny <KustoIngestionProperties>(),
                             It.IsAny <StreamSourceOptions>()))
            .Callback((Stream s, KustoIngestionProperties p, StreamSourceOptions o) => { props = p; })
            .Returns(Task.FromResult(Mock.Of <IKustoIngestionResult>()));

            await KustoHelpers.WriteDataToKustoInMemoryAsync(ingest.Object,
                                                             "TEST-DATABASE",
                                                             "TEST-TABLE",
                                                             new NUnitLogger(),
                                                             new[] { 1 },
                                                             v => new[]
            {
                new KustoValue("columnName", 1, KustoDataType.Int),
            }
                                                             );

            props.Should().NotBeNull();
            props.DatabaseName.Should().Be("TEST-DATABASE");
            props.TableName.Should().Be("TEST-TABLE");
        }
        public async Task BasicSend(object inputValue, KustoDataType dataType, string representation)
        {
            string saved  = null;
            var    ingest = new Mock <IKustoIngestClient>();

            ingest.Setup(i => i.IngestFromStreamAsync(
                             It.IsAny <Stream>(),
                             It.IsAny <KustoIngestionProperties>(),
                             It.IsAny <StreamSourceOptions>()))
            .Callback((Stream s, KustoIngestionProperties p, StreamSourceOptions o) =>
            {
                saved = new StreamReader(s).ReadToEnd();
            })
            .Returns(Task.FromResult(Mock.Of <IKustoIngestionResult>()));

            await KustoHelpers.WriteDataToKustoInMemoryAsync(ingest.Object,
                                                             "TEST-DATABASE",
                                                             "TEST-TABLE",
                                                             new NUnitLogger(),
                                                             new[] { inputValue },
                                                             v => new[]
            {
                new KustoValue("columnName", v, dataType),
            }
                                                             );

            string[][] parsed = CsvWriterExtensions.ParseCsvFile(saved);
            parsed.Should().ContainSingle();
            parsed[0].Should().ContainSingle();
            parsed[0][0].Should().Be(representation);
        }
Example #3
0
        public async Task <IActionResult> CollectArcadeValidation([Required] ArcadeValidationData data)
        {
            KustoOptions options = _options.Value;

            if (string.IsNullOrEmpty(options.IngestConnectionString))
            {
                throw new InvalidOperationException("No IngestConnectionString set");
            }

            List <ArcadeValidationData> arcadeValidationDatas = new List <ArcadeValidationData> {
                data
            };

            await KustoHelpers.WriteDataToKustoInMemoryAsync(
                _clientFactory.GetClient(),
                options.Database,
                "ArcadeValidation",
                _logger,
                arcadeValidationDatas,
                b => new[]
            {
                new KustoValue("BuildDateTime", b.BuildDateTime, KustoDataType.DateTime),
                new KustoValue("ArcadeVersion", b.ArcadeVersion, KustoDataType.String),
                new KustoValue("BARBuildID", b.BARBuildID, KustoDataType.Int),
                new KustoValue("ArcadeBuildLink", b.ArcadeBuildLink, KustoDataType.String),
                new KustoValue("ArcadeValidationBuildLink", b.ArcadeValidationBuildLink, KustoDataType.String),
                new KustoValue("ProductRepoName", b.ProductRepoName, KustoDataType.String),
                new KustoValue("ProductRepoBuildLink", b.ProductRepoBuildLink, KustoDataType.String),
                new KustoValue("ProductRepoBuildResult", b.ProductRepoBuildResult, KustoDataType.String),
                new KustoValue("ArcadeDiffLink", b.ArcadeDiffLink, KustoDataType.String)
            });

            return(Ok());
        }
Example #4
0
 private async Task IngestTriageItemsIntoKusto(ICollection <TriageItem> triageItems)
 {
     _logger.LogInformation("Entering IngestTriageItemIntoKusto");
     await KustoHelpers.WriteDataToKustoInMemoryAsync(
         _kustoIngestClientFactory.GetClient(),
         _kustoOptions.Value.Database,
         "TimelineIssuesTriage",
         _logger,
         triageItems,
         b => new[]
     {
         new KustoValue("ModifiedDateTime", b.ModifiedDateTime, KustoDataType.DateTime),
         new KustoValue("BuildId", b.BuildId, KustoDataType.Int),
         new KustoValue("RecordId", b.RecordId, KustoDataType.Guid),
         new KustoValue("Index", b.Index, KustoDataType.Int),
         new KustoValue("UpdatedCategory", b.UpdatedCategory, KustoDataType.String),
         new KustoValue("Url", b.Url, KustoDataType.String)
     });
 }
        public async Task EmptyWriteTestShouldNotSend()
        {
            var ingest = new Mock <IKustoIngestClient>();

            ingest.Setup(i => i.IngestFromStreamAsync(
                             It.IsAny <Stream>(),
                             It.IsAny <KustoIngestionProperties>(),
                             It.IsAny <StreamSourceOptions>()))
            .Returns(Task.FromResult(Mock.Of <IKustoIngestionResult>()))
            .Verifiable();

            await KustoHelpers.WriteDataToKustoInMemoryAsync(ingest.Object,
                                                             "TEST-DATABASE",
                                                             "TEST-TABLE",
                                                             new NUnitLogger(),
                                                             Enumerable.Empty <int>(),
                                                             null);

            ingest.VerifyNoOtherCalls();
        }
 private static async Task IngestTriageItemsIntoKusto(TriageItem[] triageItems, ILogger log)
 {
     log.LogInformation("Entering IngestTriageItemIntoKusto");
     string             kustoIngestConnectionString = System.Environment.GetEnvironmentVariable("KustoIngestConnectionString");
     string             databaseName = System.Environment.GetEnvironmentVariable("KustoDatabaseName");
     IKustoIngestClient ingestClient = KustoIngestFactory.CreateQueuedIngestClient(kustoIngestConnectionString);
     await KustoHelpers.WriteDataToKustoInMemoryAsync(
         ingestClient,
         databaseName,
         "TimelineIssuesTriage",
         log,
         triageItems,
         b => new[]
     {
         new KustoValue("ModifiedDateTime", b.ModifiedDateTime.ToString(), KustoDataTypes.DateTime),
         new KustoValue("BuildId", b.BuildId.ToString(), KustoDataTypes.Int),
         new KustoValue("RecordId", b.RecordId.ToString(), KustoDataTypes.Guid),
         new KustoValue("Index", b.Index.ToString(), KustoDataTypes.Int),
         new KustoValue("UpdatedCategory", b?.UpdatedCategory, KustoDataTypes.String),
         new KustoValue("Url", b?.Url, KustoDataTypes.String)
     });
 }
        public async Task HandlesFieldsInAnyOrder()
        {
            var ingest = new Mock <IKustoIngestClient>();

            await(((Func <Task>)(() => KustoHelpers.WriteDataToKustoInMemoryAsync(ingest.Object,
                                                                                  "TEST-DATABASE",
                                                                                  "TEST-TABLE",
                                                                                  new NUnitLogger(),
                                                                                  new[] { 1, 2 },
                                                                                  v => v switch
            {
                1 => new[]
                {
                    new KustoValue("a", 1, KustoDataType.Int),
                    new KustoValue("b", "bValue1", KustoDataType.String),
                },
                2 => new[]
                {
                    new KustoValue("b", "bValue2", KustoDataType.String),
                    new KustoValue("a", 2, KustoDataType.Int),
                },
                _ => throw new ArgumentOutOfRangeException()
            }