diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e57f726d..2389f0c8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,12 +11,15 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install dependencies + run: | + sudo apt-get update - name: Check release validity run: sh .github/scripts/check-release.sh - name: Setup dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: 3.1.101 + dotnet-version: 8.x - name: Pack run: dotnet pack src/Meilisearch/Meilisearch.csproj -c Release -o src/Meilisearch/bin/Release - name: Publish diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4d4e9912..6fbc2dbe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: "6.0.x" + dotnet-version: "8.0.x" - name: Install dependencies run: dotnet restore - name: Build @@ -39,7 +39,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: "6.0.x" + dotnet-version: "8.0.x" - name: Check with dotnet-format run: dotnet format --version - name: Check with dotnet-format diff --git a/LICENSE b/LICENSE index d0bdb412..15c3e4e8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License Copyright (c) 2020 sa -Copyright (c) 2020-2024 Meili SAS +Copyright (c) 2020-2025 Meili SAS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/Meilisearch/Extensions/ObjectExtensions.cs b/src/Meilisearch/Extensions/ObjectExtensions.cs index a911e2f6..1154f15a 100644 --- a/src/Meilisearch/Extensions/ObjectExtensions.cs +++ b/src/Meilisearch/Extensions/ObjectExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Reflection; @@ -43,31 +42,25 @@ internal static string ToQueryString(this object source, BindingFlags bindingAtt if (value != null) { - var type = value.GetType(); - - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) + if (value is List stringValue) + { + values.Add(key + "=" + string.Join(",", stringValue)); + } + else if (value is List intValue) + { + values.Add(key + "=" + string.Join(",", intValue)); + } + else if (value is List taskInfoStatusValue) + { + values.Add(key + "=" + string.Join(",", taskInfoStatusValue.Select(x => x.ToString()))); + } + else if (value is List taskInfoTypeValue) { - var itemType = type.GetGenericArguments()[0]; - if (itemType == typeof(string)) - { - values.Add(key + "=" + string.Join(",", (List)value)); - } - else if (itemType == typeof(int)) - { - values.Add(key + "=" + string.Join(",", (List)value)); - } - else if (itemType == typeof(TaskInfoStatus)) - { - values.Add(key + "=" + string.Join(",", ((List)value).Select(x => x.ToString()))); - } - else if (itemType == typeof(TaskInfoType)) - { - values.Add(key + "=" + string.Join(",", ((List)value).Select(x => x.ToString()))); - } + values.Add(key + "=" + string.Join(",", taskInfoTypeValue.Select(x => x.ToString()))); } - else if (value is DateTime) + else if (value is DateTime datetimeValue) { - values.Add(key + "=" + Uri.EscapeDataString(((DateTime)value).ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz"))); + values.Add(key + "=" + Uri.EscapeDataString(datetimeValue.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz"))); } else { diff --git a/src/Meilisearch/Meilisearch.csproj b/src/Meilisearch/Meilisearch.csproj index fb5eaa07..b4d65e3f 100644 --- a/src/Meilisearch/Meilisearch.csproj +++ b/src/Meilisearch/Meilisearch.csproj @@ -19,7 +19,9 @@ $(NoWarn);1591 - + + true + diff --git a/src/Meilisearch/runtimeconfig.json b/src/Meilisearch/runtimeconfig.json new file mode 100644 index 00000000..657711ad --- /dev/null +++ b/src/Meilisearch/runtimeconfig.json @@ -0,0 +1,7 @@ +{ + "runtimeOptions": { + "configProperties": { + "System.Globalization.Invariant": true + } + } +} diff --git a/tests/Meilisearch.Tests/DocumentTests.cs b/tests/Meilisearch.Tests/DocumentTests.cs index ebdaa3fc..e6f00076 100644 --- a/tests/Meilisearch.Tests/DocumentTests.cs +++ b/tests/Meilisearch.Tests/DocumentTests.cs @@ -162,7 +162,7 @@ public async Task BasicDocumentAdditionFromCsvStringInBatches() var csvDocuments = await File.ReadAllTextAsync(Datasets.SongsCsvPath); var tasks = (await index.AddDocumentsCsvInBatchesAsync(csvDocuments, 250)).ToList(); - Assert.Equal(2, tasks.Count()); + Assert.Equal(2, tasks.Count); foreach (var u in tasks) { u.TaskUid.Should().BeGreaterOrEqualTo(0); @@ -190,7 +190,7 @@ public async Task BasicDocumentAdditionFromCsvWithDelimiterInBatches() var csvDocuments = await File.ReadAllTextAsync(Datasets.SongsCsvCustomDelimiterPath); var tasks = (await index.AddDocumentsCsvInBatchesAsync(csvDocuments, 15, csvDelimiter: ';')).ToList(); - Assert.Equal(2, tasks.Count()); + Assert.Equal(2, tasks.Count); foreach (var u in tasks) { u.TaskUid.Should().BeGreaterOrEqualTo(0); @@ -218,7 +218,7 @@ public async Task BasicDocumentAdditionFromNdjsonStringInBatches() var ndjsonDocuments = await File.ReadAllTextAsync(Datasets.SongsNdjsonPath); var tasks = (await index.AddDocumentsNdjsonInBatchesAsync(ndjsonDocuments, 150)).ToList(); - Assert.Equal(2, tasks.Count()); + Assert.Equal(2, tasks.Count); foreach (var u in tasks) { u.TaskUid.Should().BeGreaterOrEqualTo(0); @@ -469,7 +469,7 @@ public async Task BasicDocumentUpdateFromCsvStringInBatches() var csvDocuments = await File.ReadAllTextAsync(Datasets.SongsCsvPath); var tasks = (await index.UpdateDocumentsCsvInBatchesAsync(csvDocuments, 250)).ToList(); - Assert.Equal(2, tasks.Count()); + Assert.Equal(2, tasks.Count); foreach (var u in tasks) { u.TaskUid.Should().BeGreaterOrEqualTo(0); @@ -505,7 +505,7 @@ public async Task BasicDocumentUpdateFromNdjsonStringInBatches() var ndjsonDocuments = await File.ReadAllTextAsync(Datasets.SongsNdjsonPath); var tasks = (await index.UpdateDocumentsNdjsonInBatchesAsync(ndjsonDocuments, 150)).ToList(); - Assert.Equal(2, tasks.Count()); + Assert.Equal(2, tasks.Count); foreach (var u in tasks) { u.TaskUid.Should().BeGreaterOrEqualTo(0); diff --git a/tests/Meilisearch.Tests/IndexSwapTest.cs b/tests/Meilisearch.Tests/IndexSwapTest.cs index 83a3e797..9885d425 100644 --- a/tests/Meilisearch.Tests/IndexSwapTest.cs +++ b/tests/Meilisearch.Tests/IndexSwapTest.cs @@ -1,9 +1,5 @@ -using System; using System.Collections.Generic; using System.Text.Json; -using System.Text.Json.Serialization; - -using Microsoft.AspNetCore.WebUtilities; using Xunit; diff --git a/tests/Meilisearch.Tests/Meilisearch.Tests.csproj b/tests/Meilisearch.Tests/Meilisearch.Tests.csproj index 453201fa..fca0986c 100644 --- a/tests/Meilisearch.Tests/Meilisearch.Tests.csproj +++ b/tests/Meilisearch.Tests/Meilisearch.Tests.csproj @@ -1,11 +1,18 @@ - net6.0 - + net8.0 false + + 1701;1702;CA1861 + + + + 1701;1702;CA1861 + + diff --git a/tests/Meilisearch.Tests/Movie.cs b/tests/Meilisearch.Tests/Movie.cs index c683d4bb..dc20ffed 100644 --- a/tests/Meilisearch.Tests/Movie.cs +++ b/tests/Meilisearch.Tests/Movie.cs @@ -46,7 +46,7 @@ public class FormattedMovie public string Genre { get; set; } -#pragma warning disable SA1300 + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming convention used to match meilisearch.")] public Movie _Formatted { get; set; } } @@ -57,6 +57,8 @@ public class MovieWithRankingScore public string Name { get; set; } public string Genre { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming convention used to match meilisearch.")] public double? _RankingScore { get; set; } } @@ -67,6 +69,8 @@ public class MovieWithRankingScoreDetails public string Name { get; set; } public string Genre { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming convention used to match meilisearch.")] public IDictionary _RankingScoreDetails { get; set; } } } diff --git a/tests/Meilisearch.Tests/MultiIndexSearchTests.cs b/tests/Meilisearch.Tests/MultiIndexSearchTests.cs index 02f68ab5..e5101ab0 100644 --- a/tests/Meilisearch.Tests/MultiIndexSearchTests.cs +++ b/tests/Meilisearch.Tests/MultiIndexSearchTests.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; diff --git a/tests/Meilisearch.Tests/ObjectExtensionsTests.cs b/tests/Meilisearch.Tests/ObjectExtensionsTests.cs index 53894c14..ed4e04d0 100644 --- a/tests/Meilisearch.Tests/ObjectExtensionsTests.cs +++ b/tests/Meilisearch.Tests/ObjectExtensionsTests.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text.Json.Serialization; -using Meilisearch.Converters; using Meilisearch.Extensions; using Meilisearch.QueryParameters; diff --git a/tests/Meilisearch.Tests/Properties/launchSettings.json b/tests/Meilisearch.Tests/Properties/launchSettings.json new file mode 100644 index 00000000..3f6def7a --- /dev/null +++ b/tests/Meilisearch.Tests/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "Meilisearch.Tests": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:52605;http://localhost:52606" + } + } +} \ No newline at end of file diff --git a/tests/Meilisearch.Tests/SearchTests.cs b/tests/Meilisearch.Tests/SearchTests.cs index 580ac12e..328b2143 100644 --- a/tests/Meilisearch.Tests/SearchTests.cs +++ b/tests/Meilisearch.Tests/SearchTests.cs @@ -213,7 +213,7 @@ public async Task CustomSearchWithFilter() }); movies.Hits.Should().NotBeEmpty(); movies.FacetDistribution.Should().BeNull(); - Assert.Equal(2, movies.Hits.Count()); + Assert.Equal(2, movies.Hits.Count); Assert.Equal("12", movies.Hits.First().Id); Assert.Equal("Star Wars", movies.Hits.First().Name); Assert.Equal("SF", movies.Hits.First().Genre); @@ -247,7 +247,7 @@ public async Task CustomSearchWithFilterArray() }); movies.Hits.Should().NotBeEmpty(); movies.FacetDistribution.Should().BeNull(); - Assert.Equal(2, movies.Hits.Count()); + Assert.Equal(2, movies.Hits.Count); Assert.Equal("12", movies.Hits.First().Id); Assert.Equal("Star Wars", movies.Hits.First().Name); Assert.Equal("SF", movies.Hits.First().Genre); @@ -265,7 +265,7 @@ public async Task CustomSearchWithFilterMultipleArray() }); movies.Hits.Should().NotBeEmpty(); movies.FacetDistribution.Should().BeNull(); - Assert.Equal(2, movies.Hits.Count()); + Assert.Equal(2, movies.Hits.Count); Assert.Equal("12", movies.Hits.First().Id); Assert.Equal("Star Wars", movies.Hits.First().Name); Assert.Equal("SF", movies.Hits.First().Genre); @@ -392,7 +392,7 @@ public async Task CustomSearchWithSort() }); movies.Hits.Should().NotBeEmpty(); movies.FacetDistribution.Should().BeNull(); - Assert.Equal(2, movies.Hits.Count()); + Assert.Equal(2, movies.Hits.Count); Assert.Equal("14", movies.Hits.First().Id); } @@ -494,7 +494,7 @@ public async Task CustomSearchWithMatchingStrategyLast() var searchQuery = new SearchQuery() { MatchingStrategy = "last" }; var movies = await _nestedIndex.SearchAsync("movie about rich", searchQuery); - Assert.True(movies.Hits.Count() > 1); + Assert.True(movies.Hits.Count > 1); } [Fact] diff --git a/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs b/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs index 63bf4def..f0d5973c 100644 --- a/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs +++ b/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs @@ -13,9 +13,7 @@ public class ConfigFixture : IndexFixture { public override string MeilisearchAddress() { - var env = Environment.GetEnvironmentVariable("MEILISEARCH_URL"); - - return env == null ? MeilisearchTestAddress : env; + return Environment.GetEnvironmentVariable("MEILISEARCH_URL") ?? MeilisearchTestAddress; } } diff --git a/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs b/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs index 7b07233f..21f9afb8 100644 --- a/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs +++ b/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs @@ -13,9 +13,7 @@ public class ConfigFixture : IndexFixture { public override string MeilisearchAddress() { - var env = Environment.GetEnvironmentVariable("PROXIED_MEILISEARCH"); - - return env == null ? MeilisearchTestAddress : env; + return Environment.GetEnvironmentVariable("PROXIED_MEILISEARCH") ?? MeilisearchTestAddress; } } diff --git a/tests/Meilisearch.Tests/SettingsTests.cs b/tests/Meilisearch.Tests/SettingsTests.cs index 504f29a8..395bc54a 100644 --- a/tests/Meilisearch.Tests/SettingsTests.cs +++ b/tests/Meilisearch.Tests/SettingsTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -11,14 +12,12 @@ namespace Meilisearch.Tests public abstract class SettingsTests : IAsyncLifetime where TFixture : IndexFixture { private readonly Settings _defaultSettings; - private readonly MeilisearchClient _client; private Index _index; private readonly TFixture _fixture; public SettingsTests(TFixture fixture) { _fixture = fixture; - _client = fixture.DefaultClient; _defaultSettings = new Settings { @@ -34,19 +33,19 @@ public SettingsTests(TFixture fixture) DistinctAttribute = null, SearchableAttributes = new string[] { "*" }, DisplayedAttributes = new string[] { "*" }, - Dictionary = new string[] { }, - StopWords = new string[] { }, + Dictionary = Array.Empty(), + StopWords = Array.Empty(), SeparatorTokens = new List { }, NonSeparatorTokens = new List { }, Synonyms = new Dictionary> { }, - FilterableAttributes = new string[] { }, - SortableAttributes = new string[] { }, + FilterableAttributes = Array.Empty(), + SortableAttributes = Array.Empty(), ProximityPrecision = "byWord", TypoTolerance = new TypoTolerance { Enabled = true, - DisableOnAttributes = new string[] { }, - DisableOnWords = new string[] { }, + DisableOnAttributes = Array.Empty(), + DisableOnWords = Array.Empty(), MinWordSizeForTypos = new TypoTolerance.TypoSize { OneTypo = 5, @@ -437,7 +436,7 @@ public async Task UpdateTypoTolerance() var returnedTypoTolerance = new TypoTolerance { Enabled = true, - DisableOnAttributes = new string[] { }, + DisableOnAttributes = Array.Empty(), DisableOnWords = new string[] { "harry", "potter" }, MinWordSizeForTypos = new TypoTolerance.TypoSize { @@ -495,7 +494,7 @@ public async Task ResetTypoTolerance() var returnedTypoTolerance = new TypoTolerance { Enabled = true, - DisableOnAttributes = new string[] { }, + DisableOnAttributes = Array.Empty(), DisableOnWords = new string[] { "harry", "potter" }, MinWordSizeForTypos = new TypoTolerance.TypoSize { @@ -687,13 +686,13 @@ private static Settings SettingsWithDefaultedNullFields(Settings inputSettings, }; } - private async Task AssertGetEquality(IndexGetMethod getMethod, TValue expectedValue) + private static async Task AssertGetEquality(IndexGetMethod getMethod, TValue expectedValue) { var value = await getMethod(); value.Should().BeEquivalentTo(expectedValue); } - private async Task AssertGetInequality(IndexGetMethod getMethod, TValue expectedValue) + private static async Task AssertGetInequality(IndexGetMethod getMethod, TValue expectedValue) { var value = await getMethod(); value.Should().NotBeEquivalentTo(expectedValue); diff --git a/tests/Meilisearch.Tests/TaskInfoTests.cs b/tests/Meilisearch.Tests/TaskInfoTests.cs index 3f1f4fc1..f5cb51bb 100644 --- a/tests/Meilisearch.Tests/TaskInfoTests.cs +++ b/tests/Meilisearch.Tests/TaskInfoTests.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;