|
| 1 | +using MiniLcm.Validators; |
| 2 | +using Moq; |
| 3 | + |
| 4 | +namespace MiniLcm.Tests; |
| 5 | + |
| 6 | +public class NormalizationTests |
| 7 | +{ |
| 8 | + public IMiniLcmApi MockApi { get; init; } |
| 9 | + public IMiniLcmApi NormalizingApi { get; init; } |
| 10 | + |
| 11 | + public const string NFCString = "na\u00efve"; // "naïve" with U+00EF LATIN SMALL LETTER I WITH DIAERESIS |
| 12 | + public const string NFDString = "na\u0069\u0308ve"; // "naïve" with U+0069 LATIN SMALL LETTER I + U+0308 COMBINING DIAERESIS |
| 13 | + |
| 14 | + public FilterQueryOptions NFCOptions = new() |
| 15 | + { |
| 16 | + Exemplar = new ExemplarOptions(NFCString, "en"), |
| 17 | + Filter = new Filtering.EntryFilter { GridifyFilter = NFCString }, |
| 18 | + }; |
| 19 | + |
| 20 | + public QueryOptions NFCQueryOptions = new() |
| 21 | + { |
| 22 | + Exemplar = new ExemplarOptions(NFCString, "en"), |
| 23 | + Filter = new Filtering.EntryFilter { GridifyFilter = NFCString }, |
| 24 | + }; |
| 25 | + |
| 26 | + public FilterQueryOptions NFDOptions = new() |
| 27 | + { |
| 28 | + Exemplar = new ExemplarOptions(NFDString, "en"), |
| 29 | + Filter = new Filtering.EntryFilter { GridifyFilter = NFDString }, |
| 30 | + }; |
| 31 | + |
| 32 | + public NormalizationTests() |
| 33 | + { |
| 34 | + MockApi = Mock.Of<IMiniLcmApi>(); |
| 35 | + // Mock.Get(MockApi).Setup(api => api.SearchEntries(It.IsAny<string>(), null)).Returns(new List<Entry>().ToAsyncEnumerable()); |
| 36 | + var factory = new MiniLcmApiStringNormalizationWrapperFactory(); |
| 37 | + NormalizingApi = factory.Create(MockApi); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public void SearchEntriesIsNormalized() |
| 42 | + { |
| 43 | + NormalizingApi.Should().BeOfType<MiniLcmApiStringNormalizationWrapper>(); |
| 44 | + var results = NormalizingApi.SearchEntries(NFCString, null); |
| 45 | + Mock.Get(MockApi).Verify(api => api.SearchEntries(NFDString, null)); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public void SearchEntriesWithQueryOptionsAreNormalized() |
| 50 | + { |
| 51 | + NormalizingApi.Should().BeOfType<MiniLcmApiStringNormalizationWrapper>(); |
| 52 | + var results = NormalizingApi.SearchEntries(NFCString, NFCQueryOptions); |
| 53 | + Mock.Get(MockApi).Verify(api => api.SearchEntries(NFDString, It.Is<QueryOptions>( |
| 54 | + opt => opt.Exemplar!.Value == NFDOptions.Exemplar!.Value && |
| 55 | + opt.Filter!.GridifyFilter == NFDOptions.Filter!.GridifyFilter))); |
| 56 | + } |
| 57 | + |
| 58 | + [Fact] |
| 59 | + public void CountEntriesIsNormalized() |
| 60 | + { |
| 61 | + NormalizingApi.Should().BeOfType<MiniLcmApiStringNormalizationWrapper>(); |
| 62 | + var results = NormalizingApi.CountEntries(NFCString, null); |
| 63 | + Mock.Get(MockApi).Verify(api => api.CountEntries(NFDString, null)); |
| 64 | + } |
| 65 | + |
| 66 | + [Fact] |
| 67 | + public void CountEntriesWithFilterQueryOptionsIsNormalized() |
| 68 | + { |
| 69 | + NormalizingApi.Should().BeOfType<MiniLcmApiStringNormalizationWrapper>(); |
| 70 | + var results = NormalizingApi.CountEntries(NFCString, NFCOptions); |
| 71 | + Mock.Get(MockApi).Verify(api => api.CountEntries(NFDString, It.Is<FilterQueryOptions>( |
| 72 | + opt => opt.Exemplar!.Value == NFDOptions.Exemplar!.Value && |
| 73 | + opt.Filter!.GridifyFilter == NFDOptions.Filter!.GridifyFilter))); |
| 74 | + } |
| 75 | + |
| 76 | + [Fact] |
| 77 | + public void GetEntriesIsNormalized() |
| 78 | + { |
| 79 | + NormalizingApi.Should().BeOfType<MiniLcmApiStringNormalizationWrapper>(); |
| 80 | + var results = NormalizingApi.GetEntries(NFCQueryOptions); |
| 81 | + Mock.Get(MockApi).Verify(api => api.GetEntries(It.Is<QueryOptions>( |
| 82 | + opt => opt.Exemplar!.Value == NFDOptions.Exemplar!.Value && |
| 83 | + opt.Filter!.GridifyFilter == NFDOptions.Filter!.GridifyFilter))); |
| 84 | + } |
| 85 | +} |
0 commit comments