Beispiel #1
0
        public async Task CommitTimeStampDataIsCorrect()
        {
            // Arrange
            var token               = new CancellationToken();
            var httpClientMock      = new Mock <IHttpClientWrapper>();
            var luceneExpectedTicks = 5;

            httpClientMock.Setup(hcm => hcm.GetAsync(It.Is <string>(it => it.Equals("Lucene-DiagUrl")), HttpCompletionOption.ResponseContentRead, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult((IHttpResponseMessageWrapper) new TestHttpResponseMessage(HttpStatusCode.OK, JsonConvert.SerializeObject(new SearchDiagnosticResponse
            {
                CommitUserData = new CommitUserData
                {
                    CommitTimeStamp = new DateTimeOffset(luceneExpectedTicks, new TimeSpan(0)).ToString()
                },
                LastIndexReloadTime = new DateTimeOffset(luceneExpectedTicks, new TimeSpan(0))
            }))));
            httpClientMock.Setup(hcm => hcm.GetAsync(It.Is <string>(it => it.Equals("Azure-DiagUrl")), HttpCompletionOption.ResponseContentRead, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult((IHttpResponseMessageWrapper) new TestHttpResponseMessage(HttpStatusCode.OK, JsonConvert.SerializeObject(new AzureSearchDiagnosticResponse
            {
                SearchIndex = new IndexInformation
                {
                    LastCommitTimestamp = new DateTimeOffset()
                }
            }))));
            var searchClient = new SearchServiceClient(httpClientMock.Object, _logger);

            var azureStartTimestamp = DateTime.UtcNow;

            var azureResponse = await searchClient.GetIndexLastReloadTimeAsync(_azureSearchInstance, token);

            var azureStopTimestamp = DateTime.UtcNow;

            Assert.InRange(azureResponse, azureStartTimestamp, azureStopTimestamp);
        }