Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Øyvind Tanum committed Jan 19, 2024
1 parent 43a132b commit 1b84d55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/Core.Tests/CoreIndexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
using System.IO;
using System.Net;
using Epinova.ElasticSearch.Core;
using Epinova.ElasticSearch.Core.Extensions;
using Epinova.ElasticSearch.Core.Models.Bulk;
using Epinova.ElasticSearch.Core.Settings;
using Moq;
using TestData;
using Xunit;
Expand Down Expand Up @@ -61,7 +59,7 @@ public void Bulk_NullOperations_ReturnsEmptyResult()
public void Bulk_CallsClientPost()
{
var id = Factory.GetInteger();
string indexName = new ElasticSearchSettings().GetCustomIndexName("my-index", new CultureInfo("en"));
string indexName = _fixture.ServiceLocationMock.SettingsMock.Object.GetCustomIndexName("my-index", new CultureInfo("en"));
_coreIndexer.Bulk(new BulkOperation(indexName, new { Foo = "bar" }, Operation.Index, null, id));

_fixture.ServiceLocationMock.HttpClientMock
Expand All @@ -71,8 +69,8 @@ public void Bulk_CallsClientPost()
[Fact]
public void Bulk_ReturnsBatchResults()
{
string indexName = new ElasticSearchSettings().GetCustomIndexName("my-index", new CultureInfo("en"));
var result = _coreIndexer.Bulk(new BulkOperation(indexName, new { Foo = 42 }, Operation.Index, null, 123));
string indexName = _fixture.ServiceLocationMock.SettingsMock.Object.GetCustomIndexName("my-index", new CultureInfo("en"));
var result = _coreIndexer.Bulk(new BulkOperation(indexName, new { Foo = 42 }, Operation.Index, null, 123));
Assert.NotEmpty(result.Batches);
}

Expand All @@ -81,7 +79,7 @@ public void Delete_CallsClientHeadAndDelete()
{
var id = Factory.GetInteger();
_coreIndexer.Delete(id, new CultureInfo("sv"));
var uri = new Uri($"http://example.com/delete-me/{typeof(TestPage).GetTypeName()}/{id}");
var uri = new Uri($"http://example.com/delete-me/_doc/{id}");

_fixture.ServiceLocationMock.HttpClientMock
.Verify(m => m.Head(uri), Times.Once);
Expand All @@ -96,7 +94,7 @@ public void Update_CallsClientPut()
_coreIndexer.Update(id, new { Foo = 42 }, "my-index");

_fixture.ServiceLocationMock.HttpClientMock
.Verify(m => m.Put(new Uri($"http://example.com/my-index/AnonymousType/{id}"), It.IsAny<byte[]>()), Times.Once);
.Verify(m => m.Put(new Uri($"http://example.com/my-index/_doc/{id}"), It.IsAny<byte[]>()), Times.Once);
}

[Fact]
Expand All @@ -106,7 +104,7 @@ public void Update_WithTypes_CallsClientPut()
_coreIndexer.Update(id, new { Foo = 42, Types = new[] { "foo", "bar" } }, "my-index");

_fixture.ServiceLocationMock.HttpClientMock
.Verify(m => m.Put(new Uri($"http://example.com/my-index/AnonymousType/{id}"), It.IsAny<byte[]>()), Times.Once);
.Verify(m => m.Put(new Uri($"http://example.com/my-index/_doc/{id}"), It.IsAny<byte[]>()), Times.Once);
}

[Fact]
Expand Down Expand Up @@ -146,7 +144,7 @@ public void ClearBestBets_CallsClientPost()
_coreIndexer.ClearBestBets("my-index", id);

_fixture.ServiceLocationMock.HttpClientMock
.Verify(m => m.Post(new Uri($"http://example.com/my-index/{typeof(TestPage).GetTypeName()}/{id}/_update"), It.IsAny<byte[]>()), Times.Once);
.Verify(m => m.Post(new Uri($"http://example.com/my-index/_update/{id}/"), It.IsAny<byte[]>()), Times.Once);
}

[Fact]
Expand All @@ -166,7 +164,7 @@ public void UpdateBestBets_CallsClientPost()
_coreIndexer.ClearBestBets("my-index", id);

_fixture.ServiceLocationMock.HttpClientMock
.Verify(m => m.Post(new Uri($"http://example.com/my-index/{typeof(TestPage).GetTypeName()}/{id}/_update"), It.IsAny<byte[]>()), Times.Once);
.Verify(m => m.Post(new Uri($"http://example.com/my-index/_update/{id}/"), It.IsAny<byte[]>()), Times.Once);
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions tests/TestData/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ internal static ServiceLocationMock SetupServiceLocator()
settings.Setup(m => m.Index).Returns(ElasticFixtureSettings.IndexName);
settings.Setup(m => m.Indices).Returns(new[] { ElasticFixtureSettings.IndexNameWithoutLang });
settings.Setup(m => m.GetLanguageFromIndexName(It.IsAny<string>())).Returns("no");
settings.Setup(m => m.GetCustomIndexName(It.IsAny<string>(), It.IsAny<CultureInfo>())).Returns(ElasticFixtureSettings.IndexName);
settings.Setup(m => m.GetDefaultIndexName(It.IsAny<CultureInfo>())).Returns(ElasticFixtureSettings.IndexName);
settings.Setup(m => m.Host).Returns("http://example.com");
result.SettingsMock = settings;
Expand Down

0 comments on commit 1b84d55

Please sign in to comment.