public void ShouldCallClientWhenCreatingIndex() { //Arrange _clientMock .Setup(x => x.IndexExists(_indexName, string.Empty)) .Returns(false); _clientMock .Setup(x => x.CreateIndex(_indexName, It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >(), string.Empty)) .Returns(new Elasticsearch.CreateIndexResponse { HttpStatusCode = (int)HttpStatusCode.OK }); //Act _sut = new ElasticSearchIndexProvider(_clientMock.Object, _loggerMock.Object, _settings.Object); _sut.CreateIndex <UserSearchModel>(_indexName); //Assert _clientMock .Verify(x => x.IndexExists(_indexName, string.Empty), Times.AtLeastOnce); _clientMock .Verify( x => x.CreateIndex(_indexName, It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >(), string.Empty), Times.AtLeastOnce); }
public void ShouldThrowExceptionWhenIndexCreationStatusIsNotOk() { //Arrange _clientMock .Setup(x => x.CreateIndex(_indexName, It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >(), string.Empty)) .Returns(new Elasticsearch.CreateIndexResponse { HttpStatusCode = (int)HttpStatusCode.BadRequest }) .Verifiable(); //Act _sut = new ElasticSearchIndexProvider(_clientMock.Object, _loggerMock.Object, _settings.Object); Action action = () => _sut.CreateIndex <UserSearchModel>(_indexName); //Assert action.ShouldThrow <Exception>(); }