public void ShouldThrowAnExceptionIfCantCreateAnIndex() { var response = new StubResponse(400); MockElasticClient.Setup(x => x.CreateIndex(It.IsAny <IndexName>(), It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >(), It.IsAny <string>())).Returns(response); var indexMaintainer = new ElasticsearchApprenticeshipIndexMaintainer(MockElasticClient.Object, Mock.Of <IElasticsearchMapper>(), Mock.Of <ILog>(), Mock.Of <IElasticsearchConfiguration>()); Assert.Throws <ConnectionException>(() => indexMaintainer.CreateIndex("testindex")); }
public async Task ShouldFilterOutStandardsThatAreNotValid() { var response = new StubResponse(400); var mockResponse = new Mock <IBulkResponse> { DefaultValue = DefaultValue.Mock }; var mockSettings = new Mock <IInfrastructureSettings>(); mockSettings.SetupGet(x => x.FrameworkIdFormat).Returns("{0}{1}{2}"); MockElasticClient.Setup(x => x.CreateIndex(It.IsAny <IndexName>(), It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >(), It.IsAny <string>())).Returns(response); MockElasticClient.Setup(x => x.BulkAsync(It.IsAny <IBulkRequest>(), It.IsAny <string>())).Returns(Task.FromResult <IBulkResponse>(mockResponse.Object)); var indexMaintainer = new ElasticsearchApprenticeshipIndexMaintainer( MockElasticClient.Object, new ElasticsearchMapper(mockSettings.Object, Mock.Of <IOrganisationTypeProcessor>()), Mock.Of <ILog>(), Mock.Of <IElasticsearchConfiguration>()); await indexMaintainer.IndexStandards("testindex", StandardsTestData4001WithOneNull()); MockElasticClient.Verify(x => x.BulkAsync(It.IsAny <IBulkRequest>(), It.IsAny <string>()), Times.Exactly(1)); }