public async Task ComplexObject() { var httpClientMock = new Mock <HttpClient>(); HttpRequestMessage recordedMessage = null; httpClientMock .Setup(httpClient => httpClient.SendAsync( It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.OK)) .Callback <HttpRequestMessage, CancellationToken>((message, token) => recordedMessage = message); var options = new ElasticSearchTelemetryReplicatorOptions { BulkEndPoint = new Uri("http://localhost:12345", UriKind.Absolute), HttpClientFactory = () => httpClientMock.Object, IndexSelector = _ => new IndexDefinition { Index = "ai", Type = "telemetry" }, }; var sut = new ElasticSearchTelemetryReplicator(options, new DummyLoggerFactory()); var expected = ComplexSampleObjects; var jarray = JArray.FromObject(expected); await sut.ReplicateAsync(jarray, Enumerable.Empty <KeyValuePair <string, IEnumerable <string> > >()); var body = await recordedMessage.Content.ReadAsStringAsync(); var list = body.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); int odd = 0; var json = $"[{string.Join(",", list.Where(item => (++odd % 2) == 0))}]"; var actual = JsonConvert.DeserializeObject <ComplexSample[]>(json); Assert.Equal(expected.Length, actual.Length); for (int i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], actual[i]); } }
public void Throws_ArgumentException_with_invalid_options(ElasticSearchTelemetryReplicatorOptions options) { Assert.Throws <ArgumentException>( () => new ElasticSearchTelemetryReplicator(options, Mock.Of <ILoggerFactory>())); }