Expand Cosmos Emulator tests and harden read extension validation - #18
Expand Cosmos Emulator tests and harden read extension validation#18xperiandri with Copilot wants to merge 34 commits into
Conversation
xperiandri
left a comment
There was a problem hiding this comment.
Fix and format with Fantomas according to your instructions
542f3fc to
d5b9617
Compare
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/727cc9a9-e850-45de-b65f-4e8eb8ff33fc Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/63ac5990-d78f-452f-9f2f-85e08fdbff91 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/6f71a1f0-316c-4294-88a6-23f8995238fc Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/6f71a1f0-316c-4294-88a6-23f8995238fc Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
…h AndRead coverage
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/a905fb7f-9390-4144-84f7-22ff34a8fb8c Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Co-authored-by: Andrii Chebukin <XperiAndri@Outlook.com>
…mulator readiness
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/b2eda2fa-a0cb-4604-b8ca-51bd73075963 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/b2eda2fa-a0cb-4604-b8ca-51bd73075963 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/b2eda2fa-a0cb-4604-b8ca-51bd73075963 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/b2eda2fa-a0cb-4604-b8ca-51bd73075963 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
…eding Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/fb87fcd3-5c25-4e1f-ab2c-0f29ce614280 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/fb87fcd3-5c25-4e1f-ab2c-0f29ce614280 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/fb87fcd3-5c25-4e1f-ab2c-0f29ce614280 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
2a78e83 to
bde1f0d
Compare
| $"""SELECT VALUE COUNT(1) | ||
| FROM item | ||
| WHERE item.id = @Id | ||
| AND (NOT IS_DEFINED(item.{deletedFieldName}) OR IS_NULL(item.{deletedFieldName}))""" |
There was a problem hiding this comment.
@copilot так что с покрытием всех этих кейсов тестами?
| (deletedFieldName : string | null) | ||
| (id : string, [<Optional>] requiestOptions : QueryRequestOptions, [<Optional>] cancellationToken : CancellationToken) | ||
| = | ||
| task { | ||
| let deletedFieldName = | ||
| match deletedFieldName with | ||
| | null -> nullArg (nameof deletedFieldName) | ||
| | deletedFieldName -> deletedFieldName |
There was a problem hiding this comment.
@copilot ты понимаешь что это идиотизм декларировать string | null а потом кидать исключение.
| (deletedFieldName : string | null) | |
| (id : string, [<Optional>] requiestOptions : QueryRequestOptions, [<Optional>] cancellationToken : CancellationToken) | |
| = | |
| task { | |
| let deletedFieldName = | |
| match deletedFieldName with | |
| | null -> nullArg (nameof deletedFieldName) | |
| | deletedFieldName -> deletedFieldName | |
| (deletedFieldName : string) | |
| (id : string, [<Optional>] requiestOptions : QueryRequestOptions, [<Optional>] cancellationToken : CancellationToken) | |
| = | |
| if deletedFieldName |> withNull |> isNull then | |
| nullArg (nameof deletedFieldName) | |
| task { |
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/7c652b6b-140a-42c5-9e86-a71d0a69c5ba Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/7c652b6b-140a-42c5-9e86-a71d0a69c5ba Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/7c652b6b-140a-42c5-9e86-a71d0a69c5ba Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/7c652b6b-140a-42c5-9e86-a71d0a69c5ba Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
xperiandri
left a comment
There was a problem hiding this comment.
@copilot изучи все методы на классе Assert и переделай все assert'ы на подходящие overloads.
Обработай все комментарии
| $"""SELECT VALUE COUNT(1) | ||
| FROM item | ||
| WHERE item.id = @Id | ||
| AND (NOT IS_DEFINED(item.{deletedFieldName}) OR IS_NULL(item.{deletedFieldName}))""" |
There was a problem hiding this comment.
But it must be true to be treated as deleted
if it is { "deleted": false } it is not deleted
| let isAsciiLetter c = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') | ||
| let isAsciiDigit c = '0' <= c && c <= '9' | ||
|
|
||
| let isValidDeletedFieldName = | ||
| if String.IsNullOrWhiteSpace deletedFieldName then | ||
| false | ||
| else | ||
| let firstCharacter = deletedFieldName[0] | ||
| let hasValidStart = firstCharacter = '_' || isAsciiLetter firstCharacter | ||
| let hasValidBody = | ||
| deletedFieldName | ||
| |> Seq.forall (fun c -> c = '_' || isAsciiLetter c || isAsciiDigit c) | ||
|
|
||
| hasValidStart && hasValidBody |
There was a problem hiding this comment.
Это же правила валидации имени поля в Cosmos? Давай тогда создадим вверху файла модуль CosmosName и в нём функцию [<CompiledName "ValidateField">] validateField которая будет создержать этот код. И на эту функцию напишем тесты
| ) | ||
|
|
||
| [<TestMethod>] | ||
| member _.``Read builder configures id partition key and request options`` () = |
There was a problem hiding this comment.
| member _.``Read builder configures id partition key and request options`` () = | |
| member _.``Read builder configures id and partition key and request options`` () = |
| sessionToken "read-session" | ||
| } | ||
|
|
||
| Assert.IsTrue (operation.Id = "read-id", "Read builder should set id.") |
There was a problem hiding this comment.
там есть метод аля Assert.Equals для сравнения строк
| } | ||
|
|
||
| Assert.IsTrue (operation.Id = "read-id", "Read builder should set id.") | ||
| Assert.IsFalse (isNull operation.RequestOptions, "Read builder should initialize request options when needed.") |
There was a problem hiding this comment.
разве там нет метода Assert.IsNull?
|
|
||
| Assert.IsTrue (operation.Id = "read-id", "Read builder should set id.") | ||
| Assert.IsFalse (isNull operation.RequestOptions, "Read builder should initialize request options when needed.") | ||
| Assert.IsTrue (operation.RequestOptions.IfNoneMatchEtag = "etag-value", "Read builder should set eTag option.") |
| Assert.IsTrue (operation.Id = "read-id", "Read builder should set id.") | ||
| Assert.IsFalse (isNull operation.RequestOptions, "Read builder should initialize request options when needed.") | ||
| Assert.IsTrue (operation.RequestOptions.IfNoneMatchEtag = "etag-value", "Read builder should set eTag option.") | ||
| Assert.IsTrue (operation.RequestOptions.SessionToken = "read-session", "Read builder should set session token.") |
|
|
||
| let updateResult = | ||
| replaceConcurrentlyOperation.Update { id = "id"; partitionKey = "pk"; value = 2 } | ||
| |> Async.RunSynchronously |
There was a problem hiding this comment.
переделай на асинхронный тест
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Azure.Cosmos/sessions/f0174b7d-c2d6-4a25-aa23-d50cac7c65f3 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
This PR expands Cosmos Emulator integration coverage and incorporates review-driven fixes in both tests and read extension behavior.
Changes Made
DatabaseTestApplicationFactoryderivatives (SingleItemScenario,MultipleItemsScenario).IntegrationTestBase<'DatabaseTestApplicationFactory>/OperationTestBase<'DatabaseTestApplicationFactory>patterns.TestCategoriesconstants and applied explicitTestCategoryattributes across test classes.IsNotDeletedAsyncinCosmos.fs:deletedFieldNameto non-nullablestring,nullArgguard,requestOptionsparameter naming.<exception>documentation for methods that throw inCosmos.fs(IsNotDeletedAsync,AddPreTriggers,AddPostTriggers).IsNotDeletedAsyncresult as expected.Validation
dotnet build FSharp.Azure.Cosmos.slnxdotnet test FSharp.Azure.Cosmos.slnxdotnet test tests/Cosmos.Tests/FSharp.Azure.Cosmos.Tests.fsprojdotnet test tests/Cosmos.Tests/FSharp.Azure.Cosmos.Tests.fsproj --filter "FullyQualifiedName~ReadExtensionsIntegrationTests"