Add BLite.NetStandard21.Tests: coverage for netstandard2.1 conditional code paths#9
Merged
mrdevrobot merged 2 commits intomainfrom Mar 4, 2026
Merged
Conversation
…code path coverage Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add new test project for netstandard2.1 support
Add BLite.NetStandard21.Tests: coverage for netstandard2.1 conditional code paths
Mar 2, 2026
mrdevrobot
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BLite.CoreandBLite.Bsonmulti-targetnet10.0;netstandard2.1with numerous#ifbranches, but the only test project targetsnet10.0exclusively — leaving every#elsepath untested.New project
tests/BLite.NetStandard21.Tests/— targetsnetstandard2.1only, compiles against thenetstandard2.1builds ofBLite.CoreandBLite.Bson(noBLite.Shared, which isnet10.0-only).InternalsVisibleTo
Added
BLite.NetStandard21.TeststoBLite.Core.csprojto expose internal types (PageFile,StorageEngine,SlottedPageHeader,TimeSeriesPage,PriorityQueuepolyfill).Test coverage — one file per conditional path
PageFileNetStandardTestsReadPageAsync#else:Seek+SemaphoreSlimlockStorageEngineNetStandardTestsReadPageAsyncWAL fast paths returningdefaultinstead ofValueTask.CompletedTaskObjectIdNetStandardTestsNewObjectId()random vianew Random(),ToString()viaBitConverter.ToString(...).Replace("-","")BsonWriterNetStandardTestsWriteDoubleInternalviaWriteInt64LittleEndian(BitConverter.DoubleToInt64Bits(v))PageHeaderNetStandardTestsWriteToviaMemoryMarshal.Write(destination, ref copy)on bothPageHeaderandSlottedPageHeaderTimeSeriesPageNetStandardTestsSetLastTimestamp/SetEntryCountviaMemoryMarshal.Write(..., ref value)IndexKeyNetStandardTestsComputeHashCodeviaforeach (var b in data) hash.Add(b)PolyfillsNetStandardTestsPriorityQueue<TElement,TPriority>min-heap polyfill (guarded#if NETSTANDARD2_1)All test code uses only netstandard2.1-compatible APIs — no
Random.Shared,Convert.ToHexString,RandomAccess, orValueTask.CompletedTask.Original prompt
Problema
Le librerie di produzione (
BLite,BLite.Core,BLite.Bson) fanno multi-targeting sunet10.0;netstandard2.1, ma l'unico progetto di test esistente —BLite.Tests— target solonet10.0. Questo significa che nessun test viene mai eseguito contro il runtimenetstandard2.1, nonostante esistano numerosi path di codice condizionali (#if NETSTANDARD2_1,#if NET6_0_OR_GREATER,#if NET5_0_OR_GREATER,#if NET8_0_OR_GREATER, ecc.) che attivano implementazioni alternative.Obiettivo
Creare un nuovo progetto di test dedicato
tests/BLite.NetStandard21.Tests/che:netstandard2.1BLite.Tests)dotnet test -f netstandard2.1(tramite un runtime compatibile, es. .NET 5/6/8/9)Path critici da coprire (tutti con codice condizionale nel sorgente)
1.
PageFile.ReadPageAsync— path#else(Seek + SemaphoreSlim)File:
src/BLite.Core/Storage/PageFile.csSu
net10.0usaRandomAccess.ReadAsync(lock-free). Sunetstandard2.1usa il path#else:Test da scrivere:
ReadPageAsync_SingleRead_ReturnsCorrectData— scrive una pagina, la rilegge async e verifica i datiReadPageAsync_ConcurrentReads_DoNotDeadlock— 20 reader concorrenti sulla stessa pagina, verifica che non ci sia deadlock o corruzione (il SemaphoreSlim serializza, non deve bloccarsi)ReadPageAsync_WithCancellation_ThrowsOperationCanceledException— cancellation token già cancellato deve lanciareOperationCanceledException2.
StorageEngine.ReadPageAsync—ValueTask.CompletedTaskpolyfillFile:
src/BLite.Core/Storage/StorageEngine.Pages.csSu
netstandard2.1non esisteValueTask.CompletedTask, quindi usareturn default;:Test da scrivere:
ReadPageAsync_FromWalCache_ReturnsCorrectly_OnNetStandard— scrive in WAL cache e legge async; ilValueTaskrestituito dal pathdefaultdeve essere awaitable correttamenteReadPageAsync_FromWalIndex_ReturnsCorrectly_OnNetStandard— stessa verifica per il path WAL index3.
ObjectId.NewObjectId()— generazione randomFile:
src/BLite.Bson/ObjectId.csSu
net6.0+usaRandom.Shared.NextInt64(). Sunetstandard2.1:Test da scrivere:
ObjectId_NewObjectId_IsUnique— genera 1000 ObjectId e verifica che siano tutti distintiObjectId_NewObjectId_HasCurrentTimestamp— verifica che il timestamp dell'ObjectId sia vicino aDateTimeOffset.UtcNowObjectId_ToString_ReturnsHexString— verifica il path#elsediToString()(usaBitConverter.ToString+Replace("-", "")invece diConvert.ToHexString)4.
ObjectId.ToString()—Convert.ToHexStringpolyfillFile:
src/BLite.Bson/ObjectId.csTest da scrivere:
ObjectId_RoundTrip_ToString_Parse— serializza un ObjectId a stringa e verifica che il formato sia 24 caratteri hex lowercaseObjectId_KnownValue_ToString_MatchesExpected— crea un ObjectId con bytes noti e verifica cheToString()produca il valore hex atteso5.
BsonBufferWriter.WriteDoubleInternal—BinaryPrimitives.WriteDoubleLittleEndianFile:
src/BLite.Bson/BsonBufferWriter.csSu
netstandard2.1usa:Test da scrivere:
BsonWriter_WriteDouble_RoundTrip— scrive un double nel BSON e lo rilegge, verificando identità di valoreBsonWriter_WriteDouble_SpecialValues— testadouble.NaN,double.PositiveInfinity,double.NegativeInfinity,double.MaxValue,double.MinValue6.
PageHeader.WriteToeSlottedPageHeader.WriteTo—MemoryMarshal.WriteconrefvsinFile:
src/BLite.Core/Storage/PageHeader.cs,src/BLite.Core/Storage/SlottedPage.csSu
netstandard2.1usaref copyinvece diin this:Test da scrivere:
PageHeader_WriteTo_ReadFrom_RoundTrip— crea unPageHeadercon valori noti, lo scrive su uno span e lo rilegge conReadFrom, verificando ogni campoThis pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.