public void ShouldDeleteOnlyOldIndexes()
        {
            var indexToDelete01 = "at-das-support-portal-account_20180119100000";
            var indexToDelete02 = "at-das-support-portal-account_20180119103000";
            var indexToKeep01   = "at-das-support-portal-account_20180119110000";
            var indexToKeep02   = "at-das-support-portal-account_20180119113000";
            //Arrange
            var indexList = new Dictionary <string, IndicesStats>();

            indexList.Add(indexToDelete01, new IndicesStats());
            indexList.Add(indexToKeep01, new IndicesStats());
            indexList.Add(indexToDelete02, new IndicesStats());
            indexList.Add(indexToKeep02, new IndicesStats());

            var readOnlyMockResult = new ReadOnlyDictionary <string, IndicesStats>(indexList);

            var indicesStatsResult = new Elasticsearch.IndicesStatsResponse {
                Indices = readOnlyMockResult
            };

            _clientMock
            .Setup(x => x.IndicesStats(Indices.All, null, It.IsAny <string>()))
            .Returns(indicesStatsResult)
            .Verifiable();

            var deleteResponse = new Elasticsearch.DeleteIndexResponse {
                Acknowledged = true
            };

            _clientMock
            .Setup(x => x.DeleteIndex(It.IsAny <IndexName>(), It.IsAny <string>()))
            .Returns(deleteResponse)
            .Verifiable();

            //Act
            _sut = new ElasticSearchIndexProvider(_clientMock.Object, _loggerMock.Object, _settings.Object);
            _sut.DeleteIndexes(2, "at-das-support-portal-account");

            ////Assert

            _clientMock
            .Verify(x => x.DeleteIndex(indexToDelete01, It.IsAny <string>()), Times.Once);

            _clientMock
            .Verify(x => x.DeleteIndex(indexToDelete02, It.IsAny <string>()), Times.Once);

            _clientMock
            .Verify(x => x.DeleteIndex(It.IsAny <IndexName>(), It.IsAny <string>()), Times.Exactly(2));
        }
        public void ShouldThrowExceptiontWhenIndexDeletionRespnseIsInValid()
        {
            //Arrange
            Elasticsearch.DeleteIndexResponse deleteResponse = null;

            _clientMock
            .Setup(x => x.DeleteIndex(_indexName, string.Empty))
            .Returns(deleteResponse);

            //Act
            _sut = new ElasticSearchIndexProvider(_clientMock.Object, _loggerMock.Object, _settings.Object);
            Action action = () => _sut.DeleteIndex(_indexName);

            //Assert
            action.ShouldThrow <Exception>();
        }
        public void ShouldCallClientWhenDeletingIndex()
        {
            //Arrange
            var deleteResponse = new Elasticsearch.DeleteIndexResponse {
                Acknowledged = true
            };

            _clientMock
            .Setup(x => x.DeleteIndex(_indexName, string.Empty))
            .Returns(deleteResponse);

            //Act
            _sut = new ElasticSearchIndexProvider(_clientMock.Object, _loggerMock.Object, _settings.Object);
            _sut.DeleteIndex(_indexName);

            //Assert
            _clientMock
            .Verify(x => x.DeleteIndex(_indexName, string.Empty), Times.AtLeastOnce);
        }