Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Jul 21, 2022
1 parent 8f4dd86 commit cea1279
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;

namespace Kentico.Xperience.AlgoliaSearch.Services.Implementations
namespace Kentico.Xperience.AlgoliaSearch.Services
{
/// <summary>
/// Default implementation of <see cref="IAlgoliaIndexRegister"/>.
Expand Down
11 changes: 11 additions & 0 deletions tests/Fakes/TestSearchModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,16 @@ public class Model7 : ModelBaseClass
[Searchable]
public string NodeAliasPath { get; set; }
}


[IncludedPath("/Articles/%")]
public class Model8 : AlgoliaSearchModel
{
public const string IndexName = "Model8";


[Searchable]
public string DocumentCreatedWhen { get; set; }
}
}
}
70 changes: 70 additions & 0 deletions tests/Tests/IAlgoliaIndexRegisterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Algolia.Search.Clients;

using Kentico.Xperience.AlgoliaSearch.Services;

using NSubstitute;

using NUnit.Framework;

using static Kentico.Xperience.AlgoliaSearch.Test.TestSearchModels;

namespace Kentico.Xperience.AlgoliaSearch.Test
{
internal class IAlgoliaIndexRegisterTests
{
[TestFixture]
internal class IndexRegistrationTests : AlgoliaTests
{
[Test]
public void ValidIndex_IsRegistered()
{
var indexRegister = new DefaultAlgoliaIndexRegister()
.Add<Model8>(Model8.IndexName);

var algoliaRegistrationService = GetRegistrationService(indexRegister);
algoliaRegistrationService.RegisterAlgoliaIndexes();

Assert.AreEqual(8, algoliaRegistrationService.RegisteredIndexes.Count);
}


[Test]
public void DuplicateIndexes_NotRegistered()
{
var indexRegister = new DefaultAlgoliaIndexRegister()
.Add<Model8>(Model8.IndexName)
.Add<Model8>(Model8.IndexName)
.Add<Model8>(Model8.IndexName);

var algoliaRegistrationService = GetRegistrationService(indexRegister);
algoliaRegistrationService.RegisterAlgoliaIndexes();

Assert.AreEqual(8, algoliaRegistrationService.RegisteredIndexes.Count);
}


[Test]
public void IndexRegisteredWithAttribute_NotRegistered()
{
var indexRegister = new DefaultAlgoliaIndexRegister()
.Add<Model7>(Model7.IndexName);

var algoliaRegistrationService = GetRegistrationService(indexRegister);
algoliaRegistrationService.RegisterAlgoliaIndexes();

Assert.AreEqual(7, algoliaRegistrationService.RegisteredIndexes.Count);
}


private IAlgoliaRegistrationService GetRegistrationService(IAlgoliaIndexRegister indexRegister)
{
return new DefaultAlgoliaRegistrationService(
Substitute.For<IAlgoliaSearchService>(),
new MockEventLogService(),
Substitute.For<ISearchClient>(),
Substitute.For<IAlgoliaIndexService>(),
indexRegister);
}
}
}
}
1 change: 0 additions & 1 deletion tests/Tests/IAlgoliaIndexingServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CMS.DataEngine;
using CMS.DocumentEngine;

using Kentico.Xperience.AlgoliaSearch.Attributes;
using Kentico.Xperience.AlgoliaSearch.Models;
using Kentico.Xperience.AlgoliaSearch.Services;

Expand Down
2 changes: 0 additions & 2 deletions tests/Tests/IAlgoliaRegistrationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using CMS.DocumentEngine;
using CMS.SiteProvider;

using Kentico.Xperience.AlgoliaSearch.Attributes;
using Kentico.Xperience.AlgoliaSearch.Models;
using Kentico.Xperience.AlgoliaSearch.Services;

using NSubstitute;
Expand Down

0 comments on commit cea1279

Please sign in to comment.