From dc7e8aeb8630ab9289ff86dc7711d49e9e25db18 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Fri, 7 May 2021 08:52:29 +0200 Subject: [PATCH 01/31] feat: updated workflows --- .github/workflows/build.yml | 121 ++++++++++++ .github/workflows/changelog.yml | 85 ++++++++ .github/workflows/gitflow.yml | 54 +++++ .github/workflows/release-github.yml | 49 +++++ .github/workflows/release-nuget.yml | 54 +++++ .github/workflows/release.yml | 284 --------------------------- 6 files changed, 363 insertions(+), 284 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/gitflow.yml create mode 100644 .github/workflows/release-github.yml create mode 100644 .github/workflows/release-nuget.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..609614f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,121 @@ +name: Build + +on: + workflow_run: + workflows: [ "Changelog generator" ] + types: + - completed + workflow_dispatch: + +jobs: + build: + name: Build + runs-on: windows-latest + env: + # Dotnet Setup + DOTNET_VERSION: 3.1.401 + + # Stop wasting time caching packages + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + + # Disable sending usage data to Microsoft + DOTNET_CLI_TELEMETRY_OPTOUT: true + + # Solution Setup + CONFIG: 'Release' + PROJECT_NAME: 'Cogworks.AzureSearch' + VERSION: '1.0.0' + SOURCE_PATH: './Source' + + # Nuget Setup + NUGET_VERSION: 'latest' + NUGET_OUTPUT: '.output/' + + steps: + - name: Checkout reference commit + if: ${{ github.event_name == 'pull_request' }} + uses: actions/checkout@v2 + + - name: Checkout master + if: ${{ github.event_name != 'pull_request' }} + uses: actions/checkout@v2 + with: + ref: master + fetch-depth: 0 + + - name: Get version + if: ${{ github.event_name != 'pull_request' }} + shell: bash + run: | + tag_check=$(git describe --exact-match `git rev-parse HEAD` | head -1) + echo "VERSION=$tag_check" >> $GITHUB_ENV + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v1 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Configure NuGet + uses: nuget/setup-nuget@v1 + with: + nuget-version: ${{ env.NUGET_VERSION }} + + - name: NuGet Restore + shell: powershell + working-directory: ${{ github.workspace }} + run: | + $solutions = Get-ChildItem -Path ${{ env.SOURCE_PATH}} -Recurse -Include *.sln + + foreach ($solutionFile in $solutions){ + nuget restore "$solutionFile" + } + + - name: Install Dependencies + shell: powershell + working-directory: ${{ github.workspace }} + run: | + $solutions = Get-ChildItem -Path ${{ env.SOURCE_PATH}} -Recurse -Include *.sln + + foreach ($solutionFile in $solutions){ + dotnet restore "$solutionFile" + } + + - name: Build + shell: powershell + working-directory: ${{ github.workspace }} + run: | + $solutions = Get-ChildItem -Path ${{ env.SOURCE_PATH}} -Recurse -Include *.sln + + foreach ($solutionFile in $solutions){ + msbuild.exe "$solutionFile" ` + /p:Configuration=${{ env.CONFIG }} ` + /p:DeployOnBuild=false ` + /p:SkipInvalidConfigurations=true ` + /p:TransformWebConfigEnabled=False ` + /p:AutoParameterizationWebConfigConnectionStrings=False ` + /p:MarkWebConfigAssistFilesAsExclude=False + } + + - name: Pack all nuspec files + if: ${{ github.event_name != 'pull_request' }} + shell: powershell + working-directory: ${{ github.workspace }} + run: | + $nuspecFiles = Get-ChildItem -Path ${{ env.SOURCE_PATH}} -Recurse -Include *.nuspec + + foreach ($nuspecFile in $nuspecFiles){ + nuget pack "$nuspecFile" ` + -Version ${{ env.VERSION }} ` + -Properties Configuration=${{ env.CONFIG }} ` + -OutputDirectory ${{ env.NUGET_OUTPUT }} + } + + - name: Upload build artifact + if: ${{ github.event_name != 'pull_request' }} + uses: actions/upload-artifact@v2 + with: + name: build_${{ env.PROJECT_NAME }}.${{ env.VERSION }} + path: ${{ github.workspace }}/${{ env.NUGET_OUTPUT }} diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..ffb918b --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,85 @@ +name: Changelog generator + +on: + push: + tags: + - '*' + +jobs: + changelog_generator: + name: Changelog Generator + runs-on: ubuntu-latest + env: + branch: master + CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set local user + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + - name: Get tag branch + run: | + branch_check=$(git branch -r --contains $(git rev-parse $GITHUB_REF~0) | sed 's/remotes\/origin\///' | sed 's/origin\///' | sed 's/develop//' | sed 's/* //' | sed -r '/^\s*$/d' | head -1) + + echo $branch_check + + if [[ $branch_check =~ ^(release|master)$ ]]; then + echo "Not correct branch. Allowed branches release and master." + exit 1 + fi + + echo "branch=$branch_check" >> $GITHUB_ENV + + - uses: actions/checkout@v2 + name: Checkout tag branch + with: + fetch-depth: 0 + ref: ${{ env.branch }} + + - name: Get tag + run: | + echo "Describe: $(git describe)" + echo "Rev parse: $(git rev-parse $GITHUB_REF~0)" + + tag_check=$(git describe --exact-match `git rev-parse $GITHUB_REF~0`) + echo "tag=$tag_check" >> $GITHUB_ENV + + - name: Install dependencies + run: | + rm -rf node_modules + npm install + + - name: Generate changelog and update npm version + run: | + npm run release + + - name: Remove tag + run: | + git tag -d ${{ env.tag }} + + - name: Updating tags + run: | + git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master + git tag -a ${{ env.tag }} -m "${{ env.tag }}" + git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --tag -f + + - name: Pushing latest changes to master + run: | + git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master + git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" ${{ env.branch }}:master + + - name: Checkout master + run: | + git checkout master + git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master + + - name: Generate GitHub release notes + run: | + npm run github-release + continue-on-error: true diff --git a/.github/workflows/gitflow.yml b/.github/workflows/gitflow.yml new file mode 100644 index 0000000..38a9959 --- /dev/null +++ b/.github/workflows/gitflow.yml @@ -0,0 +1,54 @@ +name: Git Flow + +on: + workflow_run: + workflows: [ "Changelog generator" ] + types: + - completed +jobs: + gitflow: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: Git Flow + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + ref: master + fetch-depth: 0 + + - name: Set local user + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + - name: Get latest tag + run: | + tag_check=$(git describe --exact-match `git rev-parse HEAD` | head -1) + echo "tag=$tag_check" >> $GITHUB_ENV + + - name: Clear release branch + run: | + branch_check=$(git branch -r | grep release/${{ env.tag }} | sed 's/remotes\/origin\///' | sed 's/origin\///' | sed 's/* //' | sed -r '/^\s*$/d' | head -1) + if [[ $branch_check ]]; then + git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --delete $branch_check + fi + + - name: Checkout develop and pull latest develop + run: | + git checkout develop + git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" develop + + - name: Pull master into develop + run: | + Conflicts=$(git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master -q --ff || echo "fatal: Not possible to fast-forward, aborting") + AbortingMsg='aborting' + + if [[ "$Conflicts" == *"$AbortingMsg"* ]]; then + exit 1 + fi + + - name: Pushing develop to origin if pulling successfully + if: success() + run: | + git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" develop:develop diff --git a/.github/workflows/release-github.yml b/.github/workflows/release-github.yml new file mode 100644 index 0000000..d304cff --- /dev/null +++ b/.github/workflows/release-github.yml @@ -0,0 +1,49 @@ +name: (NuGet) GitHub Packages Release + +on: + workflow_run: + workflows: [ "Build" ] + types: + - completed +jobs: + github_packages_release: + name: GitHub Packages Release + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event != 'pull_request' }} + runs-on: ubuntu-latest + env: + # GitHub Packages Feed settings + GITHUB_USER: thecogworks + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_FEED: https://nuget.pkg.github.com/thecogworks + GITHUB_PACKAGES_OUTPUT: ${{ github.workspace }}/github_packages + + # Project Setup + PROJECT_NAME: 'Cogworks.AzureSearch' + + steps: + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: master + fetch-depth: 0 + + - name: Get version + shell: bash + run: | + tag_check=$(git describe --exact-match `git rev-parse HEAD` | head -1) + echo "VERSION=$tag_check" >> $GITHUB_ENV + + - name: Download a single artifact + uses: aochmann/actions-download-artifact@1.0.2 + with: + name: build_${{ env.PROJECT_NAME }}.${{ env.VERSION }} + path: ${{ env.GITHUB_PACKAGES_OUTPUT }} + + - name: Push to GitHub Feed + shell: bash + working-directory: ${{ env.GITHUB_PACKAGES_OUTPUT }} + run: | + for nugetFile in ./*.nupkg + do + curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$nugetFile $GITHUB_FEED + done diff --git a/.github/workflows/release-nuget.yml b/.github/workflows/release-nuget.yml new file mode 100644 index 0000000..c9add94 --- /dev/null +++ b/.github/workflows/release-nuget.yml @@ -0,0 +1,54 @@ +name: (NuGet) NuGet Release + +on: + workflow_run: + workflows: [ "Build" ] + types: + - completed +jobs: + nuget_release: + name: NuGet Release + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event != 'pull_request' }} + runs-on: ubuntu-latest + env: + # Nuget Setup + NUGET_VERSION: 'latest' + NUGET_OUTPUT: ${{ github.workspace }}/nuget/ + NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }} + NUGET_FEED: https://api.nuget.org/v3/index.json + + # Project Setup + PROJECT_NAME: 'Cogworks.AzureSearch' + + steps: + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: master + fetch-depth: 0 + + - name: Get version + shell: bash + run: | + tag_check=$(git describe --exact-match `git rev-parse HEAD` | head -1) + echo "VERSION=$tag_check" >> $GITHUB_ENV + + - name: Download a single artifact + uses: aochmann/actions-download-artifact@1.0.2 + with: + name: build_${{ env.PROJECT_NAME }}.${{ env.VERSION }} + path: ${{ env.NUGET_OUTPUT }} + + - name: Configure NuGet + uses: nuget/setup-nuget@v1 + with: + nuget-version: ${{ env.NUGET_VERSION }} + + - name: Push to NuGet Feed + shell: bash + working-directory: ${{ env.NUGET_OUTPUT }} + run: | + for nugetFile in ./*.nupkg + do + nuget push $nugetFile ${{ env.NUGET_TOKEN }} -Source ${{ env.NUGET_FEED }} + done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 7f2ba8f..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,284 +0,0 @@ -name: Changelog generator and NuGet Releasing - -on: - push: - tags: - - '*' - -jobs: - changelog-generator: - runs-on: ubuntu-latest - env: - TagOnMaster: false - Branch: master - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - steps: - - uses: actions/checkout@v1 - - name: Set local user - run: | - git config --local user.email "devteam@thecogworks.com" - git config --local user.name "cogworks-infrastructure" - - name: Checkout to master from current head - run: | - git checkout master - git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master - - name: Checking if hotfix applied to master - run: | - HotFixOnMaster=$(git branch --contains refs/tags/`basename $GITHUB_REF` | sed 's/remotes\/origin\///' | sed 's/* //' | grep master) - - if [[ "$HotFixOnMaster" == *"master"* ]]; then - echo ::set-env name=TagOnMaster::true - fi - continue-on-error: true - - name: Set branch variable - if: env.TagOnMaster == 'false' || env.TagOnMaster == 0 - run: echo ::set-env name=Branch::$(git branch -a --contains refs/tags/`basename $GITHUB_REF` | sed 's/remotes\/origin\///' | sed 's/master//' | sed 's/* //' | grep release/`basename $GITHUB_REF`) - - name: Checkout to branch - run: | - echo Branch: $Branch - git checkout $Branch - - name: Check the tag - run: git describe --exact-match `git rev-parse HEAD` - - name: Get tag - run: echo ::set-env name=Tag::$(git describe --exact-match `git rev-parse HEAD`) - - name: Install dependencies - run: | - rm -rf node_modules - npm install - - name: Generate changelog and update npm version - run: npm run release - - name: Remove tag - run: git tag -d $Tag - - name: Updating tags - run: | - git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master - git tag -a $Tag -m "$Tag" - git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --tag -f - - name: Pushing latest changes to master - run: | - git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master - git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" $Branch:master - - - name: Deleting release branch - if: env.TagOnMaster == 'false' || env.TagOnMaster == 0 - run: git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --delete $Branch - - - name: Create file status_changelog-generator.txt and write the job status into it - if: always() - run: echo ${{ job.status }} > status_changelog-generator.txt - - name: Upload file status_changelog-generator.txt as an artifact - if: always() - uses: actions/upload-artifact@v1 - with: - name: pass_status_changelog-generator - path: status_changelog-generator.txt - - updating-branches: - needs: changelog-generator - runs-on: ubuntu-latest - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - - steps: - - uses: actions/checkout@v1 - - name: Set local user - run: | - git config --local user.email "devteam@thecogworks.com" - git config --local user.name "cogworks-infrastructure" - - name: Checkout develop and pull latest develop - run: | - git checkout develop - git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" develop - - name: Pull master into develop - run: | - Conflicts=$(git pull "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" master -q --ff-only || echo "fatal: Not possible to fast-forward, aborting") - AbortingMsg='aborting' - - if [[ "$Conflicts" == *"$AbortingMsg"* ]]; then - exit 1 - fi - - name: Pushing develop to origin if pulling successfully - if: success() - run: git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" develop:develop - - - name: Create file status_updating-branches.txt and write the job status into it - if: always() - run: echo ${{ job.status }} > status_updating-branches.txt - - name: Upload file status_updating-branches.txt as an artifact - if: always() - uses: actions/upload-artifact@v1 - with: - name: pass_status_updating-branches - path: status_updating-branches.txt - - nuget-release: - needs: changelog-generator - runs-on: windows-latest - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - - # Dotnet Setup - DOTNET_VERSION: 3.1.401 - - # Stop wasting time caching packages - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - - # Disable sending usage data to Microsoft - DOTNET_CLI_TELEMETRY_OPTOUT: true - - # Nuget Setup - NUGET_VERSION: 'latest' - NUGET_OUTPUT: output - - # Solution Setup - CONFIG: 'Release' - SOLUTION: 'Cogworks.AzureSearch.sln' - - # GitHub Packages Feed settings - GITHUB_USER: thecogworks - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_FEED: https://nuget.pkg.github.com/thecogworks - - # Official NuGet Feed settings - NUGET_FEED: https://api.nuget.org/v3/index.json - NUGET_KEY: ${{ secrets.NUGET_KEY }} - - steps: - - name: Checkout commit - uses: actions/checkout@v2 - with: - ref: master - - - name: Set Version based on tag - shell: bash - run: echo ::set-env name=VERSION::$(basename $GITHUB_REF) - - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} - - - uses: nuget/setup-nuget@v1 - with: - nuget-version: ${{ env.NUGET_VERSION }} - - - name: NuGet Restore - run: nuget restore ${{ env.SOLUTION }} -LockedMode - - - name: Install dependencies - run: dotnet restore ${{env.SOLUTION}} - - - name: Build - working-directory: ${{ github.workspace }} - run: dotnet build --configuration ${{ env.CONFIG }} ${{ env.SOLUTION }} - - - name: Pack all nuspec files - shell: bash - run: | - for nuspecFile in ./src/**/*.nuspec - do - nuget pack $nuspecFile -Version ${{ env.VERSION }} -Properties Configuration=${{ env.CONFIG }} -OutputDirectory .\${{ env.NUGET_OUTPUT }} - done - - - name: Push to GitHub Feed - shell: bash - run: | - for f in ./${{ env.NUGET_OUTPUT }}/*.nupkg - do - curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED - done - - - name: Push to NuGet Feed - run: dotnet nuget push .\${{ env.NUGET_OUTPUT }}\*.nupkg --source ${{ env.NUGET_FEED }} --skip-duplicate --api-key ${{ env.NUGET_KEY }} - - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: packages - path: ${{ env.NUGET_OUTPUT }}\*.nupkg - - finalization-and-notification: - needs: [changelog-generator, updating-branches] - if: always() - runs-on: ubuntu-latest - env: - Failure: "Failure" - Success: "Success" - steps: - - name: Download artifact pass_status_changelog-generator - uses: actions/download-artifact@v1 - with: - name: pass_status_changelog-generator - continue-on-error: true - - - name: Download artifact pass_status_updating-branches - uses: actions/download-artifact@v1 - with: - name: pass_status_updating-branches - continue-on-error: true - - - name: Set the statuses of jobs - id: set_outputs - run: | - if [ -f "pass_status_changelog-generator/status_changelog-generator.txt" ]; then - echo "::set-output name=status_changelog-generator::$( Date: Fri, 7 May 2021 08:56:44 +0200 Subject: [PATCH 02/31] chore: added vscode solution explorer templates --- .gitignore | 1 + .vscode/solution-explorer/class.cs-template | 6 +++++ .vscode/solution-explorer/enum.cs-template | 6 +++++ .../solution-explorer/interface.cs-template | 6 +++++ .vscode/solution-explorer/template-list.json | 22 +++++++++++++++++++ .../solution-explorer/template-parameters.js | 17 ++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 .vscode/solution-explorer/class.cs-template create mode 100644 .vscode/solution-explorer/enum.cs-template create mode 100644 .vscode/solution-explorer/interface.cs-template create mode 100644 .vscode/solution-explorer/template-list.json create mode 100644 .vscode/solution-explorer/template-parameters.js diff --git a/.gitignore b/.gitignore index 84a9006..f83d2f0 100644 --- a/.gitignore +++ b/.gitignore @@ -608,6 +608,7 @@ fabric.properties ### VisualStudioCode ### .vscode/* +!.vscode/solution-explorer !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json diff --git a/.vscode/solution-explorer/class.cs-template b/.vscode/solution-explorer/class.cs-template new file mode 100644 index 0000000..f494012 --- /dev/null +++ b/.vscode/solution-explorer/class.cs-template @@ -0,0 +1,6 @@ +namespace {{namespace}} +{ + public class {{name}} + { + } +} diff --git a/.vscode/solution-explorer/enum.cs-template b/.vscode/solution-explorer/enum.cs-template new file mode 100644 index 0000000..51e86bb --- /dev/null +++ b/.vscode/solution-explorer/enum.cs-template @@ -0,0 +1,6 @@ +namespace {{namespace}} +{ + public enum {{name}} + { + } +} diff --git a/.vscode/solution-explorer/interface.cs-template b/.vscode/solution-explorer/interface.cs-template new file mode 100644 index 0000000..6a423e0 --- /dev/null +++ b/.vscode/solution-explorer/interface.cs-template @@ -0,0 +1,6 @@ +namespace {{namespace}} +{ + public interface {{name}} + { + } +} diff --git a/.vscode/solution-explorer/template-list.json b/.vscode/solution-explorer/template-list.json new file mode 100644 index 0000000..ec73048 --- /dev/null +++ b/.vscode/solution-explorer/template-list.json @@ -0,0 +1,22 @@ +{ + "templates": [ + { + "name": "Class", + "extension": "cs", + "file": "./class.cs-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Interface", + "extension": "cs", + "file": "./interface.cs-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Enum", + "extension": "cs", + "file": "./enum.cs-template", + "parameters": "./template-parameters.js" + } + ] +} \ No newline at end of file diff --git a/.vscode/solution-explorer/template-parameters.js b/.vscode/solution-explorer/template-parameters.js new file mode 100644 index 0000000..daba8b2 --- /dev/null +++ b/.vscode/solution-explorer/template-parameters.js @@ -0,0 +1,17 @@ +var path = require("path"); + +module.exports = function(filename, projectPath, folderPath) { + var namespace = "Unknown"; + if (projectPath) { + namespace = path.basename(projectPath, path.extname(projectPath)); + if (folderPath) { + namespace += "." + folderPath.replace(path.dirname(projectPath), "").substring(1).replace(/[\\\/]/g, "."); + } + namespace = namespace.replace(/[\\\-]/g, "_"); + } + + return { + namespace: namespace, + name: path.basename(filename, path.extname(filename)) + } +}; \ No newline at end of file From 99f09fe58b76ff4b24cd3f047903a7c132907d28 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Mon, 10 May 2021 11:26:26 +0200 Subject: [PATCH 03/31] feat: sdk update + refactor --- .../Builder/IAzureSearchBuilder.cs | 29 ++++ .../Cogworks.AzureCognitiveSearch.csproj | 15 ++ .../Constants/StringConstants/Separators.cs | 9 ++ .../Constants/StringConstants/Terms.cs | 7 + .../Enums/AzureQueryType.cs | 8 + .../Enums/AzureSearchModeType.cs | 8 + .../AddOrUpdateDocumentException.cs | 18 +++ .../RemoveDocumentException.cs | 17 +++ .../Exceptions/DomainException.cs | 18 +++ .../IndexExceptions/IndexClearException.cs | 18 +++ .../IndexCreateOrUpdateException.cs | 17 +++ .../IndexExceptions/IndexDeleteException.cs | 17 +++ .../Extensions/EnumerableExtensions.cs | 18 +++ .../Extensions/StringExtensions.cs | 20 +++ .../Interfaces/Indexes/IAzureIndex.cs | 19 +++ .../Initializers/IAzureInitializer.cs | 11 ++ .../Operations/IAzureDocumentOperation.cs | 18 +++ .../Operations/IAzureIndexOperation.cs | 17 +++ .../Repositories/IAzureSearchRepository.cs | 12 ++ .../Wrappers/IDocumentOperationWrapper.cs | 17 +++ .../Wrappers/IIndexOperationWrapper.cs | 17 +++ .../Mappers/AzureSearchParametersMapper.cs | 79 ++++++++++ .../Models/AzureIndexDefinition.cs | 17 +++ .../Models/AzureSearchParameters.cs | 38 +++++ .../AzureBatchDocumentsOperationResult.cs | 16 ++ .../Dtos/AzureDocumentOperationResult.cs | 15 ++ .../Models/Dtos/AzureIndexOperationResult.cs | 9 ++ .../Models/Dtos/SearchResult.cs | 13 ++ .../Models/Dtos/SearchResultItem.cs | 20 +++ .../Models/IAzureModel.cs | 6 + .../Models/IAzureModelIdentity.cs | 7 + .../Options/AzureSearchClientOption.cs | 48 ++++++ .../Options/AzureSearchIndexOption.cs | 15 ++ .../Repositories/AzureSearchRepository.cs | 48 ++++++ .../Services/AzureDocumentOperationService.cs | 141 ++++++++++++++++++ .../Services/AzureIndexOperationService.cs | 76 ++++++++++ .../Wrappers/DocumentOperationWrapper.cs | 43 ++++++ .../Wrappers/IndexOperationWrapper.cs | 56 +++++++ Cogworks.AzureSearch.sln | 9 +- 39 files changed, 985 insertions(+), 1 deletion(-) create mode 100644 Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs create mode 100644 Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj create mode 100644 Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs create mode 100644 Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs create mode 100644 Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs create mode 100644 Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/DomainException.cs create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexClearException.cs create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexDeleteException.cs create mode 100644 Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs create mode 100644 Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs create mode 100644 Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs create mode 100644 Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs create mode 100644 Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs create mode 100644 Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs create mode 100644 Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs create mode 100644 Cogworks.AzureCognitiveSearch/Services/AzureDocumentOperationService.cs create mode 100644 Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs create mode 100644 Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs create mode 100644 Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs diff --git a/Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs b/Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs new file mode 100644 index 0000000..d3a7f1e --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs @@ -0,0 +1,29 @@ +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureCognitiveSearch.Interfaces.Searches; +using Cogworks.AzureCognitiveSearch.Models; + +namespace Cogworks.AzureCognitiveSearch.Builder +{ + public interface IAzureSearchBuilder + { + IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false); + + IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials); + + IAzureSearchBuilder RegisterIndexDefinitions(string indexName) + where TDocument : class, IAzureModel, new(); + + IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) + where TDocument : class, IAzureModel, new(); + + IAzureSearchBuilder RegisterDomainSearcher() + where TDocument : class, IAzureModel, new() + where TSearcher : class, IAzureSearch, TSearcherType + where TSearcherType : class; + + IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) + where TDocument : class, IAzureModel, new() + where TSearcher : class, IAzureSearch, TSearcherType + where TSearcherType : class; + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj b/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj new file mode 100644 index 0000000..837c0a2 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + + + + + + + + + + + diff --git a/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs b/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs new file mode 100644 index 0000000..83aeded --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs @@ -0,0 +1,9 @@ +namespace Cogworks.AzureCognitiveSearch.Constants.StringConstants +{ + internal class Separators + { + public const string Comma = ","; + public const string Vertical = "|"; + public const string Hyphen = "-"; + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs b/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs new file mode 100644 index 0000000..76bffe9 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs @@ -0,0 +1,7 @@ +namespace Cogworks.AzureCognitiveSearch.Constants.StringConstants +{ + internal class Terms + { + public const string Null = "null"; + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs b/Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs new file mode 100644 index 0000000..9cf50d7 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs @@ -0,0 +1,8 @@ +namespace Cogworks.AzureCognitiveSearch.Enums +{ + public enum AzureQueryType + { + Simple = 0, + Full = 1 + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs b/Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs new file mode 100644 index 0000000..b582914 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs @@ -0,0 +1,8 @@ +namespace Cogworks.AzureCognitiveSearch.Enums +{ + public enum AzureSearchModeType + { + Any = 0, + All = 1 + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs new file mode 100644 index 0000000..406a151 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs @@ -0,0 +1,18 @@ +using System; + +namespace Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions +{ + public class AddOrUpdateDocumentException : DomainException + { + + public override string Code => "add_or_update_document_exception"; + + public AddOrUpdateDocumentException(string message) : base(message) + { + } + + public AddOrUpdateDocumentException(string message, Exception innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs new file mode 100644 index 0000000..ca7053e --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions +{ + public class RemoveDocumentException : DomainException + { + public override string Code => "remove_document_exception"; + + public RemoveDocumentException(string message) : base(message) + { + } + + public RemoveDocumentException(string message, Exception innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/DomainException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/DomainException.cs new file mode 100644 index 0000000..a95f0b6 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/DomainException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections; + +namespace Cogworks.AzureCognitiveSearch.Exceptions +{ + public abstract class DomainException : Exception + { + public abstract string Code { get; } + + protected DomainException(string message) : base(message) + { + } + + protected DomainException(string message, Exception innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexClearException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexClearException.cs new file mode 100644 index 0000000..b7f24ab --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexClearException.cs @@ -0,0 +1,18 @@ +using System; + +namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +{ + public class IndexClearException : DomainException + { + public override string Code => "index_clear_error"; + + public IndexClearException(string message) : base(message) + { + } + + public IndexClearException(string message, Exception innerException) : base(message, innerException) + { + } + + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs new file mode 100644 index 0000000..4042284 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +{ + public class IndexCreateOrUpdateException :DomainException + { + public override string Code => "index_create_or_update_error"; + + public IndexCreateOrUpdateException(string message) : base(message) + { + } + + public IndexCreateOrUpdateException(string message, Exception innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexDeleteException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexDeleteException.cs new file mode 100644 index 0000000..7884c66 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexDeleteException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +{ + public class IndexDeleteException : DomainException + { + public override string Code => "index_delete_error"; + + public IndexDeleteException(string message) : base(message) + { + } + + public IndexDeleteException(string message, Exception innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs b/Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs new file mode 100644 index 0000000..8906779 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Cogworks.AzureCognitiveSearch.Extensions +{ + internal static class EnumerableExtensions + { + public static bool HasAny(this IEnumerable items) + => items != null && items.Any(); + + public static IEnumerable> ChunkBy(this IEnumerable items, int chunkSize) + => items + .Select((x, i) => new { Index = i, Value = x }) + .GroupBy(x => x.Index / chunkSize) + .Select(x => x.Select(v => v.Value).ToList()) + .ToList(); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs b/Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs new file mode 100644 index 0000000..6c3c5ba --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs @@ -0,0 +1,20 @@ +using Cogworks.AzureCognitiveSearch.Constants.StringConstants; + +namespace Cogworks.AzureCognitiveSearch.Extensions +{ + internal static class StringExtensions + { + public static bool HasValue(this string input) + => !string.IsNullOrWhiteSpace(input); + + public static string EscapeHyphen(this string input) + => input.Escape(Separators.Hyphen); + + public static string Escape(this string input, string character) + => input.HasValue() + ? input.Replace( + $"{character}", + $@"\{character}") + : input; + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs new file mode 100644 index 0000000..5875c5a --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs @@ -0,0 +1,19 @@ + +using System.Collections.Generic; +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Indexes +{ + public interface IAzureIndex where TAzureModel : class, IAzureModel, new() + { + Task AddOrUpdateDocumentAsync(TAzureModel model); + + Task AddOrUpdateDocumentsAsync(IEnumerable models); + + Task TryRemoveDocumentAsync(TAzureModel model); + + Task TryRemoveDocumentsAsync(IEnumerable models); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs new file mode 100644 index 0000000..d8fbbb9 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs @@ -0,0 +1,11 @@ +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; +using System.Threading.Tasks; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Initializers +{ + public interface IAzureInitializer where TAzureModel : class, IAzureModel, new() + { + Task InitializeAsync(); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs new file mode 100644 index 0000000..f0dd705 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Operations +{ + public interface IAzureDocumentOperation where TAzureModel : class, IAzureModel, new() + { + Task AddOrUpdateDocumentAsync(TAzureModel model); + + Task AddOrUpdateDocumentsAsync(IEnumerable models); + + Task TryRemoveDocumentAsync(TAzureModel model); + + Task TryRemoveDocumentsAsync(IEnumerable models); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs new file mode 100644 index 0000000..f068234 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Operations +{ + public interface IAzureIndexOperation where TAzureModel : class, IAzureModel, new() + { + Task IndexExistsAsync(); + + Task IndexDeleteAsync(); + + Task IndexCreateOrUpdateAsync(); + + Task IndexClearAsync(); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs new file mode 100644 index 0000000..07e47a2 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs @@ -0,0 +1,12 @@ +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Models; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Repositories +{ + public interface IAzureSearchRepository : + IAzureDocumentOperation, + IAzureIndexOperation + where TAzureModel : class, IAzureModel, new() + { + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs new file mode 100644 index 0000000..4bf49f2 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; +using Azure; +using Azure.Search.Documents; +using Azure.Search.Documents.Models; +using Cogworks.AzureCognitiveSearch.Models; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Wrappers +{ + public interface IDocumentOperationWrapper where TAzureModel : class, IAzureModel, new() + { + SearchResults Search(string searchText, SearchOptions parameters = null); + + Task>> SearchAsync(string searchText, SearchOptions parameters = null); + + Task> IndexAsync(IndexDocumentsBatch indexBatch); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs new file mode 100644 index 0000000..bc902fb --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureCognitiveSearch.Models; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Wrappers +{ + public interface IIndexOperationWrapper + { + Task ExistsAsync(string indexName); + + Task DeleteAsync(string indexName); + + Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new(); + + Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new(); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs b/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs new file mode 100644 index 0000000..1f63d4d --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs @@ -0,0 +1,79 @@ +using System.Linq; +using Azure.Search.Documents; +using Azure.Search.Documents.Models; +using Cogworks.AzureCognitiveSearch.Enums; +using Cogworks.AzureCognitiveSearch.Extensions; +using Cogworks.AzureCognitiveSearch.Models; + +namespace Cogworks.AzureCognitiveSearch.Mappers +{ + public static class AzureSearchParametersMapper + { + internal static SearchOptions GetSearchParameters(AzureSearchParameters azureSearchParameters) + { + var searchParameters = new SearchOptions + { + Filter = azureSearchParameters.Filter, + HighlightPostTag = azureSearchParameters.HighlightPostTag, + HighlightPreTag = azureSearchParameters.HighlightPreTag, + IncludeTotalCount = azureSearchParameters.IncludeTotalResultCount, + MinimumCoverage = azureSearchParameters.MinimumCoverage, + QueryType = azureSearchParameters.QueryType == AzureQueryType.Full + ? SearchQueryType.Full + : SearchQueryType.Simple, + ScoringProfile = azureSearchParameters.ScoringProfile, + SearchMode = azureSearchParameters.SearchMode == AzureSearchModeType.Any + ? SearchMode.Any + : SearchMode.All, + Skip = azureSearchParameters.Skip, + Size = azureSearchParameters.Take + }; + + if (azureSearchParameters.Select.HasAny()) + { + foreach (var selectField in azureSearchParameters.Select) + { + searchParameters.Select.Add(selectField); + } + } + + if (azureSearchParameters.SearchFields.HasAny()) + { + foreach (var searchField in azureSearchParameters.SearchFields) + { + searchParameters.SearchFields.Add(searchField); + } + } + + + if (azureSearchParameters.HighlightFields.HasAny()) + { + foreach (var highlightField in azureSearchParameters.HighlightFields) + { + searchParameters.HighlightFields.Add(highlightField); + } + + } + + if (azureSearchParameters.Facets.HasAny()) + { + foreach (var facet in azureSearchParameters.Facets) + { + searchParameters.Facets.Add(facet); + } + + } + + if (azureSearchParameters.OrderBy.HasAny()) + { + foreach (var order in azureSearchParameters.OrderBy) + { + searchParameters.OrderBy.Add(order); + } + + } + + return searchParameters; + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs b/Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs new file mode 100644 index 0000000..78eb199 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs @@ -0,0 +1,17 @@ +using Azure.Search.Documents.Indexes.Models; + +namespace Cogworks.AzureCognitiveSearch.Models +{ + public class AzureIndexDefinition where TAzureModel : class, IAzureModel, new() + { + public string IndexName { get; } + + public SearchIndex CustomIndexDefinition { get; } + + public AzureIndexDefinition(string indexName) + => IndexName = indexName; + + public AzureIndexDefinition(SearchIndex customIndex) + => (CustomIndexDefinition, IndexName) = (customIndex, customIndex.Name); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs b/Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs new file mode 100644 index 0000000..4872e3a --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using Cogworks.AzureCognitiveSearch.Enums; + +namespace Cogworks.AzureCognitiveSearch.Models +{ + public class AzureSearchParameters + { + public bool IncludeTotalResultCount { get; set; } + + public IEnumerable Facets { get; set; } + + public string Filter { get; set; } + + public IEnumerable HighlightFields { get; set; } + + public string HighlightPostTag { get; set; } + + public string HighlightPreTag { get; set; } + + public double? MinimumCoverage { get; set; } + + public IEnumerable OrderBy { get; set; } + + public AzureQueryType QueryType { get; set; } + + public string ScoringProfile { get; set; } + + public IEnumerable SearchFields { get; set; } + + public AzureSearchModeType SearchMode { get; set; } + + public IEnumerable Select { get; set; } + + public int Skip { get; set; } + + public int Take { get; set; } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs new file mode 100644 index 0000000..6152c97 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Cogworks.AzureCognitiveSearch.Models.Dtos +{ + public class AzureBatchDocumentsOperationResult + { + public bool Succeeded { get; set; } + + public string Message { get; set; } + + public IEnumerable SucceededDocuments { get; set; } = Enumerable.Empty(); + + public IEnumerable FailedDocuments { get; set; } = Enumerable.Empty(); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs new file mode 100644 index 0000000..f1e0423 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs @@ -0,0 +1,15 @@ +namespace Cogworks.AzureCognitiveSearch.Models.Dtos +{ + public class AzureDocumentOperationResult + { + public bool Succeeded { get; set; } + + public string ModelId { get; set; } + + public string Message { get; set; } + + public string InnerMessage { get; set; } + + public int StatusCode { get; set; } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs new file mode 100644 index 0000000..96ae3fa --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs @@ -0,0 +1,9 @@ +namespace Cogworks.AzureCognitiveSearch.Models.Dtos +{ + public class AzureIndexOperationResult + { + public bool Succeeded { get; set; } + + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs new file mode 100644 index 0000000..c5dedd8 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Cogworks.AzureCognitiveSearch.Models.Dtos +{ + public class SearchResult where TModel : class, IAzureModel, new() + { + public long TotalCount { get; set; } + + public IEnumerable> Results { get; set; } + + public bool HasMoreItems { get; set; } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs new file mode 100644 index 0000000..88d6934 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Cogworks.AzureCognitiveSearch.Models.Dtos +{ + public class SearchResultItem where TModel : class, IAzureModel, new() + { + public TModel Document { get; } + + public IDictionary> Highlights { get; } + + public double Score { get; } + + public SearchResultItem(TModel document, IDictionary> highlights, double score) + { + Document = document; + Highlights = highlights; + Score = score; + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs b/Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs new file mode 100644 index 0000000..631bf95 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs @@ -0,0 +1,6 @@ +namespace Cogworks.AzureCognitiveSearch.Models +{ + public interface IAzureModel + { + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs b/Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs new file mode 100644 index 0000000..3bca2a9 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs @@ -0,0 +1,7 @@ +namespace Cogworks.AzureCognitiveSearch.Models +{ + public interface IAzureModelIdentity : IAzureModel + { + string Id { get; set; } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs b/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs new file mode 100644 index 0000000..738c2d5 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs @@ -0,0 +1,48 @@ +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Search.Documents; + +namespace Cogworks.AzureCognitiveSearch.Options +{ + public class AzureSearchClientOption + { + public string ServiceName { get; } + + public string Credentials { get; } + + public string ServiceUrlEndpoint { get; } + + public SearchClientOptions ClientOptions { get; } + + + + public AzureSearchClientOption(string serviceName, string credentials, string serviceUrlEndpoint) + { + ServiceName = serviceName; + Credentials = credentials; + ServiceUrlEndpoint = serviceUrlEndpoint; + ClientOptions = GetOptions(); + } + + + private SearchClientOptions GetOptions() + { + var clientOptions = new SearchClientOptions(); + + + clientOptions.AddPolicy( + new SearchIdPipelinePolicy(), + HttpPipelinePosition.PerCall); + + return clientOptions; + } + + private class SearchIdPipelinePolicy : HttpPipelineSynchronousPolicy + { + public override void OnSendingRequest(HttpMessage message) + => message.Request + .Headers + .SetValue("x-ms-azs-return-searchid", "true"); + } +} +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs b/Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs new file mode 100644 index 0000000..35efb01 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs @@ -0,0 +1,15 @@ +namespace Cogworks.AzureCognitiveSearch.Options +{ + public class AzureSearchIndexOption + { + public bool Recreate { get; } + + public bool RecreateOnUpdateFailure { get; } + + public AzureSearchIndexOption(bool recreate, bool recreateOnUpdateFailure) + { + Recreate = recreate; + RecreateOnUpdateFailure = recreateOnUpdateFailure; + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs b/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs new file mode 100644 index 0000000..7cd995d --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Interfaces.Repositories; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Repositories +{ + internal class AzureSearchRepository : IAzureSearchRepository + where TAzureModel : class, IAzureModel, new() + { + private readonly IAzureIndexOperation _indexOperation; + private readonly IAzureDocumentOperation _documentOperation; + + public AzureSearchRepository( + IAzureIndexOperation indexOperation, + IAzureDocumentOperation documentOperation) + { + _indexOperation = indexOperation; + _documentOperation = documentOperation; + } + + public async Task AddOrUpdateDocumentAsync(TAzureModel model) + => await _documentOperation.AddOrUpdateDocumentAsync(model); + + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + => await _documentOperation.AddOrUpdateDocumentsAsync(models); + + public async Task TryRemoveDocumentAsync(TAzureModel model) + => await _documentOperation.TryRemoveDocumentAsync(model); + + public async Task TryRemoveDocumentsAsync(IEnumerable models) + => await _documentOperation.TryRemoveDocumentsAsync(models); + + public async Task IndexExistsAsync() + => await _indexOperation.IndexExistsAsync(); + + public async Task IndexDeleteAsync() + => await _indexOperation.IndexDeleteAsync(); + + public async Task IndexCreateOrUpdateAsync() + => await _indexOperation.IndexCreateOrUpdateAsync(); + + public async Task IndexClearAsync() + => await _indexOperation.IndexClearAsync(); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Services/AzureDocumentOperationService.cs b/Cogworks.AzureCognitiveSearch/Services/AzureDocumentOperationService.cs new file mode 100644 index 0000000..f7774a9 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Services/AzureDocumentOperationService.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Azure.Search.Documents.Models; +using Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions; +using Cogworks.AzureCognitiveSearch.Extensions; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Services +{ + public class AzureDocumentOperationService : IAzureDocumentOperation + where TAzureModel : class, IAzureModel, new() + { + private readonly IDocumentOperationWrapper _documentOperationWrapper; + + private const int BatchOperationSize = 500; + + public AzureDocumentOperationService(IDocumentOperationWrapper documentOperationWrapper) + => _documentOperationWrapper = documentOperationWrapper; + + + public async Task AddOrUpdateDocumentAsync(TAzureModel model) + { + var azureBatchDocumentsOperationResult = await AddOrUpdateDocumentsAsync(new[] { model }); + + return azureBatchDocumentsOperationResult.Succeeded + ? azureBatchDocumentsOperationResult.SucceededDocuments.FirstOrDefault() + : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); + } + + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + { + if (!models.HasAny()) + { + return new AzureBatchDocumentsOperationResult() + { + Succeeded = true, + Message = "No documents found to index." + }; + } + + var chunkedBatchActions = models + .Select(IndexDocumentsAction.MergeOrUpload) + .ChunkBy(BatchOperationSize) + .ToList(); + + var indexResults = new List(); + + foreach (var batchActions in chunkedBatchActions) + { + var batch = IndexDocumentsBatch.Create(batchActions.ToArray()); + + try + { + var result = await _documentOperationWrapper.IndexAsync(batch); + indexResults.AddRange(result.Value.Results); + } + catch (Exception exception) + { + throw new AddOrUpdateDocumentException(exception.Message, exception.InnerException); + } + } + + return GetBatchOperationStatus(indexResults, "adding or updating"); + } + + public async Task TryRemoveDocumentAsync(TAzureModel model) + { + var azureBatchDocumentsOperationResult = await TryRemoveDocumentsAsync(new[] { model }); + + return azureBatchDocumentsOperationResult.Succeeded + ? azureBatchDocumentsOperationResult.SucceededDocuments.FirstOrDefault() + : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); + } + + public async Task TryRemoveDocumentsAsync(IEnumerable models) + { + if (!models.HasAny()) + { + return new AzureBatchDocumentsOperationResult() + { + Succeeded = true, + Message = "No documents found to delete." + }; + } + + var chunkedBatchActions = models + .Select(IndexDocumentsAction.Delete) + .ChunkBy(BatchOperationSize) + .ToList(); + + var indexResults = new List(); + + foreach (var batchActions in chunkedBatchActions) + { + var batch = IndexDocumentsBatch.Create(batchActions.ToArray()); + + try + { + var result = await _documentOperationWrapper.IndexAsync(batch); + indexResults.AddRange(result.Value.Results); + } + catch (Exception exception) + { + throw new RemoveDocumentException(exception.Message, exception.InnerException); + } + } + + return GetBatchOperationStatus(indexResults, "removing"); + } + + private static AzureBatchDocumentsOperationResult GetBatchOperationStatus(IEnumerable indexingResults, string operationType) + { + var successfullyItems = indexingResults.Where(x => x.Succeeded).ToList(); + var failedItems = indexingResults.Where(x => !x.Succeeded).ToList(); + + return new AzureBatchDocumentsOperationResult + { + Succeeded = !failedItems.Any(), + SucceededDocuments = successfullyItems.Select(successfullyItem => new AzureDocumentOperationResult + { + Succeeded = true, + Message = $"Successfully {operationType} document.", + ModelId = successfullyItem.Key, + StatusCode = successfullyItem.Status + }).ToList(), + FailedDocuments = failedItems.Select(failedItem => new AzureDocumentOperationResult + { + Message = $"Failed {operationType} document.", + InnerMessage = failedItem.ErrorMessage, + ModelId = failedItem.Key, + StatusCode = failedItem.Status + }).ToList() + }; + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs b/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs new file mode 100644 index 0000000..86e9669 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs @@ -0,0 +1,76 @@ +using System; +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Exceptions; +using Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Services +{ + public class AzureIndexOperationService : IAzureIndexOperation + where TAzureModel : class, IAzureModel, new() + { + private readonly AzureIndexDefinition _azureIndexDefinition; + private readonly IIndexOperationWrapper _indexOperationWrapper; + + public AzureIndexOperationService( + AzureIndexDefinition azureIndexDefinition, + IIndexOperationWrapper indexOperationWrapper) + { + _azureIndexDefinition = azureIndexDefinition; + _indexOperationWrapper = indexOperationWrapper; + } + + public async Task IndexExistsAsync() + => await _indexOperationWrapper.ExistsAsync(_azureIndexDefinition.IndexName); + + public async Task IndexDeleteAsync() + { + try + { + await _indexOperationWrapper.DeleteAsync(_azureIndexDefinition.IndexName); + } + catch (Exception exception) + { + throw new IndexDeleteException(exception.Message, exception.InnerException); + } + } + + public async Task IndexCreateOrUpdateAsync() + { + try + { + + _ = _azureIndexDefinition.CustomIndexDefinition != null + ? await _indexOperationWrapper.CreateOrUpdateAsync(_azureIndexDefinition.CustomIndexDefinition, true) + : await _indexOperationWrapper.CreateOrUpdateAsync(_azureIndexDefinition.IndexName); + + } + catch (Exception exception) + { + throw new IndexCreateOrUpdateException(exception.Message, exception.InnerException); + + } + } + + public async Task IndexClearAsync() + { + try + { + if (await IndexExistsAsync()) + { + await IndexDeleteAsync(); + } + + await IndexCreateOrUpdateAsync(); + + } + catch (Exception exception) + { + throw new IndexClearException(exception.Message, exception.InnerException); + } + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs new file mode 100644 index 0000000..48ea247 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs @@ -0,0 +1,43 @@ + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Search.Documents; +using Azure.Search.Documents.Models; +using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Options; + +namespace Cogworks.AzureCognitiveSearch.Wrappers +{ + internal class DocumentOperationWrapper : IDocumentOperationWrapper + where TAzureModel : class, IAzureModel, new() + { + private readonly SearchClient _searchClient; + + + public DocumentOperationWrapper( + AzureIndexDefinition azureIndexDefinition, + AzureSearchClientOption azureSearchClientOption) + { + var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); + + _searchClient = new SearchClient( + endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), + indexName: azureIndexDefinition.IndexName, + credential: azureKeyCredential, + options: azureSearchClientOption.ClientOptions + + ); + } + + public SearchResults Search(string searchText, SearchOptions parameters = null) + => _searchClient.Search(searchText, parameters); + + public async Task>> SearchAsync(string searchText, SearchOptions parameters = null) + => await _searchClient.SearchAsync(searchText, parameters); + + public async Task> IndexAsync(IndexDocumentsBatch indexBatch) + => await _searchClient.IndexDocumentsAsync(indexBatch); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs new file mode 100644 index 0000000..71417d6 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs @@ -0,0 +1,56 @@ +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Search.Documents.Indexes; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Options; + +namespace Cogworks.AzureCognitiveSearch.Wrappers +{ + internal class IndexOperationWrapper : IIndexOperationWrapper + { + private readonly SearchIndexClient _searchIndexClient; + + public IndexOperationWrapper(AzureSearchClientOption azureSearchClientOption) + { + var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); + + _searchIndexClient = new SearchIndexClient( + endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), + credential: azureKeyCredential); + } + + public async Task ExistsAsync(string indexName) + => (await _searchIndexClient.GetIndexAsync(indexName)).Value != null; + + public async Task DeleteAsync(string indexName) + => await _searchIndexClient.DeleteIndexAsync(indexName); + + public async Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new() + { + var fieldBuilder = new FieldBuilder(); + var searchFields = fieldBuilder.Build(typeof(TAzureModel)); + + var definition = new SearchIndex( + indexName, + searchFields); + + return await _searchIndexClient.CreateOrUpdateIndexAsync(definition); + } + + public async Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new() + { + if (overrideFields) + { + var fieldBuilder = new FieldBuilder(); + var searchFields = fieldBuilder.Build(typeof(TAzureModel)); + + customIndexDefinition.Fields = searchFields; + } + + return await _searchIndexClient.CreateOrUpdateIndexAsync(customIndexDefinition); + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureSearch.sln b/Cogworks.AzureSearch.sln index 6f23936..a88dc5e 100644 --- a/Cogworks.AzureSearch.sln +++ b/Cogworks.AzureSearch.sln @@ -21,7 +21,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cogworks.AzureSearch.Umbrac EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.LightInject.IocExtension", "src\Cogworks.AzureSearch.LightInject.IocExtension\Cogworks.AzureSearch.LightInject.IocExtension.csproj", "{4C606328-9108-4584-8E4A-04450B9A1170}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cogworks.AzureSearch.Microsoft.IocExtension", "src\Cogworks.AzureSearch.Microsoft.IocExtension\Cogworks.AzureSearch.Microsoft.IocExtension.csproj", "{E60BD2A0-C5ED-4EFE-8F8A-15FB26AD69B4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.Microsoft.IocExtension", "src\Cogworks.AzureSearch.Microsoft.IocExtension\Cogworks.AzureSearch.Microsoft.IocExtension.csproj", "{E60BD2A0-C5ED-4EFE-8F8A-15FB26AD69B4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.MicrosoftIoc.UnitTests", "tests\UnitTests\Cogworks.AzureSearch.MicrosoftIoc.UnitTests\Cogworks.AzureSearch.MicrosoftIoc.UnitTests.csproj", "{1F9F4E09-E496-49F2-A1EB-D4EB3AC3E721}" EndProject @@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.Autofa EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.LightInject.UnitTests", "tests\UnitTests\Cogworks.AzureSearch.LightInject.UnitTests\Cogworks.AzureSearch.LightInject.UnitTests.csproj", "{90E65F2C-9592-473C-83BB-FC109A11C47D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cogworks.AzureCognitiveSearch", "Cogworks.AzureCognitiveSearch\Cogworks.AzureCognitiveSearch.csproj", "{A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -75,6 +77,10 @@ Global {90E65F2C-9592-473C-83BB-FC109A11C47D}.Debug|Any CPU.Build.0 = Debug|Any CPU {90E65F2C-9592-473C-83BB-FC109A11C47D}.Release|Any CPU.ActiveCfg = Release|Any CPU {90E65F2C-9592-473C-83BB-FC109A11C47D}.Release|Any CPU.Build.0 = Release|Any CPU + {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -91,6 +97,7 @@ Global {1F9F4E09-E496-49F2-A1EB-D4EB3AC3E721} = {180E9BD6-30B9-4D88-B88C-9F289D316967} {0648AF35-71D5-4BA4-A1BF-0476AAC71BEE} = {180E9BD6-30B9-4D88-B88C-9F289D316967} {90E65F2C-9592-473C-83BB-FC109A11C47D} = {180E9BD6-30B9-4D88-B88C-9F289D316967} + {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DC813CF7-BD65-4CD5-B0B7-7B1F828A9909} From 85cb71fd83052742d8ce41f2c49e41bb0a7ce27d Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Mon, 10 May 2021 12:38:17 +0200 Subject: [PATCH 04/31] refactor: refactor search --- .../Searches/IAzureDocumentSearch.cs | 12 +++++ .../Interfaces/Searches/IAzureSearch.cs | 13 +++++ .../Wrappers/IDocumentOperationWrapper.cs | 2 +- .../Mappers/AzureSearchParametersMapper.cs | 2 +- .../Mappers/SearchResultMapper.cs | 32 ++++++++++++ .../Searchers/AzureSearch.cs | 49 +++++++++++++++++++ .../Wrappers/DocumentOperationWrapper.cs | 2 +- 7 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs create mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs create mode 100644 Cogworks.AzureCognitiveSearch/Mappers/SearchResultMapper.cs create mode 100644 Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs new file mode 100644 index 0000000..a832190 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs @@ -0,0 +1,12 @@ +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Models; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Searches +{ + public interface IAzureDocumentSearch where TAzureModel : class, IAzureModel, new() + { + Models.Dtos.SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters); + + Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs new file mode 100644 index 0000000..2a65c09 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Interfaces.Searches +{ + public interface IAzureSearch where TAzureModel : class, IAzureModel, new() + { + SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters); + + Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters); + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs index 4bf49f2..dffeca0 100644 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs @@ -10,7 +10,7 @@ namespace Cogworks.AzureCognitiveSearch.Interfaces.Wrappers { SearchResults Search(string searchText, SearchOptions parameters = null); - Task>> SearchAsync(string searchText, SearchOptions parameters = null); + Task> SearchAsync(string searchText, SearchOptions parameters = null); Task> IndexAsync(IndexDocumentsBatch indexBatch); } diff --git a/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs b/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs index 1f63d4d..b94f76a 100644 --- a/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs +++ b/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs @@ -9,7 +9,7 @@ namespace Cogworks.AzureCognitiveSearch.Mappers { public static class AzureSearchParametersMapper { - internal static SearchOptions GetSearchParameters(AzureSearchParameters azureSearchParameters) + internal static SearchOptions Map(AzureSearchParameters azureSearchParameters) { var searchParameters = new SearchOptions { diff --git a/Cogworks.AzureCognitiveSearch/Mappers/SearchResultMapper.cs b/Cogworks.AzureCognitiveSearch/Mappers/SearchResultMapper.cs new file mode 100644 index 0000000..f555192 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Mappers/SearchResultMapper.cs @@ -0,0 +1,32 @@ +using System.Linq; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Mappers +{ + public static class SearchResultMapper + { + public static SearchResult Map( + Azure.Search.Documents.Models.SearchResults results, + int skip, + int take) where TAzureModel : class, IAzureModel, new() + { + var resultsCount = results.TotalCount ?? 0; + + var searchedDocuments = results.GetResults() + .Select(resultDocument => new SearchResultItem( + resultDocument.Document, + resultDocument.Highlights, + resultDocument.Score ?? default + )) + .ToArray(); + + return new SearchResult() + { + HasMoreItems = skip + take < resultsCount, + TotalCount = resultsCount, + Results = searchedDocuments + }; + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs b/Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs new file mode 100644 index 0000000..9d69226 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs @@ -0,0 +1,49 @@ +using System.Linq; +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Extensions; +using Cogworks.AzureCognitiveSearch.Interfaces.Searches; +using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; +using Cogworks.AzureCognitiveSearch.Mappers; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; + +namespace Cogworks.AzureCognitiveSearch.Searchers +{ + public class AzureSearch : IAzureSearch + where TAzureModel : class, IAzureModel, new() + { + private readonly IDocumentOperationWrapper _documentOperationWrapper; + + public AzureSearch(IDocumentOperationWrapper documentOperationWrapper) + => _documentOperationWrapper = documentOperationWrapper; + + public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) + { + var searchText = GetSearchText(keyword); + var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); + var results = _documentOperationWrapper.Search($"{searchText}", parameters); + + return SearchResultMapper.Map( + results, + azureSearchParameters.Skip, + azureSearchParameters.Take); + } + + public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) + { + var searchText = GetSearchText(keyword); + var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); + var results = await _documentOperationWrapper.SearchAsync(searchText, parameters); + + return SearchResultMapper.Map( + results, + azureSearchParameters.Skip, + azureSearchParameters.Take); + } + + private static string GetSearchText(string keyword) + => keyword.EscapeHyphen().HasValue() + ? keyword.EscapeHyphen() + : "*"; + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs index 48ea247..eca45e5 100644 --- a/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs +++ b/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs @@ -34,7 +34,7 @@ public DocumentOperationWrapper( public SearchResults Search(string searchText, SearchOptions parameters = null) => _searchClient.Search(searchText, parameters); - public async Task>> SearchAsync(string searchText, SearchOptions parameters = null) + public async Task> SearchAsync(string searchText, SearchOptions parameters = null) => await _searchClient.SearchAsync(searchText, parameters); public async Task> IndexAsync(IndexDocumentsBatch indexBatch) From 44d9fcf240e14d558630d3015116c5979e6cd32a Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Mon, 10 May 2021 12:47:28 +0200 Subject: [PATCH 05/31] refactor: refactor index initializer --- .../IndexInitializerException.cs | 17 ++++++ .../Initializers/AzureInitializer.cs | 53 +++++++++++++++++++ .../Initializers/IAzureInitializer.cs | 2 +- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexInitializerException.cs create mode 100644 Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexInitializerException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexInitializerException.cs new file mode 100644 index 0000000..2b44ae6 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexInitializerException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +{ + public class IndexInitializerException : DomainException + { + public override string Code => "index_initializer_exception"; + + public IndexInitializerException(string message) : base(message) + { + } + + public IndexInitializerException(string message, Exception innerException) : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs b/Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs new file mode 100644 index 0000000..6f8d72b --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs @@ -0,0 +1,53 @@ +using System; +using System.Threading.Tasks; +using Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions; +using Cogworks.AzureCognitiveSearch.Interfaces.Initializers; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; +using Cogworks.AzureCognitiveSearch.Options; + +namespace Cogworks.AzureCognitiveSearch.Initializers +{ + internal class AzureInitializer : IAzureInitializer + where TAzureModel : class, IAzureModel, new() + { + private readonly AzureSearchIndexOption _azureSearchIndexOption; + private readonly IAzureIndexOperation _azureIndexOperation; + + public AzureInitializer(AzureSearchIndexOption azureSearchIndexOption, IAzureIndexOperation azureIndexOperation) + { + _azureSearchIndexOption = azureSearchIndexOption; + _azureIndexOperation = azureIndexOperation; + } + + public async Task InitializeAsync() + { + if (_azureSearchIndexOption.Recreate) + { + await _azureIndexOperation.IndexDeleteAsync(); + } + + try + { + await _azureIndexOperation.IndexCreateOrUpdateAsync(); + } + catch (Exception) + { + if (_azureSearchIndexOption.RecreateOnUpdateFailure) + { + await _azureIndexOperation.IndexDeleteAsync(); + } + } + + try + { + await _azureIndexOperation.IndexCreateOrUpdateAsync(); + } + catch (Exception exception) + { + throw new IndexInitializerException(exception.Message, exception.InnerException); + } + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs index d8fbbb9..32a4bae 100644 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs @@ -6,6 +6,6 @@ namespace Cogworks.AzureCognitiveSearch.Interfaces.Initializers { public interface IAzureInitializer where TAzureModel : class, IAzureModel, new() { - Task InitializeAsync(); + Task InitializeAsync(); } } \ No newline at end of file From 18eb85ca37e5230f2184d3333eca2057e5c84c78 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Mon, 10 May 2021 12:52:01 +0200 Subject: [PATCH 06/31] refactor: extended repository --- .../Repositories/IAzureSearchRepository.cs | 4 +++- .../Interfaces/Searches/IAzureDocumentSearch.cs | 12 ------------ .../Repositories/AzureSearchRepository.cs | 13 ++++++++++++- 3 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs index 07e47a2..7a74471 100644 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs +++ b/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs @@ -1,11 +1,13 @@ using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Interfaces.Searches; using Cogworks.AzureCognitiveSearch.Models; namespace Cogworks.AzureCognitiveSearch.Interfaces.Repositories { public interface IAzureSearchRepository : IAzureDocumentOperation, - IAzureIndexOperation + IAzureIndexOperation, + IAzureSearch where TAzureModel : class, IAzureModel, new() { } diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs deleted file mode 100644 index a832190..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureDocumentSearch.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Models; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Searches -{ - public interface IAzureDocumentSearch where TAzureModel : class, IAzureModel, new() - { - Models.Dtos.SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters); - - Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs b/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs index 7cd995d..3d6e520 100644 --- a/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs +++ b/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Cogworks.AzureCognitiveSearch.Interfaces.Operations; using Cogworks.AzureCognitiveSearch.Interfaces.Repositories; +using Cogworks.AzureCognitiveSearch.Interfaces.Searches; using Cogworks.AzureCognitiveSearch.Models; using Cogworks.AzureCognitiveSearch.Models.Dtos; @@ -12,13 +13,16 @@ internal class AzureSearchRepository : IAzureSearchRepository _indexOperation; private readonly IAzureDocumentOperation _documentOperation; + private readonly IAzureSearch _search; public AzureSearchRepository( IAzureIndexOperation indexOperation, - IAzureDocumentOperation documentOperation) + IAzureDocumentOperation documentOperation, + IAzureSearch search) { _indexOperation = indexOperation; _documentOperation = documentOperation; + _search = search; } public async Task AddOrUpdateDocumentAsync(TAzureModel model) @@ -44,5 +48,12 @@ public async Task IndexCreateOrUpdateAsync() public async Task IndexClearAsync() => await _indexOperation.IndexClearAsync(); + + public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) + => _search.Search(keyword, azureSearchParameters); + + public async Task> SearchAsync(string keyword, + AzureSearchParameters azureSearchParameters) + => await _search.SearchAsync(keyword, azureSearchParameters); } } \ No newline at end of file From 3d3192642e34db43afe85d49ab5aa3ff3385a2ea Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Mon, 10 May 2021 13:00:44 +0200 Subject: [PATCH 07/31] refactor: added filters --- .../Filters/ArrayOperationsFilter.cs | 21 +++++ .../Filters/LiteralsOperationsFilter.cs | 21 +++++ .../Filters/LogicOperationsFilter.cs | 89 +++++++++++++++++++ .../Filters/RangeFilter.cs | 33 +++++++ 4 files changed, 164 insertions(+) create mode 100644 Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs create mode 100644 Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs create mode 100644 Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs create mode 100644 Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs diff --git a/Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs new file mode 100644 index 0000000..3a911a0 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs @@ -0,0 +1,21 @@ +using Cogworks.AzureCognitiveSearch.Extensions; + +namespace Cogworks.AzureCognitiveSearch.Filters +{ + public static class ArrayOperationsFilter + { + public static string SearchIn(this string query, string field, string searchedValue, string separator = Constants.StringConstants.Separators.Comma) + { + if (!field.HasValue()) + { + return query; + } + + var searchQuery = $"search.in({field}, '{searchedValue}', '{separator}')"; + + return query.HasValue() + ? $"{query} {searchQuery}" + : searchQuery; + } + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs new file mode 100644 index 0000000..91df616 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs @@ -0,0 +1,21 @@ +using Cogworks.AzureCognitiveSearch.Extensions; + +namespace Cogworks.AzureCognitiveSearch.Filters +{ + public static class LiteralsOperationsFilter + { + public static string Field(this string query, string field) + => query.HasValue() + ? $"{query} {field}" + : field; + + public static string Value(this string query, string value) + => $"{query} '{value}'"; + + public static string Property(this string query, string value) + => $"{query}/{value}"; + + public static string Append(this string query, string value) + => value.HasValue() ? $"{query} {value}" : query; + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs new file mode 100644 index 0000000..c064a14 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs @@ -0,0 +1,89 @@ +using Cogworks.AzureCognitiveSearch.Extensions; +using System.Collections.Generic; + +namespace Cogworks.AzureCognitiveSearch.Filters +{ + public static class LogicOperationsFilter + { + public static string And(this string query) + => query.HasValue() && !query.EndsWith(" and") + ? $"{query} and" + : query; + + public static string Or(this string query) + => query.HasValue() && !query.EndsWith(" or") ? $"{query} or" : query; + + public static string Not(this string query) + => query.HasValue() && !query.EndsWith(" not") ? $"{query} not" : query; + + public static string Equals(this string query) + => query.HasValue() && !query.EndsWith(" eq") ? $"{query} eq" : query; + + public static string EqualsValue(this string query, string value) + { + var equalsQuery = query.Equals(); + + return equalsQuery.HasValue() && equalsQuery.EndsWith(" eq") && value.HasValue() + ? equalsQuery.Value(value) + : query; + } + + public static string EqualsNull(this string query) + => query.HasValue() && !query.EndsWith($" {Constants.StringConstants.Terms.Null}") + ? $"{query.Equals()} {Constants.StringConstants.Terms.Null}" + : query; + + public static string NotEquals(this string query) + => query.HasValue() && !query.EndsWith(" ne") ? $"{query} ne" : query; + + public static string NotEqualsValue(this string query, string value) + { + var notEqualsQuery = query.NotEquals(); + + return notEqualsQuery.HasValue() && notEqualsQuery.EndsWith(" ne") && value.HasValue() + ? notEqualsQuery.Value(value) + : query; + } + + public static string NotEqualsNull(this string query) + => query.HasValue() && !query.EndsWith(" ne") + ? $"{query.NotEquals()} {Constants.StringConstants.Terms.Null}" + : query; + + public static string Any(this string query, string collectionName, string condition) + { + if (collectionName.HasValue() && condition.HasValue()) + { + return query.HasValue() + ? $"{query} {collectionName}/any({condition})" + : $"{collectionName}/any({condition})"; + } + + return query; + } + + public static string NormalizeQuery(this string query) + { + var normalizedQuery = query.Trim(); + + foreach (var logicalOperator in LogicalOperators()) + { + normalizedQuery = normalizedQuery + .TrimEnd(logicalOperator.ToCharArray()) + .TrimStart(logicalOperator.ToCharArray()); + } + + return normalizedQuery; + } + + private static IEnumerable LogicalOperators() + => new[] + { + "and", + "or", + "ne", + "eq", + "not" + }; + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs new file mode 100644 index 0000000..fbca364 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs @@ -0,0 +1,33 @@ +using Cogworks.AzureCognitiveSearch.Extensions; + +namespace Cogworks.AzureCognitiveSearch.Filters +{ + public static class RangeFilter + { + public static string GreaterThan(this string query, string field, string value) + => BuildRangeFilter(query, field, value, "gt"); + + public static string GreaterThanOrEqualTo(this string query, string field, string value) + => BuildRangeFilter(query, field, value, "ge"); + + public static string LessThan(this string query, string field, string value) + => BuildRangeFilter(query, field, value, "lt"); + + public static string LessThanOrEqualTo(this string query, string field, string value) + => BuildRangeFilter(query, field, value, "le"); + + private static string BuildRangeFilter(string query, string field, string value, string @operator) + { + if (!field.HasValue() || !value.HasValue()) + { + return query; + } + + var resultQuery = $"{field} {@operator} {value}"; + + return query.HasValue() + ? $"{query} {resultQuery}" + : resultQuery; + } + } +} \ No newline at end of file From 52cc00187d0e4d2e2c534d65e69ef64f91b2761f Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Mon, 10 May 2021 13:00:58 +0200 Subject: [PATCH 08/31] refactor: added azure index --- .../Indexes/AzureIndex.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs diff --git a/Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs b/Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs new file mode 100644 index 0000000..da20b00 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs @@ -0,0 +1,29 @@ +using Cogworks.AzureCognitiveSearch.Interfaces.Indexes; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Models.Dtos; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Cogworks.AzureCognitiveSearch.Indexes +{ + internal class AzureIndex : IAzureIndex where TAzureModel : class, IAzureModel, new() + { + private readonly IAzureDocumentOperation _documentOperation; + + public AzureIndex(IAzureDocumentOperation documentOperation) + => _documentOperation = documentOperation; + + public async Task AddOrUpdateDocumentAsync(TAzureModel model) + => await _documentOperation.AddOrUpdateDocumentAsync(model); + + public async Task TryRemoveDocumentAsync(TAzureModel model) + => await _documentOperation.TryRemoveDocumentAsync(model); + + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + => await _documentOperation.AddOrUpdateDocumentsAsync(models); + + public async Task TryRemoveDocumentsAsync(IEnumerable models) + => await _documentOperation.TryRemoveDocumentsAsync(models); + } +} \ No newline at end of file From a66fcf22c10a53208b4d5bda6df8bd148c7558c2 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Mon, 10 May 2021 14:42:36 +0200 Subject: [PATCH 09/31] refactor: added tests for core --- .../Cogworks.AzureCognitiveSearch.csproj | 9 + .../Options/AzureSearchClientOption.cs | 2 +- Cogworks.AzureSearch.sln | 9 +- ...orks.AzureCognitiveSearch.UnitTests.csproj | 51 +++ .../Models/TestDocumentModel.cs | 18 ++ .../Models/TestResponse.cs | 20 ++ .../Operations/DocumentOperationTests.cs | 210 +++++++++++++ .../Operations/IndexOperationTests.cs | 290 ++++++++++++++++++ .../TestBase.cs | 45 +++ 9 files changed, 652 insertions(+), 2 deletions(-) create mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj create mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs create mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestResponse.cs create mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs create mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs create mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs diff --git a/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj b/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj index 837c0a2..86baa95 100644 --- a/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj +++ b/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj @@ -5,6 +5,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -12,4 +16,9 @@ + + + + + diff --git a/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs b/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs index 738c2d5..3b814a4 100644 --- a/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs +++ b/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs @@ -25,7 +25,7 @@ public AzureSearchClientOption(string serviceName, string credentials, string se } - private SearchClientOptions GetOptions() + private static SearchClientOptions GetOptions() { var clientOptions = new SearchClientOptions(); diff --git a/Cogworks.AzureSearch.sln b/Cogworks.AzureSearch.sln index a88dc5e..90c5434 100644 --- a/Cogworks.AzureSearch.sln +++ b/Cogworks.AzureSearch.sln @@ -29,7 +29,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.Autofa EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.LightInject.UnitTests", "tests\UnitTests\Cogworks.AzureSearch.LightInject.UnitTests\Cogworks.AzureSearch.LightInject.UnitTests.csproj", "{90E65F2C-9592-473C-83BB-FC109A11C47D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cogworks.AzureCognitiveSearch", "Cogworks.AzureCognitiveSearch\Cogworks.AzureCognitiveSearch.csproj", "{A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureCognitiveSearch", "Cogworks.AzureCognitiveSearch\Cogworks.AzureCognitiveSearch.csproj", "{A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureCognitiveSearch.UnitTests", "tests\UnitTests\Cogworks.AzureCognitiveSearch.UnitTests\Cogworks.AzureCognitiveSearch.UnitTests.csproj", "{733886AB-26AF-4169-BA23-87B25D11EE56}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -81,6 +83,10 @@ Global {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Debug|Any CPU.Build.0 = Debug|Any CPU {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Release|Any CPU.ActiveCfg = Release|Any CPU {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Release|Any CPU.Build.0 = Release|Any CPU + {733886AB-26AF-4169-BA23-87B25D11EE56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {733886AB-26AF-4169-BA23-87B25D11EE56}.Debug|Any CPU.Build.0 = Debug|Any CPU + {733886AB-26AF-4169-BA23-87B25D11EE56}.Release|Any CPU.ActiveCfg = Release|Any CPU + {733886AB-26AF-4169-BA23-87B25D11EE56}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -98,6 +104,7 @@ Global {0648AF35-71D5-4BA4-A1BF-0476AAC71BEE} = {180E9BD6-30B9-4D88-B88C-9F289D316967} {90E65F2C-9592-473C-83BB-FC109A11C47D} = {180E9BD6-30B9-4D88-B88C-9F289D316967} {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} + {733886AB-26AF-4169-BA23-87B25D11EE56} = {180E9BD6-30B9-4D88-B88C-9F289D316967} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DC813CF7-BD65-4CD5-B0B7-7B1F828A9909} diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj new file mode 100644 index 0000000..fd9584e --- /dev/null +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj @@ -0,0 +1,51 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs new file mode 100644 index 0000000..9c7ff0d --- /dev/null +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; +using Cogworks.AzureCognitiveSearch.Models; + +namespace Cogworks.AzureCognitiveSearch.UnitTests.Models +{ + public class TestDocumentModel : IAzureModel + { + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] + public string Id { get; set; } + + [SimpleField(IsFilterable = true)] + [SearchableField()] + + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestResponse.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestResponse.cs new file mode 100644 index 0000000..5f4302c --- /dev/null +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestResponse.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Azure; +using Azure.Search.Documents.Models; + +namespace Cogworks.AzureCognitiveSearch.UnitTests.Models +{ + + public class TestResponse : Response + { + + public TestResponse(T value) + { + Value = value; + } + + public override T Value { get; } + + public override Response GetRawResponse() => null; + } +} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs new file mode 100644 index 0000000..0756e74 --- /dev/null +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs @@ -0,0 +1,210 @@ +using System.Linq; +using System.Threading.Tasks; +using AutoFixture; +using Azure; +using Azure.Search.Documents.Models; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Repositories; +using Cogworks.AzureCognitiveSearch.UnitTests.Models; +using NSubstitute; +using Xunit; + +namespace Cogworks.AzureCognitiveSearch.UnitTests.Operations +{ + public class DocumentOperationTests : TestBase + { + private readonly IAzureDocumentOperation _azureDocumentOperation; + + public DocumentOperationTests() + => _azureDocumentOperation = new AzureSearchRepository( + AzureIndexOperationService, + AzureDocumentOperationService, + Search); + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_AddOrUpdateDocuments(int documentsCount) + { + // Arrange + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + + var indexResults = testDocuments + .Select(testDocument => SearchModelFactory.IndexingResult( + key: testDocument.Id, + errorMessage: string.Empty, + succeeded: true, + status: 200)) + .ToList(); + + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); + + // Act + var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); + + // Assert + Assert.NotNull(result); + Assert.True(result.Succeeded); + Assert.NotEmpty(result.SucceededDocuments); + Assert.Empty(result.FailedDocuments); + Assert.All( + result.SucceededDocuments, + succeedItem => + { + Assert.True(succeedItem.Succeeded); + Assert.Equal(200, succeedItem.StatusCode); + Assert.Equal("Successfully adding or updating document.", succeedItem.Message); + Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); + }); + } + + [Fact] + public async Task Should_Succeeded_When_TryToAddEmptyDocuments() + { + // Arrange + var testDocuments = Enumerable.Empty(); + + var documentIndexResult = new TestResponse( + SearchModelFactory.IndexDocumentsResult( + Enumerable.Empty())); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(documentIndexResult); + + // Act + var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); + + // Assert + Assert.NotNull(result); + Assert.True(result.Succeeded); + Assert.Empty(result.SucceededDocuments); + Assert.Empty(result.FailedDocuments); + Assert.Equal("No documents found to index.", result.Message); + } + + [Fact] + public async Task Should_Succeeded_When_TryToRemoveEmptyDocuments() + { + // Arrange + var testDocuments = Enumerable.Empty(); + + var documentIndexResult = new TestResponse( + SearchModelFactory.IndexDocumentsResult( + Enumerable.Empty())); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(documentIndexResult); + + // Act + var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); + + // Assert + Assert.NotNull(result); + Assert.True(result.Succeeded); + Assert.Empty(result.SucceededDocuments); + Assert.Empty(result.FailedDocuments); + Assert.Equal("No documents found to delete.", result.Message); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Succeeded_When_TryRemoveDocuments(int documentsCount) + { + // Arrange + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + var indexResults = testDocuments + .Select(testDocument => SearchModelFactory.IndexingResult( + key: testDocument.Id, + errorMessage: string.Empty, + succeeded: true, + status: 200)) + .ToList(); + + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); + + // Act + var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); + + // Assert + Assert.NotNull(result); + Assert.True(result.Succeeded); + Assert.NotEmpty(result.SucceededDocuments); + Assert.Empty(result.FailedDocuments); + Assert.All( + result.SucceededDocuments, + succeedItem => + { + Assert.True(succeedItem.Succeeded); + Assert.Equal(200, succeedItem.StatusCode); + Assert.Equal("Successfully removing document.", succeedItem.Message); + Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); + }); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Fail_When_TryRemoveNotExistingDocuments(int documentsCount) + { + // Arrange + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + var indexResults = testDocuments + .Select(testDocument => SearchModelFactory.IndexingResult( + key: testDocument.Id, + errorMessage: string.Empty, + succeeded: false, + status: 404)) + .ToList(); + + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); + + // Act + var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); + + // Assert + Assert.NotNull(result); + Assert.False(result.Succeeded); + Assert.Empty(result.SucceededDocuments); + Assert.NotEmpty(result.FailedDocuments); + Assert.All( + result.FailedDocuments, + failedItem => + { + Assert.False(failedItem.Succeeded); + Assert.Equal(404, failedItem.StatusCode); + Assert.Equal("Failed removing document.", failedItem.Message); + Assert.Contains(testDocuments, item => item.Id == failedItem.ModelId); + }); + } + } +} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs new file mode 100644 index 0000000..a0cb975 --- /dev/null +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs @@ -0,0 +1,290 @@ +// using System.Threading.Tasks; +// using AutoFixture; +// using Cogworks.AzureCognitiveSearch.UnitTests.Models; +// using NSubstitute; +// using Xunit; +// +// namespace Cogworks.AzureCognitiveSearch.UnitTests.Operations +// { +// public class IndexOperationTests : TestBase +// { +// private readonly IAzureIndexOperation _azureIndexOperation; +// +// public IndexOperationTests() +// => _azureIndexOperation = new AzureSearchRepository( +// TestDocumentModelDefinition, +// IndexOperationWrapper, +// DocumentOperationWrapper); +// +// #region Exists Tests +// +// [Fact] +// public async Task Should_ReturnTrue_When_IndexExists() +// { +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Returns(true); +// +// // Act +// var result = await _azureIndexOperation.IndexExistsAsync(); +// +// // Assert +// Assert.True(result); +// } +// +// [Fact] +// public async Task Should_ReturnFalse_When_IndexNotExists() +// { +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Returns(false); +// +// // Act +// var result = await _azureIndexOperation.IndexExistsAsync(); +// +// // Assert +// Assert.False(result); +// } +// +// [Fact] +// public async Task Should_ThrowException_When_IssuesWithConnection() +// { +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Throws(_ => new CloudException(AzureWrapperException)); +// +// // Assert +// _ = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexExistsAsync()); +// } +// +// [Fact] +// public async Task Should_Not_ThrowException_When_NoIssueWithConnection() +// { +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Returns(true); +// +// // Act +// var indexNotExistsResult = await Record.ExceptionAsync(Should_ReturnFalse_When_IndexNotExists); +// var indexExistsResult = await Record.ExceptionAsync(Should_ReturnTrue_When_IndexExists); +// +// // Assert +// Assert.Null(indexNotExistsResult); +// Assert.Null(indexExistsResult); +// } +// +// #endregion Exists Tests +// +// #region Delete Tests +// +// [Fact] +// public async Task Should_DeleteIndex_When_IndexExists() +// { +// // Act +// var deleteResult = await _azureIndexOperation.IndexDeleteAsync(); +// +// // Assert +// Assert.NotNull(deleteResult); +// Assert.True(deleteResult.Succeeded); +// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully deleted.", deleteResult.Message); +// } +// +// [Fact] +// public async Task Should_Not_DeleteIndex_When_IndexNotExists() +// { +// // Arrange +// _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) +// .Throws(_ => new CloudException(AzureWrapperException)); +// +// // Act +// var deleteResult = await _azureIndexOperation.IndexDeleteAsync(); +// +// // Assert +// Assert.NotNull(deleteResult); +// Assert.False(deleteResult.Succeeded); +// Assert.Equal($"An issue occurred on deleting index: {TestDocumentModelDefinition.IndexName}. More information: {AzureWrapperException}", deleteResult.Message); +// } +// +// [Fact] +// public async Task Should_Not_ThrowException_When_DeletingExistingIndex() +// { +// // Act +// var indexDeletingResult = await Record.ExceptionAsync(Should_DeleteIndex_When_IndexExists); +// +// // Assert +// Assert.Null(indexDeletingResult); +// } +// +// [Fact] +// public async Task Should_Not_ThrowException_When_DeletingNotExistingIndex() +// { +// // Act +// var indexDeletingResult = await Record.ExceptionAsync(Should_Not_DeleteIndex_When_IndexNotExists); +// +// // Assert +// Assert.Null(indexDeletingResult); +// } +// +// #endregion Delete Tests +// +// #region Index Create or Update Tests +// +// [Fact] +// public async Task Should_CreateOrUpdateIndex() +// { +// // Arrange +// var createdOrUpdatedIndex = new Index +// { +// Name = TestDocumentModelDefinition.IndexName +// }; +// +// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) +// .Returns(createdOrUpdatedIndex); +// +// // Act +// var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); +// +// // Assert +// Assert.NotNull(operationResult); +// Assert.True(operationResult.Succeeded); +// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully created or updated.", operationResult.Message); +// } +// +// [Fact] +// public async Task Should_CreateOrUpdateCustomIndex() +// { +// // Arrange +// var createdOrUpdatedIndex = new Index +// { +// Name = TestDocumentModelDefinition.IndexName +// }; +// +// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) +// .Returns(createdOrUpdatedIndex); +// +// // Act +// var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); +// +// // Assert +// Assert.NotNull(operationResult); +// Assert.True(operationResult.Succeeded); +// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully created or updated.", operationResult.Message); +// } +// +// [Fact] +// public async Task Should_Not_ThrowException_When_IssueOnCreatingOrUpdatingIndex() +// { +// // Arrange +// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) +// .Throws(_ => new CloudException(AzureWrapperException)); +// +// // Act +// var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); +// +// // Assert +// Assert.NotNull(operationResult); +// Assert.False(operationResult.Succeeded); +// Assert.Equal($"An issue occurred on creating or updating index: {TestDocumentModelDefinition.IndexName}. More information: {AzureWrapperException}", operationResult.Message); +// } +// +// [Fact] +// public async Task Should_Not_ThrowException_When_IssueOnCreatingOrUpdatingCustomIndex() +// { +// // Arrange +// var index = new Index +// { +// Name = Fixture.Create() +// }; +// +// var customModelDefinition = new AzureIndexDefinition(index); +// +// var azureIndexOperation = new AzureSearchRepository( +// customModelDefinition, +// IndexOperationWrapper, +// DocumentOperationWrapper); +// +// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) +// .Throws(_ => new CloudException(AzureWrapperException)); +// +// // Act +// var operationResult = await azureIndexOperation.IndexCreateOrUpdateAsync(); +// +// // Assert +// Assert.NotNull(operationResult); +// Assert.False(operationResult.Succeeded); +// Assert.Equal($"An issue occurred on creating or updating index: {customModelDefinition.IndexName}. More information: {AzureWrapperException}", operationResult.Message); +// } +// +// #endregion Index Create or Update Tests +// +// #region Index Clear Tests +// +// [Fact] +// public async Task Should_ClearIndex_When_IndexExists() +// { +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Returns(true); +// +// // Act +// var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); +// +// // Assert +// Assert.NotNull(indexOperationResult); +// Assert.True(indexOperationResult.Succeeded); +// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully cleared.", indexOperationResult.Message); +// } +// +// [Fact] +// public async Task Should_ClearIndex_When_IndexNotExists() +// { +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Returns(false); +// +// // Act +// var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); +// +// // Assert +// Assert.NotNull(indexOperationResult); +// Assert.True(indexOperationResult.Succeeded); +// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully cleared.", indexOperationResult.Message); +// } +// +// [Fact] +// public async Task Should_Not_ThrowException_When_IssueWithConnectionOnClearingIndex() +// { +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Returns(true); +// +// _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) +// .Throws(_ => new CloudException(AzureWrapperException)); +// +// // Act +// var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); +// +// // Assert +// Assert.NotNull(indexOperationResult); +// Assert.False(indexOperationResult.Succeeded); +// Assert.Equal($"An issue occurred on clearing index: {TestDocumentModelDefinition.IndexName}. Could not delete existing index.", indexOperationResult.Message); +// +// // Arrange +// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) +// .Throws(_ => new CloudException(AzureWrapperException)); +// +// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) +// .Throws(_ => new CloudException(AzureWrapperException)); +// +// // Act +// indexOperationResult = await _azureIndexOperation.IndexClearAsync(); +// +// // Assert +// Assert.NotNull(indexOperationResult); +// Assert.False(indexOperationResult.Succeeded); +// Assert.Equal($"An issue occurred on clearing index: {TestDocumentModelDefinition.IndexName}. Could not create index.", indexOperationResult.Message); +// } +// +// #endregion Index Clear Tests +// } +// } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs new file mode 100644 index 0000000..b9669e7 --- /dev/null +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs @@ -0,0 +1,45 @@ +using AutoFixture; +using AutoFixture.AutoNSubstitute; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Interfaces.Searches; +using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Services; +using Cogworks.AzureCognitiveSearch.UnitTests.Models; +using NSubstitute; + +namespace Cogworks.AzureCognitiveSearch.UnitTests +{ + public abstract class TestBase + { + protected const string AzureWrapperException = "some internal exception"; + + protected readonly IFixture Fixture = new Fixture() + .Customize(new AutoNSubstituteCustomization()); + + protected readonly IIndexOperationWrapper IndexOperationWrapper; + protected readonly IDocumentOperationWrapper DocumentOperationWrapper; + protected readonly AzureIndexDefinition TestDocumentModelDefinition; + protected readonly IAzureSearch Search; + + protected readonly IAzureDocumentOperation AzureDocumentOperationService; + protected readonly IAzureIndexOperation AzureIndexOperationService; + + protected TestBase() + { + TestDocumentModelDefinition = Fixture.Create>(); + + IndexOperationWrapper = Substitute.For(); + DocumentOperationWrapper = Substitute.For>(); + + Search = Substitute.For>(); + + AzureDocumentOperationService = new AzureDocumentOperationService( + DocumentOperationWrapper); + + AzureIndexOperationService = new AzureIndexOperationService( + TestDocumentModelDefinition, + IndexOperationWrapper); + } + } +} \ No newline at end of file From ef0882c952bea25b0ab4061f977ce5702ea62537 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Tue, 11 May 2021 12:45:20 +0200 Subject: [PATCH 10/31] feat: added more test for document operation tests --- .../Operations/DocumentOperationTests.cs | 159 +++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs index 0756e74..3cf67fa 100644 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs @@ -1,12 +1,14 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading.Tasks; using AutoFixture; -using Azure; using Azure.Search.Documents.Models; +using Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions; using Cogworks.AzureCognitiveSearch.Interfaces.Operations; using Cogworks.AzureCognitiveSearch.Repositories; using Cogworks.AzureCognitiveSearch.UnitTests.Models; using NSubstitute; +using NSubstitute.ExceptionExtensions; using Xunit; namespace Cogworks.AzureCognitiveSearch.UnitTests.Operations @@ -67,6 +69,71 @@ public async Task Should_AddOrUpdateDocuments(int documentsCount) }); } + [Theory] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Fail_When_AddOrUpdateDocumentsPartiallyFail(int documentsCount) + { + // Arrange + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + + var indexResults = testDocuments + .Select((document, index) => new + { + Document = document, + Succeded = index % (documentsCount / 2) == 0 + }) + .Select(item => SearchModelFactory.IndexingResult( + key: item.Document.Id, + errorMessage: !item.Succeded + ? "Internal Unit Error." + : string.Empty, + succeeded: item.Succeded, + status: item.Succeded + ? 200 + : 404)) + .ToList(); + + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); + + // Act + var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); + + // Assert + Assert.NotNull(result); + Assert.False(result.Succeeded); + Assert.NotEmpty(result.SucceededDocuments); + Assert.NotEmpty(result.FailedDocuments); + Assert.All( + result.SucceededDocuments, + succeedItem => + { + Assert.True(succeedItem.Succeeded); + Assert.Equal(200, succeedItem.StatusCode); + Assert.Equal("Successfully adding or updating document.", succeedItem.Message); + Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); + }); + + Assert.All( + result.FailedDocuments, + succeedItem => + { + Assert.False(succeedItem.Succeeded); + Assert.Equal(404, succeedItem.StatusCode); + Assert.Equal("Failed adding or updating document.", succeedItem.Message); + Assert.Equal("Internal Unit Error.", succeedItem.InnerMessage); + Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); + }); + } + [Fact] public async Task Should_Succeeded_When_TryToAddEmptyDocuments() { @@ -206,5 +273,93 @@ public async Task Should_Fail_When_TryRemoveNotExistingDocuments(int documentsCo Assert.Contains(testDocuments, item => item.Id == failedItem.ModelId); }); } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_ThrowDomainException_When_IssueWith_TryAddOrUpdateDocuments(int documentsCount) + { + // Arrange + + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Throws(_ => new AddOrUpdateDocumentException("Test Error", Fixture.Create())); + + // Assert + var domainException = await Assert.ThrowsAsync(async () => + await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments)); + + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Not_ThrowDomainException_When_No_IssueWith_TryAddOrUpdateDocuments(int documentsCount) + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + // Act + var domainExceptionResult = await Record.ExceptionAsync(() => Should_AddOrUpdateDocuments(documentsCount)); + + // Assert + Assert.Null(domainExceptionResult); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_ThrowDomainException_When_IssueWith_TryRemoveDocuments(int documentsCount) + { + // Arrange + + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Throws(_ => new AddOrUpdateDocumentException("Test Error", Fixture.Create())); + + // Assert + var domainException = await Assert.ThrowsAsync(async () => + await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments)); + + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Not_ThrowDomainException_When_No_IssueWith_TryRemoveDocuments(int documentsCount) + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + // Act + var domainExceptionResult = await Record.ExceptionAsync(() => Should_Succeeded_When_TryRemoveDocuments(documentsCount)); + + // Assert + Assert.Null(domainExceptionResult); + } } } \ No newline at end of file From 404d9137c87dc5331aa32d4bf99513ce2427cc78 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Tue, 11 May 2021 14:22:04 +0200 Subject: [PATCH 11/31] feat: update index operation tests --- .../IndexExceptions/IndexExistsException.cs | 18 + .../Services/AzureIndexOperationService.cs | 11 +- .../Operations/IndexOperationTests.cs | 592 +++++++++--------- 3 files changed, 330 insertions(+), 291 deletions(-) create mode 100644 Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexExistsException.cs diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexExistsException.cs b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexExistsException.cs new file mode 100644 index 0000000..8faf434 --- /dev/null +++ b/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexExistsException.cs @@ -0,0 +1,18 @@ +using System; + +namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +{ + public class IndexExistsException : DomainException + { + public override string Code => "index_exists_exception"; + + public IndexExistsException(string message) : base(message) + { + } + + public IndexExistsException(string message, Exception innerException) : base(message, innerException) + { + } + + } +} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs b/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs index 86e9669..087d05f 100644 --- a/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs +++ b/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs @@ -24,7 +24,16 @@ public AzureIndexOperationService( } public async Task IndexExistsAsync() - => await _indexOperationWrapper.ExistsAsync(_azureIndexDefinition.IndexName); + { + try + { + return await _indexOperationWrapper.ExistsAsync(_azureIndexDefinition.IndexName); + } + catch (Exception exception) + { + throw new IndexExistsException(exception.Message, exception.InnerException); + } + } public async Task IndexDeleteAsync() { diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs index a0cb975..165cf08 100644 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs @@ -1,290 +1,302 @@ -// using System.Threading.Tasks; -// using AutoFixture; -// using Cogworks.AzureCognitiveSearch.UnitTests.Models; -// using NSubstitute; -// using Xunit; -// -// namespace Cogworks.AzureCognitiveSearch.UnitTests.Operations -// { -// public class IndexOperationTests : TestBase -// { -// private readonly IAzureIndexOperation _azureIndexOperation; -// -// public IndexOperationTests() -// => _azureIndexOperation = new AzureSearchRepository( -// TestDocumentModelDefinition, -// IndexOperationWrapper, -// DocumentOperationWrapper); -// -// #region Exists Tests -// -// [Fact] -// public async Task Should_ReturnTrue_When_IndexExists() -// { -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Returns(true); -// -// // Act -// var result = await _azureIndexOperation.IndexExistsAsync(); -// -// // Assert -// Assert.True(result); -// } -// -// [Fact] -// public async Task Should_ReturnFalse_When_IndexNotExists() -// { -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Returns(false); -// -// // Act -// var result = await _azureIndexOperation.IndexExistsAsync(); -// -// // Assert -// Assert.False(result); -// } -// -// [Fact] -// public async Task Should_ThrowException_When_IssuesWithConnection() -// { -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Throws(_ => new CloudException(AzureWrapperException)); -// -// // Assert -// _ = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexExistsAsync()); -// } -// -// [Fact] -// public async Task Should_Not_ThrowException_When_NoIssueWithConnection() -// { -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Returns(true); -// -// // Act -// var indexNotExistsResult = await Record.ExceptionAsync(Should_ReturnFalse_When_IndexNotExists); -// var indexExistsResult = await Record.ExceptionAsync(Should_ReturnTrue_When_IndexExists); -// -// // Assert -// Assert.Null(indexNotExistsResult); -// Assert.Null(indexExistsResult); -// } -// -// #endregion Exists Tests -// -// #region Delete Tests -// -// [Fact] -// public async Task Should_DeleteIndex_When_IndexExists() -// { -// // Act -// var deleteResult = await _azureIndexOperation.IndexDeleteAsync(); -// -// // Assert -// Assert.NotNull(deleteResult); -// Assert.True(deleteResult.Succeeded); -// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully deleted.", deleteResult.Message); -// } -// -// [Fact] -// public async Task Should_Not_DeleteIndex_When_IndexNotExists() -// { -// // Arrange -// _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) -// .Throws(_ => new CloudException(AzureWrapperException)); -// -// // Act -// var deleteResult = await _azureIndexOperation.IndexDeleteAsync(); -// -// // Assert -// Assert.NotNull(deleteResult); -// Assert.False(deleteResult.Succeeded); -// Assert.Equal($"An issue occurred on deleting index: {TestDocumentModelDefinition.IndexName}. More information: {AzureWrapperException}", deleteResult.Message); -// } -// -// [Fact] -// public async Task Should_Not_ThrowException_When_DeletingExistingIndex() -// { -// // Act -// var indexDeletingResult = await Record.ExceptionAsync(Should_DeleteIndex_When_IndexExists); -// -// // Assert -// Assert.Null(indexDeletingResult); -// } -// -// [Fact] -// public async Task Should_Not_ThrowException_When_DeletingNotExistingIndex() -// { -// // Act -// var indexDeletingResult = await Record.ExceptionAsync(Should_Not_DeleteIndex_When_IndexNotExists); -// -// // Assert -// Assert.Null(indexDeletingResult); -// } -// -// #endregion Delete Tests -// -// #region Index Create or Update Tests -// -// [Fact] -// public async Task Should_CreateOrUpdateIndex() -// { -// // Arrange -// var createdOrUpdatedIndex = new Index -// { -// Name = TestDocumentModelDefinition.IndexName -// }; -// -// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) -// .Returns(createdOrUpdatedIndex); -// -// // Act -// var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); -// -// // Assert -// Assert.NotNull(operationResult); -// Assert.True(operationResult.Succeeded); -// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully created or updated.", operationResult.Message); -// } -// -// [Fact] -// public async Task Should_CreateOrUpdateCustomIndex() -// { -// // Arrange -// var createdOrUpdatedIndex = new Index -// { -// Name = TestDocumentModelDefinition.IndexName -// }; -// -// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) -// .Returns(createdOrUpdatedIndex); -// -// // Act -// var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); -// -// // Assert -// Assert.NotNull(operationResult); -// Assert.True(operationResult.Succeeded); -// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully created or updated.", operationResult.Message); -// } -// -// [Fact] -// public async Task Should_Not_ThrowException_When_IssueOnCreatingOrUpdatingIndex() -// { -// // Arrange -// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) -// .Throws(_ => new CloudException(AzureWrapperException)); -// -// // Act -// var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); -// -// // Assert -// Assert.NotNull(operationResult); -// Assert.False(operationResult.Succeeded); -// Assert.Equal($"An issue occurred on creating or updating index: {TestDocumentModelDefinition.IndexName}. More information: {AzureWrapperException}", operationResult.Message); -// } -// -// [Fact] -// public async Task Should_Not_ThrowException_When_IssueOnCreatingOrUpdatingCustomIndex() -// { -// // Arrange -// var index = new Index -// { -// Name = Fixture.Create() -// }; -// -// var customModelDefinition = new AzureIndexDefinition(index); -// -// var azureIndexOperation = new AzureSearchRepository( -// customModelDefinition, -// IndexOperationWrapper, -// DocumentOperationWrapper); -// -// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) -// .Throws(_ => new CloudException(AzureWrapperException)); -// -// // Act -// var operationResult = await azureIndexOperation.IndexCreateOrUpdateAsync(); -// -// // Assert -// Assert.NotNull(operationResult); -// Assert.False(operationResult.Succeeded); -// Assert.Equal($"An issue occurred on creating or updating index: {customModelDefinition.IndexName}. More information: {AzureWrapperException}", operationResult.Message); -// } -// -// #endregion Index Create or Update Tests -// -// #region Index Clear Tests -// -// [Fact] -// public async Task Should_ClearIndex_When_IndexExists() -// { -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Returns(true); -// -// // Act -// var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); -// -// // Assert -// Assert.NotNull(indexOperationResult); -// Assert.True(indexOperationResult.Succeeded); -// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully cleared.", indexOperationResult.Message); -// } -// -// [Fact] -// public async Task Should_ClearIndex_When_IndexNotExists() -// { -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Returns(false); -// -// // Act -// var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); -// -// // Assert -// Assert.NotNull(indexOperationResult); -// Assert.True(indexOperationResult.Succeeded); -// Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully cleared.", indexOperationResult.Message); -// } -// -// [Fact] -// public async Task Should_Not_ThrowException_When_IssueWithConnectionOnClearingIndex() -// { -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Returns(true); -// -// _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) -// .Throws(_ => new CloudException(AzureWrapperException)); -// -// // Act -// var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); -// -// // Assert -// Assert.NotNull(indexOperationResult); -// Assert.False(indexOperationResult.Succeeded); -// Assert.Equal($"An issue occurred on clearing index: {TestDocumentModelDefinition.IndexName}. Could not delete existing index.", indexOperationResult.Message); -// -// // Arrange -// _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) -// .Throws(_ => new CloudException(AzureWrapperException)); -// -// _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) -// .Throws(_ => new CloudException(AzureWrapperException)); -// -// // Act -// indexOperationResult = await _azureIndexOperation.IndexClearAsync(); -// -// // Assert -// Assert.NotNull(indexOperationResult); -// Assert.False(indexOperationResult.Succeeded); -// Assert.Equal($"An issue occurred on clearing index: {TestDocumentModelDefinition.IndexName}. Could not create index.", indexOperationResult.Message); -// } -// -// #endregion Index Clear Tests -// } -// } \ No newline at end of file +using System; +using System.Threading.Tasks; +using AutoFixture; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions; +using Cogworks.AzureCognitiveSearch.Interfaces.Operations; +using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureCognitiveSearch.Repositories; +using Cogworks.AzureCognitiveSearch.Services; +using Cogworks.AzureCognitiveSearch.UnitTests.Models; +using NSubstitute; +using NSubstitute.ExceptionExtensions; +using Xunit; + +namespace Cogworks.AzureCognitiveSearch.UnitTests.Operations +{ + public class IndexOperationTests : TestBase + { + private readonly IAzureIndexOperation _azureIndexOperation; + + public IndexOperationTests() + => _azureIndexOperation = new AzureSearchRepository( + AzureIndexOperationService, + AzureDocumentOperationService, + Search); + + #region Exists Tests + + [Fact] + public async Task Should_ReturnTrue_When_IndexExists() + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + // Act + var result = await _azureIndexOperation.IndexExistsAsync(); + + // Assert + Assert.True(result); + } + + [Fact] + public async Task Should_ReturnFalse_When_IndexNotExists() + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(false); + + // Act + var result = await _azureIndexOperation.IndexExistsAsync(); + + // Assert + Assert.False(result); + } + + [Fact] + public async Task Should_ThrowException_When_IssuesWithConnection() + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Throws(_ => new IndexExistsException( + "Test Error", + Fixture.Create())); + + // Assert + var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexExistsAsync()); + + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + [Fact] + public async Task Should_Not_ThrowException_When_NoIssueWithConnection() + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + // Act + var indexNotExistsResult = await Record.ExceptionAsync(Should_ReturnFalse_When_IndexNotExists); + var indexExistsResult = await Record.ExceptionAsync(Should_ReturnTrue_When_IndexExists); + + // Assert + Assert.Null(indexNotExistsResult); + Assert.Null(indexExistsResult); + } + + #endregion Exists Tests + + #region Delete Tests + + [Fact] + public async Task Should_DeleteIndex_When_IndexExists() + { + // Act + + var deleteResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); + + // Assert + Assert.Null(deleteResult); + } + + [Fact] + public async Task Should_Not_ThrowException_When_DeletingExistingIndex() + { + // Act + var indexDeletingResult = await Record.ExceptionAsync(Should_DeleteIndex_When_IndexExists); + + // Assert + Assert.Null(indexDeletingResult); + } + + [Fact] + public async Task Should_ThrowException_When_IssuesWithConnection_On_DeletingIndex() + { + // Arrange + _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) + .Throws(_ => new IndexDeleteException( + "Test Error", + Fixture.Create())); + + // Act + var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); + + // Assert + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + #endregion Delete Tests + + #region Index Create or Update Tests + + [Fact] + public async Task Should_CreateOrUpdateIndex() + { + // Arrange + var createdOrUpdatedIndex = new SearchIndex(TestDocumentModelDefinition.IndexName); + + _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) + .Returns(createdOrUpdatedIndex); + + // Act + var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); + + // Assert + Assert.Null(indexResult); + + } + + [Fact] + public async Task Should_CreateOrUpdateCustomIndex() + { + // Arrange + var index = new SearchIndex(Fixture.Create()); + + var customModelDefinition = new AzureIndexDefinition(index); + + var customIndexOperationService = new AzureIndexOperationService( + customModelDefinition, + IndexOperationWrapper); + + var azureIndexOperation = new AzureSearchRepository( + customIndexOperationService, + AzureDocumentOperationService, + Search); + + // Act + var indexResult = await Record.ExceptionAsync(async () => await azureIndexOperation.IndexCreateOrUpdateAsync()); + + // Assert + Assert.Null(indexResult); + } + + [Fact] + public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingIndex() + { + // Arrange + _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) + .Throws(_ => new IndexCreateOrUpdateException( + "Test Error", + Fixture.Create())); + + // Act + var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); + + // Assert + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + [Fact] + public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomIndex() + { + // Arrange + var index = new SearchIndex(Fixture.Create()); + + var customModelDefinition = new AzureIndexDefinition(index); + + var customIndexOperationService = new AzureIndexOperationService( + customModelDefinition, + IndexOperationWrapper); + + var azureIndexOperation = new AzureSearchRepository( + customIndexOperationService, + AzureDocumentOperationService, + Search); + + _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) + .Throws(_ => new IndexCreateOrUpdateException( + "Test Error", + Fixture.Create())); + + // Act + var domainException = await Assert.ThrowsAsync(async () => await azureIndexOperation.IndexCreateOrUpdateAsync()); + + // Assert + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + #endregion Index Create or Update Tests + + #region Index Clear Tests + + [Fact] + public async Task Should_ClearIndex_When_IndexExists() + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + // Act + var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + + // Assert + Assert.Null(indexResult); + } + + [Fact] + public async Task Should_ClearIndex_When_IndexNotExists() + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(false); + + // Act + var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + + // Assert + Assert.Null(indexResult); + } + + [Fact] + public async Task Should_ThrowException_When_IssueWithConnectionOnClearingIndex() + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) + .Throws(_ => new IndexClearException( + "Test Error", + Fixture.Create())); + + // Act + var domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + + // Assert + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + + + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Throws(_ => new IndexExistsException( + "Test Error", + Fixture.Create())); + + _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) + .Throws(_ => new IndexCreateOrUpdateException( + "Test Error", + Fixture.Create())); + + // Act + domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + + // Assert + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + #endregion Index Clear Tests + } +} \ No newline at end of file From 25bc1cbeadc0577c2bfc01a406f603f0e8b47922 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 11:49:17 +0200 Subject: [PATCH 12/31] feat: updating projects --- .../Builder/IAzureSearchBuilder.cs | 29 -- .../Cogworks.AzureCognitiveSearch.csproj | 24 -- .../Constants/StringConstants/Separators.cs | 9 - .../Constants/StringConstants/Terms.cs | 7 - .../Enums/AzureQueryType.cs | 8 - .../Enums/AzureSearchModeType.cs | 8 - .../Extensions/EnumerableExtensions.cs | 18 - .../Extensions/StringExtensions.cs | 20 - .../Filters/ArrayOperationsFilter.cs | 21 - .../Filters/LiteralsOperationsFilter.cs | 21 - .../Filters/LogicOperationsFilter.cs | 89 ----- .../Filters/RangeFilter.cs | 33 -- .../Indexes/AzureIndex.cs | 29 -- .../Initializers/AzureInitializer.cs | 53 --- .../Interfaces/Indexes/IAzureIndex.cs | 19 - .../Initializers/IAzureInitializer.cs | 11 - .../Operations/IAzureDocumentOperation.cs | 18 - .../Operations/IAzureIndexOperation.cs | 17 - .../Repositories/IAzureSearchRepository.cs | 14 - .../Interfaces/Searches/IAzureSearch.cs | 13 - .../Wrappers/IDocumentOperationWrapper.cs | 17 - .../Wrappers/IIndexOperationWrapper.cs | 17 - .../Models/AzureIndexDefinition.cs | 17 - .../Models/AzureSearchParameters.cs | 38 -- .../AzureBatchDocumentsOperationResult.cs | 16 - .../Dtos/AzureDocumentOperationResult.cs | 15 - .../Models/Dtos/AzureIndexOperationResult.cs | 9 - .../Models/Dtos/SearchResult.cs | 13 - .../Models/Dtos/SearchResultItem.cs | 20 - .../Models/IAzureModel.cs | 6 - .../Models/IAzureModelIdentity.cs | 7 - .../Options/AzureSearchClientOption.cs | 48 --- .../Options/AzureSearchIndexOption.cs | 15 - .../Repositories/AzureSearchRepository.cs | 59 --- .../Searchers/AzureSearch.cs | 49 --- .../Wrappers/DocumentOperationWrapper.cs | 43 --- .../Wrappers/IndexOperationWrapper.cs | 56 --- Cogworks.AzureSearch.sln | 38 +- .../Builders/AzureSearchBuilder.cs | 36 +- .../Extensions/AutofacExtensions.cs | 3 +- .../Builders/AzureSearchBuilder.cs | 46 ++- ...zureSearch.LightInject.IocExtension.csproj | 4 +- .../Extensions/RegisterExtensions.cs | 3 +- .../Builders/AzureSearchBuilder.cs | 38 +- .../Extensions/BuilderExtensions.cs | 3 +- .../Builders/AzureSearchBuilder.cs | 44 ++- ...ks.AzureSearch.Umbraco.IocExtension.csproj | 72 ++-- .../Extensions/RegisterExtensions.cs | 3 +- .../Properties/AssemblyInfo.cs | 4 +- .../app.config | 24 ++ .../packages.config | 73 ++-- .../Builder/IAzureSearchBuilder.cs | 13 +- .../Cogworks.AzureSearch.csproj | 10 +- .../AddOrUpdateDocumentException.cs | 2 +- .../RemoveDocumentException.cs | 2 +- .../Exceptions/DomainException.cs | 2 +- .../IndexExceptions/IndexClearException.cs | 2 +- .../IndexCreateOrUpdateException.cs | 2 +- .../IndexExceptions/IndexDeleteException.cs | 2 +- .../IndexExceptions/IndexExistsException.cs | 2 +- .../IndexInitializerException.cs | 2 +- .../Indexes/AzureIndex.cs | 14 +- .../Initializers/AzureInitializer.cs | 20 +- .../Interfaces/Indexes/IAzureIndex.cs | 5 +- .../Initializers/IAzureInitializer.cs | 2 +- .../Operations/IAzureDocumentOperation.cs | 6 +- .../Operations/IAzureIndexOperation.cs | 6 +- .../Repositories/IAzureSearchRepository.cs | 2 +- .../Searches/IAzureDocumentSearch.cs | 12 - .../Interfaces/Searches/IAzureSearch.cs | 4 +- .../Wrappers/IDocumentOperationWrapper.cs | 14 +- .../Wrappers/IIndexOperationWrapper.cs | 10 +- .../Mappers/AzureSearchParametersMapper.cs | 8 +- .../Mappers/SearchResultMapper.cs | 6 +- .../Models/AzureIndexDefinition.cs | 7 +- .../Models/AzureSearchParameters.cs | 14 +- .../Dtos/AzureDocumentOperationResult.cs | 2 + .../Options/AzureSearchClientOption.cs | 40 +- .../Repositories/AzureSearchRepository.cs | 302 ++------------- .../Searchers/AzureSearch.cs | 43 ++- .../Searchers/BaseDomainSearch.cs | 22 ++ .../Services/AzureDocumentOperationService.cs | 16 +- .../Services/AzureIndexOperationService.cs | 14 +- .../Wrappers/DocumentOperationWrapper.cs | 45 ++- .../Wrappers/IndexOperationWrapper.cs | 48 ++- ...orks.AzureCognitiveSearch.UnitTests.csproj | 51 --- .../Models/TestDocumentModel.cs | 18 - .../Operations/DocumentOperationTests.cs | 365 ------------------ .../Operations/IndexOperationTests.cs | 302 --------------- .../TestBase.cs | 45 --- .../AutofacIocExtensionTests.cs | 24 +- ...ks.AzureSearch.AutofacIoc.UnitTests.csproj | 1 - .../Models/FirstTestDocumentModel.cs | 10 +- .../Models/NotRegistredTestDocumentModel.cs | 10 +- .../Models/SecondTestDocumentModel.cs | 10 +- .../Models/ThirdTestDocumentModel.cs | 10 +- .../Searchers/CustomTestSearch.cs | 6 +- ...s.AzureSearch.LightInject.UnitTests.csproj | 1 - .../LightInjectIocExtensionTests.cs | 17 +- .../Models/FirstTestDocumentModel.cs | 10 +- .../Models/NotRegistredTestDocumentModel.cs | 10 +- .../Models/SecondTestDocumentModel.cs | 10 +- .../Models/ThirdTestDocumentModel.cs | 10 +- .../Searchers/CustomTestSearch.cs | 5 +- ....AzureSearch.MicrosoftIoc.UnitTests.csproj | 1 - .../MicrosoftIocExtensionTests.cs | 13 +- .../Models/FirstTestDocumentModel.cs | 10 +- .../Models/NotRegistredTestDocumentModel.cs | 10 +- .../Models/SecondTestDocumentModel.cs | 10 +- .../Models/ThirdTestDocumentModel.cs | 10 +- .../Searchers/CustomTestSearch.cs | 5 +- ...ks.AzureSearch.UmbracoIoc.UnitTests.csproj | 58 ++- .../Models/FirstTestDocumentModel.cs | 12 +- .../Models/NotRegistredTestDocumentModel.cs | 12 +- .../Models/SecondTestDocumentModel.cs | 12 +- .../Models/ThirdTestDocumentModel.cs | 10 +- .../Searchers/CustomTestSearch.cs | 5 +- .../UmbracoIocExtensionTests.cs | 13 +- .../app.config | 20 + .../packages.config | 121 +++--- .../Cogworks.AzureSearch.UnitTests.csproj | 18 +- .../Models/TestDocumentModel.cs | 13 +- .../Models/TestResponse.cs | 2 +- .../Operations/DocumentOperationTests.cs | 224 +++++++++-- .../Operations/IndexOperationTests.cs | 190 ++++----- .../TestBase.cs | 16 + 126 files changed, 1106 insertions(+), 2592 deletions(-) delete mode 100644 Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj delete mode 100644 Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs delete mode 100644 Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs (85%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/DocumentsExceptions/RemoveDocumentException.cs (84%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/DomainException.cs (88%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/IndexExceptions/IndexClearException.cs (84%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs (85%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/IndexExceptions/IndexDeleteException.cs (84%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/IndexExceptions/IndexExistsException.cs (84%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Exceptions/IndexExceptions/IndexInitializerException.cs (85%) delete mode 100644 src/Cogworks.AzureSearch/Interfaces/Searches/IAzureDocumentSearch.cs rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Mappers/AzureSearchParametersMapper.cs (93%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Mappers/SearchResultMapper.cs (87%) create mode 100644 src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Services/AzureDocumentOperationService.cs (93%) rename {Cogworks.AzureCognitiveSearch => src/Cogworks.AzureSearch}/Services/AzureIndexOperationService.cs (86%) delete mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj delete mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs delete mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs delete mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs delete mode 100644 tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs rename tests/UnitTests/{Cogworks.AzureCognitiveSearch.UnitTests => Cogworks.AzureSearch.UnitTests}/Models/TestResponse.cs (85%) diff --git a/Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs b/Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs deleted file mode 100644 index d3a7f1e..0000000 --- a/Cogworks.AzureCognitiveSearch/Builder/IAzureSearchBuilder.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureCognitiveSearch.Interfaces.Searches; -using Cogworks.AzureCognitiveSearch.Models; - -namespace Cogworks.AzureCognitiveSearch.Builder -{ - public interface IAzureSearchBuilder - { - IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false); - - IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials); - - IAzureSearchBuilder RegisterIndexDefinitions(string indexName) - where TDocument : class, IAzureModel, new(); - - IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) - where TDocument : class, IAzureModel, new(); - - IAzureSearchBuilder RegisterDomainSearcher() - where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType - where TSearcherType : class; - - IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType - where TSearcherType : class; - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj b/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj deleted file mode 100644 index 86baa95..0000000 --- a/Cogworks.AzureCognitiveSearch/Cogworks.AzureCognitiveSearch.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - netstandard2.0 - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - diff --git a/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs b/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs deleted file mode 100644 index 83aeded..0000000 --- a/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Separators.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Constants.StringConstants -{ - internal class Separators - { - public const string Comma = ","; - public const string Vertical = "|"; - public const string Hyphen = "-"; - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs b/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs deleted file mode 100644 index 76bffe9..0000000 --- a/Cogworks.AzureCognitiveSearch/Constants/StringConstants/Terms.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Constants.StringConstants -{ - internal class Terms - { - public const string Null = "null"; - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs b/Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs deleted file mode 100644 index 9cf50d7..0000000 --- a/Cogworks.AzureCognitiveSearch/Enums/AzureQueryType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Enums -{ - public enum AzureQueryType - { - Simple = 0, - Full = 1 - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs b/Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs deleted file mode 100644 index b582914..0000000 --- a/Cogworks.AzureCognitiveSearch/Enums/AzureSearchModeType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Enums -{ - public enum AzureSearchModeType - { - Any = 0, - All = 1 - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs b/Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs deleted file mode 100644 index 8906779..0000000 --- a/Cogworks.AzureCognitiveSearch/Extensions/EnumerableExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Cogworks.AzureCognitiveSearch.Extensions -{ - internal static class EnumerableExtensions - { - public static bool HasAny(this IEnumerable items) - => items != null && items.Any(); - - public static IEnumerable> ChunkBy(this IEnumerable items, int chunkSize) - => items - .Select((x, i) => new { Index = i, Value = x }) - .GroupBy(x => x.Index / chunkSize) - .Select(x => x.Select(v => v.Value).ToList()) - .ToList(); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs b/Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs deleted file mode 100644 index 6c3c5ba..0000000 --- a/Cogworks.AzureCognitiveSearch/Extensions/StringExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Constants.StringConstants; - -namespace Cogworks.AzureCognitiveSearch.Extensions -{ - internal static class StringExtensions - { - public static bool HasValue(this string input) - => !string.IsNullOrWhiteSpace(input); - - public static string EscapeHyphen(this string input) - => input.Escape(Separators.Hyphen); - - public static string Escape(this string input, string character) - => input.HasValue() - ? input.Replace( - $"{character}", - $@"\{character}") - : input; - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs deleted file mode 100644 index 3a911a0..0000000 --- a/Cogworks.AzureCognitiveSearch/Filters/ArrayOperationsFilter.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Extensions; - -namespace Cogworks.AzureCognitiveSearch.Filters -{ - public static class ArrayOperationsFilter - { - public static string SearchIn(this string query, string field, string searchedValue, string separator = Constants.StringConstants.Separators.Comma) - { - if (!field.HasValue()) - { - return query; - } - - var searchQuery = $"search.in({field}, '{searchedValue}', '{separator}')"; - - return query.HasValue() - ? $"{query} {searchQuery}" - : searchQuery; - } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs deleted file mode 100644 index 91df616..0000000 --- a/Cogworks.AzureCognitiveSearch/Filters/LiteralsOperationsFilter.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Extensions; - -namespace Cogworks.AzureCognitiveSearch.Filters -{ - public static class LiteralsOperationsFilter - { - public static string Field(this string query, string field) - => query.HasValue() - ? $"{query} {field}" - : field; - - public static string Value(this string query, string value) - => $"{query} '{value}'"; - - public static string Property(this string query, string value) - => $"{query}/{value}"; - - public static string Append(this string query, string value) - => value.HasValue() ? $"{query} {value}" : query; - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs deleted file mode 100644 index c064a14..0000000 --- a/Cogworks.AzureCognitiveSearch/Filters/LogicOperationsFilter.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Extensions; -using System.Collections.Generic; - -namespace Cogworks.AzureCognitiveSearch.Filters -{ - public static class LogicOperationsFilter - { - public static string And(this string query) - => query.HasValue() && !query.EndsWith(" and") - ? $"{query} and" - : query; - - public static string Or(this string query) - => query.HasValue() && !query.EndsWith(" or") ? $"{query} or" : query; - - public static string Not(this string query) - => query.HasValue() && !query.EndsWith(" not") ? $"{query} not" : query; - - public static string Equals(this string query) - => query.HasValue() && !query.EndsWith(" eq") ? $"{query} eq" : query; - - public static string EqualsValue(this string query, string value) - { - var equalsQuery = query.Equals(); - - return equalsQuery.HasValue() && equalsQuery.EndsWith(" eq") && value.HasValue() - ? equalsQuery.Value(value) - : query; - } - - public static string EqualsNull(this string query) - => query.HasValue() && !query.EndsWith($" {Constants.StringConstants.Terms.Null}") - ? $"{query.Equals()} {Constants.StringConstants.Terms.Null}" - : query; - - public static string NotEquals(this string query) - => query.HasValue() && !query.EndsWith(" ne") ? $"{query} ne" : query; - - public static string NotEqualsValue(this string query, string value) - { - var notEqualsQuery = query.NotEquals(); - - return notEqualsQuery.HasValue() && notEqualsQuery.EndsWith(" ne") && value.HasValue() - ? notEqualsQuery.Value(value) - : query; - } - - public static string NotEqualsNull(this string query) - => query.HasValue() && !query.EndsWith(" ne") - ? $"{query.NotEquals()} {Constants.StringConstants.Terms.Null}" - : query; - - public static string Any(this string query, string collectionName, string condition) - { - if (collectionName.HasValue() && condition.HasValue()) - { - return query.HasValue() - ? $"{query} {collectionName}/any({condition})" - : $"{collectionName}/any({condition})"; - } - - return query; - } - - public static string NormalizeQuery(this string query) - { - var normalizedQuery = query.Trim(); - - foreach (var logicalOperator in LogicalOperators()) - { - normalizedQuery = normalizedQuery - .TrimEnd(logicalOperator.ToCharArray()) - .TrimStart(logicalOperator.ToCharArray()); - } - - return normalizedQuery; - } - - private static IEnumerable LogicalOperators() - => new[] - { - "and", - "or", - "ne", - "eq", - "not" - }; - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs b/Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs deleted file mode 100644 index fbca364..0000000 --- a/Cogworks.AzureCognitiveSearch/Filters/RangeFilter.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Extensions; - -namespace Cogworks.AzureCognitiveSearch.Filters -{ - public static class RangeFilter - { - public static string GreaterThan(this string query, string field, string value) - => BuildRangeFilter(query, field, value, "gt"); - - public static string GreaterThanOrEqualTo(this string query, string field, string value) - => BuildRangeFilter(query, field, value, "ge"); - - public static string LessThan(this string query, string field, string value) - => BuildRangeFilter(query, field, value, "lt"); - - public static string LessThanOrEqualTo(this string query, string field, string value) - => BuildRangeFilter(query, field, value, "le"); - - private static string BuildRangeFilter(string query, string field, string value, string @operator) - { - if (!field.HasValue() || !value.HasValue()) - { - return query; - } - - var resultQuery = $"{field} {@operator} {value}"; - - return query.HasValue() - ? $"{query} {resultQuery}" - : resultQuery; - } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs b/Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs deleted file mode 100644 index da20b00..0000000 --- a/Cogworks.AzureCognitiveSearch/Indexes/AzureIndex.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Interfaces.Indexes; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cogworks.AzureCognitiveSearch.Indexes -{ - internal class AzureIndex : IAzureIndex where TAzureModel : class, IAzureModel, new() - { - private readonly IAzureDocumentOperation _documentOperation; - - public AzureIndex(IAzureDocumentOperation documentOperation) - => _documentOperation = documentOperation; - - public async Task AddOrUpdateDocumentAsync(TAzureModel model) - => await _documentOperation.AddOrUpdateDocumentAsync(model); - - public async Task TryRemoveDocumentAsync(TAzureModel model) - => await _documentOperation.TryRemoveDocumentAsync(model); - - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) - => await _documentOperation.AddOrUpdateDocumentsAsync(models); - - public async Task TryRemoveDocumentsAsync(IEnumerable models) - => await _documentOperation.TryRemoveDocumentsAsync(models); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs b/Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs deleted file mode 100644 index 6f8d72b..0000000 --- a/Cogworks.AzureCognitiveSearch/Initializers/AzureInitializer.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions; -using Cogworks.AzureCognitiveSearch.Interfaces.Initializers; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; -using Cogworks.AzureCognitiveSearch.Options; - -namespace Cogworks.AzureCognitiveSearch.Initializers -{ - internal class AzureInitializer : IAzureInitializer - where TAzureModel : class, IAzureModel, new() - { - private readonly AzureSearchIndexOption _azureSearchIndexOption; - private readonly IAzureIndexOperation _azureIndexOperation; - - public AzureInitializer(AzureSearchIndexOption azureSearchIndexOption, IAzureIndexOperation azureIndexOperation) - { - _azureSearchIndexOption = azureSearchIndexOption; - _azureIndexOperation = azureIndexOperation; - } - - public async Task InitializeAsync() - { - if (_azureSearchIndexOption.Recreate) - { - await _azureIndexOperation.IndexDeleteAsync(); - } - - try - { - await _azureIndexOperation.IndexCreateOrUpdateAsync(); - } - catch (Exception) - { - if (_azureSearchIndexOption.RecreateOnUpdateFailure) - { - await _azureIndexOperation.IndexDeleteAsync(); - } - } - - try - { - await _azureIndexOperation.IndexCreateOrUpdateAsync(); - } - catch (Exception exception) - { - throw new IndexInitializerException(exception.Message, exception.InnerException); - } - } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs deleted file mode 100644 index 5875c5a..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Indexes/IAzureIndex.cs +++ /dev/null @@ -1,19 +0,0 @@ - -using System.Collections.Generic; -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Indexes -{ - public interface IAzureIndex where TAzureModel : class, IAzureModel, new() - { - Task AddOrUpdateDocumentAsync(TAzureModel model); - - Task AddOrUpdateDocumentsAsync(IEnumerable models); - - Task TryRemoveDocumentAsync(TAzureModel model); - - Task TryRemoveDocumentsAsync(IEnumerable models); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs deleted file mode 100644 index 32a4bae..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Initializers/IAzureInitializer.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; -using System.Threading.Tasks; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Initializers -{ - public interface IAzureInitializer where TAzureModel : class, IAzureModel, new() - { - Task InitializeAsync(); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs deleted file mode 100644 index f0dd705..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureDocumentOperation.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Operations -{ - public interface IAzureDocumentOperation where TAzureModel : class, IAzureModel, new() - { - Task AddOrUpdateDocumentAsync(TAzureModel model); - - Task AddOrUpdateDocumentsAsync(IEnumerable models); - - Task TryRemoveDocumentAsync(TAzureModel model); - - Task TryRemoveDocumentsAsync(IEnumerable models); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs deleted file mode 100644 index f068234..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Operations/IAzureIndexOperation.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Operations -{ - public interface IAzureIndexOperation where TAzureModel : class, IAzureModel, new() - { - Task IndexExistsAsync(); - - Task IndexDeleteAsync(); - - Task IndexCreateOrUpdateAsync(); - - Task IndexClearAsync(); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs deleted file mode 100644 index 7a74471..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Repositories/IAzureSearchRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Interfaces.Searches; -using Cogworks.AzureCognitiveSearch.Models; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Repositories -{ - public interface IAzureSearchRepository : - IAzureDocumentOperation, - IAzureIndexOperation, - IAzureSearch - where TAzureModel : class, IAzureModel, new() - { - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs deleted file mode 100644 index 2a65c09..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Searches/IAzureSearch.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Searches -{ - public interface IAzureSearch where TAzureModel : class, IAzureModel, new() - { - SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters); - - Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs deleted file mode 100644 index dffeca0..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading.Tasks; -using Azure; -using Azure.Search.Documents; -using Azure.Search.Documents.Models; -using Cogworks.AzureCognitiveSearch.Models; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Wrappers -{ - public interface IDocumentOperationWrapper where TAzureModel : class, IAzureModel, new() - { - SearchResults Search(string searchText, SearchOptions parameters = null); - - Task> SearchAsync(string searchText, SearchOptions parameters = null); - - Task> IndexAsync(IndexDocumentsBatch indexBatch); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs deleted file mode 100644 index bc902fb..0000000 --- a/Cogworks.AzureCognitiveSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading.Tasks; -using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureCognitiveSearch.Models; - -namespace Cogworks.AzureCognitiveSearch.Interfaces.Wrappers -{ - public interface IIndexOperationWrapper - { - Task ExistsAsync(string indexName); - - Task DeleteAsync(string indexName); - - Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new(); - - Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new(); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs b/Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs deleted file mode 100644 index 78eb199..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/AzureIndexDefinition.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Azure.Search.Documents.Indexes.Models; - -namespace Cogworks.AzureCognitiveSearch.Models -{ - public class AzureIndexDefinition where TAzureModel : class, IAzureModel, new() - { - public string IndexName { get; } - - public SearchIndex CustomIndexDefinition { get; } - - public AzureIndexDefinition(string indexName) - => IndexName = indexName; - - public AzureIndexDefinition(SearchIndex customIndex) - => (CustomIndexDefinition, IndexName) = (customIndex, customIndex.Name); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs b/Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs deleted file mode 100644 index 4872e3a..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/AzureSearchParameters.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Generic; -using Cogworks.AzureCognitiveSearch.Enums; - -namespace Cogworks.AzureCognitiveSearch.Models -{ - public class AzureSearchParameters - { - public bool IncludeTotalResultCount { get; set; } - - public IEnumerable Facets { get; set; } - - public string Filter { get; set; } - - public IEnumerable HighlightFields { get; set; } - - public string HighlightPostTag { get; set; } - - public string HighlightPreTag { get; set; } - - public double? MinimumCoverage { get; set; } - - public IEnumerable OrderBy { get; set; } - - public AzureQueryType QueryType { get; set; } - - public string ScoringProfile { get; set; } - - public IEnumerable SearchFields { get; set; } - - public AzureSearchModeType SearchMode { get; set; } - - public IEnumerable Select { get; set; } - - public int Skip { get; set; } - - public int Take { get; set; } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs deleted file mode 100644 index 6152c97..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Cogworks.AzureCognitiveSearch.Models.Dtos -{ - public class AzureBatchDocumentsOperationResult - { - public bool Succeeded { get; set; } - - public string Message { get; set; } - - public IEnumerable SucceededDocuments { get; set; } = Enumerable.Empty(); - - public IEnumerable FailedDocuments { get; set; } = Enumerable.Empty(); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs deleted file mode 100644 index f1e0423..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureDocumentOperationResult.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Models.Dtos -{ - public class AzureDocumentOperationResult - { - public bool Succeeded { get; set; } - - public string ModelId { get; set; } - - public string Message { get; set; } - - public string InnerMessage { get; set; } - - public int StatusCode { get; set; } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs deleted file mode 100644 index 96ae3fa..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/Dtos/AzureIndexOperationResult.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Models.Dtos -{ - public class AzureIndexOperationResult - { - public bool Succeeded { get; set; } - - public string Message { get; set; } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs deleted file mode 100644 index c5dedd8..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResult.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; - -namespace Cogworks.AzureCognitiveSearch.Models.Dtos -{ - public class SearchResult where TModel : class, IAzureModel, new() - { - public long TotalCount { get; set; } - - public IEnumerable> Results { get; set; } - - public bool HasMoreItems { get; set; } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs b/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs deleted file mode 100644 index 88d6934..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/Dtos/SearchResultItem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; - -namespace Cogworks.AzureCognitiveSearch.Models.Dtos -{ - public class SearchResultItem where TModel : class, IAzureModel, new() - { - public TModel Document { get; } - - public IDictionary> Highlights { get; } - - public double Score { get; } - - public SearchResultItem(TModel document, IDictionary> highlights, double score) - { - Document = document; - Highlights = highlights; - Score = score; - } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs b/Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs deleted file mode 100644 index 631bf95..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/IAzureModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Models -{ - public interface IAzureModel - { - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs b/Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs deleted file mode 100644 index 3bca2a9..0000000 --- a/Cogworks.AzureCognitiveSearch/Models/IAzureModelIdentity.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Models -{ - public interface IAzureModelIdentity : IAzureModel - { - string Id { get; set; } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs b/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs deleted file mode 100644 index 3b814a4..0000000 --- a/Cogworks.AzureCognitiveSearch/Options/AzureSearchClientOption.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Azure.Core; -using Azure.Core.Pipeline; -using Azure.Search.Documents; - -namespace Cogworks.AzureCognitiveSearch.Options -{ - public class AzureSearchClientOption - { - public string ServiceName { get; } - - public string Credentials { get; } - - public string ServiceUrlEndpoint { get; } - - public SearchClientOptions ClientOptions { get; } - - - - public AzureSearchClientOption(string serviceName, string credentials, string serviceUrlEndpoint) - { - ServiceName = serviceName; - Credentials = credentials; - ServiceUrlEndpoint = serviceUrlEndpoint; - ClientOptions = GetOptions(); - } - - - private static SearchClientOptions GetOptions() - { - var clientOptions = new SearchClientOptions(); - - - clientOptions.AddPolicy( - new SearchIdPipelinePolicy(), - HttpPipelinePosition.PerCall); - - return clientOptions; - } - - private class SearchIdPipelinePolicy : HttpPipelineSynchronousPolicy - { - public override void OnSendingRequest(HttpMessage message) - => message.Request - .Headers - .SetValue("x-ms-azs-return-searchid", "true"); - } -} -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs b/Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs deleted file mode 100644 index 35efb01..0000000 --- a/Cogworks.AzureCognitiveSearch/Options/AzureSearchIndexOption.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Cogworks.AzureCognitiveSearch.Options -{ - public class AzureSearchIndexOption - { - public bool Recreate { get; } - - public bool RecreateOnUpdateFailure { get; } - - public AzureSearchIndexOption(bool recreate, bool recreateOnUpdateFailure) - { - Recreate = recreate; - RecreateOnUpdateFailure = recreateOnUpdateFailure; - } - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs b/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs deleted file mode 100644 index 3d6e520..0000000 --- a/Cogworks.AzureCognitiveSearch/Repositories/AzureSearchRepository.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Interfaces.Repositories; -using Cogworks.AzureCognitiveSearch.Interfaces.Searches; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; - -namespace Cogworks.AzureCognitiveSearch.Repositories -{ - internal class AzureSearchRepository : IAzureSearchRepository - where TAzureModel : class, IAzureModel, new() - { - private readonly IAzureIndexOperation _indexOperation; - private readonly IAzureDocumentOperation _documentOperation; - private readonly IAzureSearch _search; - - public AzureSearchRepository( - IAzureIndexOperation indexOperation, - IAzureDocumentOperation documentOperation, - IAzureSearch search) - { - _indexOperation = indexOperation; - _documentOperation = documentOperation; - _search = search; - } - - public async Task AddOrUpdateDocumentAsync(TAzureModel model) - => await _documentOperation.AddOrUpdateDocumentAsync(model); - - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) - => await _documentOperation.AddOrUpdateDocumentsAsync(models); - - public async Task TryRemoveDocumentAsync(TAzureModel model) - => await _documentOperation.TryRemoveDocumentAsync(model); - - public async Task TryRemoveDocumentsAsync(IEnumerable models) - => await _documentOperation.TryRemoveDocumentsAsync(models); - - public async Task IndexExistsAsync() - => await _indexOperation.IndexExistsAsync(); - - public async Task IndexDeleteAsync() - => await _indexOperation.IndexDeleteAsync(); - - public async Task IndexCreateOrUpdateAsync() - => await _indexOperation.IndexCreateOrUpdateAsync(); - - public async Task IndexClearAsync() - => await _indexOperation.IndexClearAsync(); - - public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) - => _search.Search(keyword, azureSearchParameters); - - public async Task> SearchAsync(string keyword, - AzureSearchParameters azureSearchParameters) - => await _search.SearchAsync(keyword, azureSearchParameters); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs b/Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs deleted file mode 100644 index 9d69226..0000000 --- a/Cogworks.AzureCognitiveSearch/Searchers/AzureSearch.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Extensions; -using Cogworks.AzureCognitiveSearch.Interfaces.Searches; -using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; -using Cogworks.AzureCognitiveSearch.Mappers; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; - -namespace Cogworks.AzureCognitiveSearch.Searchers -{ - public class AzureSearch : IAzureSearch - where TAzureModel : class, IAzureModel, new() - { - private readonly IDocumentOperationWrapper _documentOperationWrapper; - - public AzureSearch(IDocumentOperationWrapper documentOperationWrapper) - => _documentOperationWrapper = documentOperationWrapper; - - public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) - { - var searchText = GetSearchText(keyword); - var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); - var results = _documentOperationWrapper.Search($"{searchText}", parameters); - - return SearchResultMapper.Map( - results, - azureSearchParameters.Skip, - azureSearchParameters.Take); - } - - public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) - { - var searchText = GetSearchText(keyword); - var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); - var results = await _documentOperationWrapper.SearchAsync(searchText, parameters); - - return SearchResultMapper.Map( - results, - azureSearchParameters.Skip, - azureSearchParameters.Take); - } - - private static string GetSearchText(string keyword) - => keyword.EscapeHyphen().HasValue() - ? keyword.EscapeHyphen() - : "*"; - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs deleted file mode 100644 index eca45e5..0000000 --- a/Cogworks.AzureCognitiveSearch/Wrappers/DocumentOperationWrapper.cs +++ /dev/null @@ -1,43 +0,0 @@ - -using System; -using System.Threading.Tasks; -using Azure; -using Azure.Search.Documents; -using Azure.Search.Documents.Models; -using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Options; - -namespace Cogworks.AzureCognitiveSearch.Wrappers -{ - internal class DocumentOperationWrapper : IDocumentOperationWrapper - where TAzureModel : class, IAzureModel, new() - { - private readonly SearchClient _searchClient; - - - public DocumentOperationWrapper( - AzureIndexDefinition azureIndexDefinition, - AzureSearchClientOption azureSearchClientOption) - { - var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); - - _searchClient = new SearchClient( - endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), - indexName: azureIndexDefinition.IndexName, - credential: azureKeyCredential, - options: azureSearchClientOption.ClientOptions - - ); - } - - public SearchResults Search(string searchText, SearchOptions parameters = null) - => _searchClient.Search(searchText, parameters); - - public async Task> SearchAsync(string searchText, SearchOptions parameters = null) - => await _searchClient.SearchAsync(searchText, parameters); - - public async Task> IndexAsync(IndexDocumentsBatch indexBatch) - => await _searchClient.IndexDocumentsAsync(indexBatch); - } -} \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs b/Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs deleted file mode 100644 index 71417d6..0000000 --- a/Cogworks.AzureCognitiveSearch/Wrappers/IndexOperationWrapper.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Threading.Tasks; -using Azure; -using Azure.Search.Documents.Indexes; -using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Options; - -namespace Cogworks.AzureCognitiveSearch.Wrappers -{ - internal class IndexOperationWrapper : IIndexOperationWrapper - { - private readonly SearchIndexClient _searchIndexClient; - - public IndexOperationWrapper(AzureSearchClientOption azureSearchClientOption) - { - var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); - - _searchIndexClient = new SearchIndexClient( - endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), - credential: azureKeyCredential); - } - - public async Task ExistsAsync(string indexName) - => (await _searchIndexClient.GetIndexAsync(indexName)).Value != null; - - public async Task DeleteAsync(string indexName) - => await _searchIndexClient.DeleteIndexAsync(indexName); - - public async Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new() - { - var fieldBuilder = new FieldBuilder(); - var searchFields = fieldBuilder.Build(typeof(TAzureModel)); - - var definition = new SearchIndex( - indexName, - searchFields); - - return await _searchIndexClient.CreateOrUpdateIndexAsync(definition); - } - - public async Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new() - { - if (overrideFields) - { - var fieldBuilder = new FieldBuilder(); - var searchFields = fieldBuilder.Build(typeof(TAzureModel)); - - customIndexDefinition.Fields = searchFields; - } - - return await _searchIndexClient.CreateOrUpdateIndexAsync(customIndexDefinition); - } - } -} \ No newline at end of file diff --git a/Cogworks.AzureSearch.sln b/Cogworks.AzureSearch.sln index 90c5434..873475d 100644 --- a/Cogworks.AzureSearch.sln +++ b/Cogworks.AzureSearch.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30128.74 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch", "src\Cogworks.AzureSearch\Cogworks.AzureSearch.csproj", "{64B55C63-5070-430F-A92D-747FF2CD57A6}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.Autofac.IocExtension", "src\Cogworks.AzureSearch.Autofac.IocExtension\Cogworks.AzureSearch.Autofac.IocExtension.csproj", "{060A2DE8-2E15-4EA5-ACCB-5061B50B350F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B85EEFD6-B048-478E-A032-3CCE3F0B3093}" @@ -15,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.UnitTests", "tests\UnitTests\Cogworks.AzureSearch.UnitTests\Cogworks.AzureSearch.UnitTests.csproj", "{37898883-18CD-47A7-BA59-E4FC1FD8B8E1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cogworks.AzureSearch.Umbraco.IocExtension", "src\Cogworks.AzureSearch.Umbraco.IocExtension\Cogworks.AzureSearch.Umbraco.IocExtension.csproj", "{FC38DB43-401F-4E88-BAF5-A28325E4C461}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cogworks.AzureSearch.UmbracoIoc.UnitTests", "tests\UnitTests\Cogworks.AzureSearch.UmbracoIoc.UnitTests\Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj", "{31032AAC-7779-4DEF-81D4-B6143A716C4F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.LightInject.IocExtension", "src\Cogworks.AzureSearch.LightInject.IocExtension\Cogworks.AzureSearch.LightInject.IocExtension.csproj", "{4C606328-9108-4584-8E4A-04450B9A1170}" @@ -29,9 +25,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.Autofa EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch.LightInject.UnitTests", "tests\UnitTests\Cogworks.AzureSearch.LightInject.UnitTests\Cogworks.AzureSearch.LightInject.UnitTests.csproj", "{90E65F2C-9592-473C-83BB-FC109A11C47D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureCognitiveSearch", "Cogworks.AzureCognitiveSearch\Cogworks.AzureCognitiveSearch.csproj", "{A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureSearch", "src\Cogworks.AzureSearch\Cogworks.AzureSearch.csproj", "{94F77E26-4E02-4ED5-BD54-45E3AAA70090}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cogworks.AzureCognitiveSearch.UnitTests", "tests\UnitTests\Cogworks.AzureCognitiveSearch.UnitTests\Cogworks.AzureCognitiveSearch.UnitTests.csproj", "{733886AB-26AF-4169-BA23-87B25D11EE56}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cogworks.AzureSearch.Umbraco.IocExtension", "src\Cogworks.AzureSearch.Umbraco.IocExtension\Cogworks.AzureSearch.Umbraco.IocExtension.csproj", "{E1317854-28A7-491E-97B1-FBEEEF7B5982}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,10 +35,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {64B55C63-5070-430F-A92D-747FF2CD57A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {64B55C63-5070-430F-A92D-747FF2CD57A6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {64B55C63-5070-430F-A92D-747FF2CD57A6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {64B55C63-5070-430F-A92D-747FF2CD57A6}.Release|Any CPU.Build.0 = Release|Any CPU {060A2DE8-2E15-4EA5-ACCB-5061B50B350F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {060A2DE8-2E15-4EA5-ACCB-5061B50B350F}.Debug|Any CPU.Build.0 = Debug|Any CPU {060A2DE8-2E15-4EA5-ACCB-5061B50B350F}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -51,10 +43,6 @@ Global {37898883-18CD-47A7-BA59-E4FC1FD8B8E1}.Debug|Any CPU.Build.0 = Debug|Any CPU {37898883-18CD-47A7-BA59-E4FC1FD8B8E1}.Release|Any CPU.ActiveCfg = Release|Any CPU {37898883-18CD-47A7-BA59-E4FC1FD8B8E1}.Release|Any CPU.Build.0 = Release|Any CPU - {FC38DB43-401F-4E88-BAF5-A28325E4C461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC38DB43-401F-4E88-BAF5-A28325E4C461}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC38DB43-401F-4E88-BAF5-A28325E4C461}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC38DB43-401F-4E88-BAF5-A28325E4C461}.Release|Any CPU.Build.0 = Release|Any CPU {31032AAC-7779-4DEF-81D4-B6143A716C4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {31032AAC-7779-4DEF-81D4-B6143A716C4F}.Debug|Any CPU.Build.0 = Debug|Any CPU {31032AAC-7779-4DEF-81D4-B6143A716C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -79,32 +67,30 @@ Global {90E65F2C-9592-473C-83BB-FC109A11C47D}.Debug|Any CPU.Build.0 = Debug|Any CPU {90E65F2C-9592-473C-83BB-FC109A11C47D}.Release|Any CPU.ActiveCfg = Release|Any CPU {90E65F2C-9592-473C-83BB-FC109A11C47D}.Release|Any CPU.Build.0 = Release|Any CPU - {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215}.Release|Any CPU.Build.0 = Release|Any CPU - {733886AB-26AF-4169-BA23-87B25D11EE56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {733886AB-26AF-4169-BA23-87B25D11EE56}.Debug|Any CPU.Build.0 = Debug|Any CPU - {733886AB-26AF-4169-BA23-87B25D11EE56}.Release|Any CPU.ActiveCfg = Release|Any CPU - {733886AB-26AF-4169-BA23-87B25D11EE56}.Release|Any CPU.Build.0 = Release|Any CPU + {94F77E26-4E02-4ED5-BD54-45E3AAA70090}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94F77E26-4E02-4ED5-BD54-45E3AAA70090}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94F77E26-4E02-4ED5-BD54-45E3AAA70090}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94F77E26-4E02-4ED5-BD54-45E3AAA70090}.Release|Any CPU.Build.0 = Release|Any CPU + {E1317854-28A7-491E-97B1-FBEEEF7B5982}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E1317854-28A7-491E-97B1-FBEEEF7B5982}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E1317854-28A7-491E-97B1-FBEEEF7B5982}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E1317854-28A7-491E-97B1-FBEEEF7B5982}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {64B55C63-5070-430F-A92D-747FF2CD57A6} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} {060A2DE8-2E15-4EA5-ACCB-5061B50B350F} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} {180E9BD6-30B9-4D88-B88C-9F289D316967} = {B5DAEDD1-13AF-4A74-BD24-42EBCB1A18D0} {37898883-18CD-47A7-BA59-E4FC1FD8B8E1} = {180E9BD6-30B9-4D88-B88C-9F289D316967} - {FC38DB43-401F-4E88-BAF5-A28325E4C461} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} {31032AAC-7779-4DEF-81D4-B6143A716C4F} = {180E9BD6-30B9-4D88-B88C-9F289D316967} {4C606328-9108-4584-8E4A-04450B9A1170} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} {E60BD2A0-C5ED-4EFE-8F8A-15FB26AD69B4} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} {1F9F4E09-E496-49F2-A1EB-D4EB3AC3E721} = {180E9BD6-30B9-4D88-B88C-9F289D316967} {0648AF35-71D5-4BA4-A1BF-0476AAC71BEE} = {180E9BD6-30B9-4D88-B88C-9F289D316967} {90E65F2C-9592-473C-83BB-FC109A11C47D} = {180E9BD6-30B9-4D88-B88C-9F289D316967} - {A6B7CF93-F21C-46A2-8F87-E9FE7C3D2215} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} - {733886AB-26AF-4169-BA23-87B25D11EE56} = {180E9BD6-30B9-4D88-B88C-9F289D316967} + {94F77E26-4E02-4ED5-BD54-45E3AAA70090} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} + {E1317854-28A7-491E-97B1-FBEEEF7B5982} = {B85EEFD6-B048-478E-A032-3CCE3F0B3093} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DC813CF7-BD65-4CD5-B0B7-7B1F828A9909} diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index d6b7731..5b1affc 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -1,4 +1,5 @@ using Autofac; +using Azure.Search.Documents.Indexes.Models; using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; @@ -12,8 +13,8 @@ using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; +using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; -using Microsoft.Azure.Search.Models; namespace Cogworks.AzureSearch.Autofac.Builders { @@ -42,9 +43,12 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials) + public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { - _ = _builder.Register(_ => new AzureSearchClientOption(serviceName, credentials)) + _ = _builder.Register(_ => new AzureSearchClientOption( + serviceName, + credentials, + serviceEndpointUrl)) .AsSelf() .SingleInstance(); @@ -61,7 +65,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(Index customIndex) + public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IAzureModel, new() { _ = _builder.Register(_ => new AzureIndexDefinition(customIndex)) @@ -97,9 +101,6 @@ internal AzureSearchBuilder RegisterRepositories() { _ = _builder.RegisterGeneric(typeof(AzureSearchRepository<>)) .As(typeof(IAzureSearchRepository<>)) - .As(typeof(IAzureIndexOperation<>)) - .As(typeof(IAzureDocumentOperation<>)) - .As(typeof(IAzureDocumentSearch<>)) .InstancePerDependency(); return this; @@ -114,9 +115,22 @@ internal AzureSearchBuilder RegisterSearchers() return this; } + internal AzureSearchBuilder RegisterOperations() + { + _ = _builder.RegisterGeneric(typeof(AzureDocumentOperationService<>)) + .As(typeof(IAzureDocumentOperation<>)) + .InstancePerDependency(); + + _ = _builder.RegisterGeneric(typeof(AzureIndexOperationService<>)) + .As(typeof(IAzureIndexOperation<>)) + .InstancePerDependency(); + + return this; + } + public IAzureSearchBuilder RegisterDomainSearcher() where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType + where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { _ = _builder.RegisterType() @@ -127,8 +141,10 @@ public IAzureSearchBuilder RegisterDomainSearcher( - TSearcherType instance) + public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) + where TDocument : class, IAzureModel, new() + where TSearcher : BaseDomainSearch, TSearcherType + where TSearcherType : class { _ = _builder.RegisterInstance(instance).As(); diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs index 2ed258c..f1765fc 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs @@ -11,6 +11,7 @@ public static AzureSearchBuilder RegisterAzureSearch(this ContainerBuilder build .RegisterIndexes() .RegisterSearchers() .RegisterInitializers() - .RegisterWrappers(); + .RegisterWrappers() + .RegisterOperations(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index 2a72534..116e170 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -1,4 +1,5 @@ -using Cogworks.AzureSearch.Builder; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; using Cogworks.AzureSearch.Interfaces.Indexes; @@ -11,9 +12,9 @@ using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; +using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; using LightInject; -using Microsoft.Azure.Search.Models; namespace Cogworks.AzureSearch.LightInject.IocExtension.Builders { @@ -42,10 +43,13 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials) + public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _ = _container.Register( - _ => new AzureSearchClientOption(serviceName, credentials), + _ => new AzureSearchClientOption( + serviceName, + credentials, + serviceEndpointUrl), new PerContainerLifetime()); return this; @@ -61,7 +65,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(Index customIndex) + public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IAzureModel, new() { _ = _container.Register( @@ -97,18 +101,6 @@ internal AzureSearchBuilder RegisterRepositories() typeof(IAzureSearchRepository<>), typeof(AzureSearchRepository<>)); - _ = _container.Register( - typeof(IAzureIndexOperation<>), - typeof(AzureSearchRepository<>)); - - _ = _container.Register( - typeof(IAzureDocumentOperation<>), - typeof(AzureSearchRepository<>)); - - _ = _container.Register( - typeof(IAzureDocumentSearch<>), - typeof(AzureSearchRepository<>)); - return this; } @@ -120,10 +112,24 @@ internal AzureSearchBuilder RegisterSearchers() return this; } + internal AzureSearchBuilder RegisterOperations() + { + _ = _container.Register( + typeof(IAzureDocumentOperation<>), + typeof(AzureDocumentOperationService<>), + new PerContainerLifetime()); + + _ = _container.Register( + typeof(IAzureIndexOperation<>), + typeof(AzureIndexOperationService<>), + new PerContainerLifetime()); + + return this; + } public IAzureSearchBuilder RegisterDomainSearcher() where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType + where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { _ = _container.Register(typeof(TSearcherType), typeof(TSearcher), new PerContainerLifetime()); @@ -132,9 +138,9 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TSearcher : class, IAzureSearch, TSearcherType - where TSearcherType : class where TDocument : class, IAzureModel, new() + where TSearcher : BaseDomainSearch, TSearcherType + where TSearcherType : class { _ = _container.RegisterInstance(instance); ; diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Cogworks.AzureSearch.LightInject.IocExtension.csproj b/src/Cogworks.AzureSearch.LightInject.IocExtension/Cogworks.AzureSearch.LightInject.IocExtension.csproj index f313719..9205d7d 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Cogworks.AzureSearch.LightInject.IocExtension.csproj +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Cogworks.AzureSearch.LightInject.IocExtension.csproj @@ -13,10 +13,10 @@ - + - + \ No newline at end of file diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs index 26faf5e..c537474 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs @@ -11,6 +11,7 @@ public static AzureSearchBuilder RegisterAzureSearch(this IServiceContainer serv .RegisterIndexes() .RegisterSearchers() .RegisterInitializers() - .RegisterWrappers(); + .RegisterWrappers() + .RegisterOperations(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index bc1b205..53cb7df 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -1,4 +1,5 @@ -using Cogworks.AzureSearch.Builder; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; using Cogworks.AzureSearch.Interfaces.Indexes; @@ -11,8 +12,8 @@ using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; +using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; -using Microsoft.Azure.Search.Models; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -39,9 +40,12 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials) + public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { - _serviceCollection.TryAddSingleton(_ => new AzureSearchClientOption(serviceName, credentials)); + _serviceCollection.TryAddSingleton(_ => new AzureSearchClientOption( + serviceName, + credentials, + serviceEndpointUrl)); return this; } @@ -54,7 +58,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(Index customIndex) + public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IAzureModel, new() { _serviceCollection.TryAddSingleton(_ => new AzureIndexDefinition(customIndex)); @@ -80,10 +84,9 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { - _serviceCollection.TryAddScoped(typeof(IAzureSearchRepository<>), typeof(AzureSearchRepository<>)); - _serviceCollection.TryAddScoped(typeof(IAzureIndexOperation<>), typeof(AzureSearchRepository<>)); - _serviceCollection.TryAddScoped(typeof(IAzureDocumentOperation<>), typeof(AzureSearchRepository<>)); - _serviceCollection.TryAddScoped(typeof(IAzureDocumentSearch<>), typeof(AzureSearchRepository<>)); + _serviceCollection.TryAddScoped( + typeof(IAzureSearchRepository<>), + typeof(AzureSearchRepository<>)); return this; } @@ -95,9 +98,18 @@ internal AzureSearchBuilder RegisterSearchers() return this; } + internal AzureSearchBuilder RegisterOperations() + { + _serviceCollection.TryAddScoped(typeof(IAzureDocumentOperation<>), typeof(AzureDocumentOperationService<>)); + + _serviceCollection.TryAddScoped(typeof(IAzureIndexOperation<>), typeof(AzureIndexOperationService<>)); + + return this; + } + public IAzureSearchBuilder RegisterDomainSearcher() where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType + where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { _serviceCollection.TryAddSingleton(); @@ -105,8 +117,10 @@ public IAzureSearchBuilder RegisterDomainSearcher( - TSearcherType instance) + public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) + where TDocument : class, IAzureModel, new() + where TSearcher : BaseDomainSearch, TSearcherType + where TSearcherType : class { _serviceCollection.TryAddSingleton(instance); diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs index 913caf1..86ef4aa 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs @@ -11,6 +11,7 @@ public static AzureSearchBuilder RegisterAzureSearch(this IServiceCollection ser .RegisterIndexes() .RegisterSearchers() .RegisterInitializers() - .RegisterWrappers(); + .RegisterWrappers() + .RegisterOperations(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index a70ac44..ecb4477 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -1,4 +1,5 @@ -using Cogworks.AzureSearch.Builder; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; using Cogworks.AzureSearch.Interfaces.Indexes; @@ -11,8 +12,8 @@ using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; +using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; -using Microsoft.Azure.Search.Models; using Umbraco.Core; using Umbraco.Core.Composing; @@ -43,10 +44,13 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials) + public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _composingRegister.Register( - _ => new AzureSearchClientOption(serviceName, credentials), + _ => new AzureSearchClientOption( + serviceName, + credentials, + serviceEndpointUrl), Lifetime.Singleton); return this; @@ -62,7 +66,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(Index customIndex) + public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IAzureModel, new() { _composingRegister.Register( @@ -98,18 +102,6 @@ internal AzureSearchBuilder RegisterRepositories() typeof(IAzureSearchRepository<>), typeof(AzureSearchRepository<>)); - _composingRegister.Register( - typeof(IAzureIndexOperation<>), - typeof(AzureSearchRepository<>)); - - _composingRegister.Register( - typeof(IAzureDocumentOperation<>), - typeof(AzureSearchRepository<>)); - - _composingRegister.Register( - typeof(IAzureDocumentSearch<>), - typeof(AzureSearchRepository<>)); - return this; } @@ -122,9 +114,23 @@ internal AzureSearchBuilder RegisterSearchers() return this; } + + internal AzureSearchBuilder RegisterOperations() + { + _composingRegister.Register( + typeof(IAzureDocumentOperation<>), + typeof(AzureDocumentOperationService<>)); + + _composingRegister.Register( + typeof(IAzureIndexOperation<>), + typeof(AzureIndexOperationService<>)); + + return this; + } + public IAzureSearchBuilder RegisterDomainSearcher() where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType + where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { _composingRegister.Register(Lifetime.Singleton); @@ -134,7 +140,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType + where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { _composingRegister.Register(instance); diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj index f94f7ee..4e585b5 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj @@ -4,12 +4,12 @@ Debug AnyCPU - {FC38DB43-401F-4E88-BAF5-A28325E4C461} + {E1317854-28A7-491E-97B1-FBEEEF7B5982} Library Properties Cogworks.AzureSearch.Umbraco.IocExtension Cogworks.AzureSearch.Umbraco.IocExtension - v4.8 + v4.7.2 512 true @@ -33,6 +33,12 @@ 4 + + ..\..\packages\Azure.Core.1.9.0\lib\net461\Azure.Core.dll + + + ..\..\packages\Azure.Search.Documents.11.2.0\lib\netstandard2.0\Azure.Search.Documents.dll + ..\..\packages\LightInject.5.4.0\lib\net46\LightInject.dll @@ -45,11 +51,8 @@ ..\..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll - - ..\..\packages\Microsoft.Azure.Search.Common.10.1.0\lib\net461\Microsoft.Azure.Search.Common.dll - - - ..\..\packages\Microsoft.Azure.Search.Service.10.1.0\lib\net461\Microsoft.Azure.Search.Service.dll + + ..\..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll ..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll @@ -57,15 +60,6 @@ ..\..\packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll - - ..\..\packages\Microsoft.Rest.ClientRuntime.2.3.20\lib\net461\Microsoft.Rest.ClientRuntime.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.18\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll - - - ..\..\packages\Microsoft.Spatial.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll - ..\..\packages\MiniProfiler.4.0.138\lib\net461\MiniProfiler.dll @@ -118,6 +112,9 @@ ..\..\packages\Superpower.2.0.0\lib\net45\Superpower.dll + + ..\..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll + @@ -128,20 +125,43 @@ ..\..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.Entity.dll - - ..\..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\..\packages\System.Diagnostics.DiagnosticSource.4.6.0\lib\net46\System.Diagnostics.DiagnosticSource.dll - + + ..\..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + + + ..\..\packages\System.Memory.Data.1.0.1\lib\net461\System.Memory.Data.dll + ..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll - + + + ..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + + ..\..\packages\System.Text.Encodings.Web.4.6.0\lib\netstandard2.0\System.Text.Encodings.Web.dll + + + ..\..\packages\System.Text.Json.4.6.0\lib\net461\System.Text.Json.dll + + + ..\..\packages\System.Threading.Channels.4.6.0\lib\netstandard2.0\System.Threading.Channels.dll + + + ..\..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + ..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -163,21 +183,21 @@ - - - - - {4c606328-9108-4584-8e4a-04450b9a1170} Cogworks.AzureSearch.LightInject.IocExtension - {64b55c63-5070-430f-a92d-747ff2cd57a6} + {94f77e26-4e02-4ed5-bd54-45e3aaa70090} Cogworks.AzureSearch + + + + + diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs index bd9acf3..05c7642 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs @@ -16,6 +16,7 @@ public static IAzureSearchBuilder RegisterAzureSearch(this IRegister composingRe .RegisterIndexes() .RegisterSearchers() .RegisterInitializers() - .RegisterWrappers(); + .RegisterWrappers() + .RegisterOperations(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs index 8f94a8d..d6649f4 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Cogworks.AzureSearch.Umbraco.IocExtension")] -[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -20,7 +20,7 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("fc38db43-401f-4e88-baf5-a28325e4c461")] +[assembly: Guid("e1317854-28a7-491e-97b1-fbeeef7b5982")] // Version information for an assembly consists of the following four values: // diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/app.config b/src/Cogworks.AzureSearch.Umbraco.IocExtension/app.config index e936cc1..1eb6c7e 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/app.config +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/app.config @@ -6,6 +6,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/packages.config b/src/Cogworks.AzureSearch.Umbraco.IocExtension/packages.config index d935827..5f0eb16 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/packages.config +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/packages.config @@ -1,36 +1,43 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs b/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs index 1319536..9644b12 100644 --- a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs @@ -1,6 +1,7 @@ -using Cogworks.AzureSearch.Interfaces.Searches; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search.Models; +using Cogworks.AzureSearch.Searchers; namespace Cogworks.AzureSearch.Builder { @@ -8,22 +9,22 @@ public interface IAzureSearchBuilder { IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false); - IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials); + IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl); IAzureSearchBuilder RegisterIndexDefinitions(string indexName) where TDocument : class, IAzureModel, new(); - IAzureSearchBuilder RegisterIndexDefinitions(Index customIndex) + IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IAzureModel, new(); IAzureSearchBuilder RegisterDomainSearcher() where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType + where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class; IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) where TDocument : class, IAzureModel, new() - where TSearcher : class, IAzureSearch, TSearcherType + where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class; } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Cogworks.AzureSearch.csproj b/src/Cogworks.AzureSearch/Cogworks.AzureSearch.csproj index 7c46776..db3f70d 100644 --- a/src/Cogworks.AzureSearch/Cogworks.AzureSearch.csproj +++ b/src/Cogworks.AzureSearch/Cogworks.AzureSearch.csproj @@ -9,11 +9,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + - + @@ -21,7 +20,7 @@ - + @@ -29,4 +28,5 @@ - \ No newline at end of file + + diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs b/src/Cogworks.AzureSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs similarity index 85% rename from Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs rename to src/Cogworks.AzureSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs index 406a151..b2df78a 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/DocumentsExceptions/AddOrUpdateDocumentException.cs @@ -1,6 +1,6 @@ using System; -namespace Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions +namespace Cogworks.AzureSearch.Exceptions.DocumentsExceptions { public class AddOrUpdateDocumentException : DomainException { diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs b/src/Cogworks.AzureSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs similarity index 84% rename from Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs rename to src/Cogworks.AzureSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs index ca7053e..b8436d0 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/DocumentsExceptions/RemoveDocumentException.cs @@ -1,6 +1,6 @@ using System; -namespace Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions +namespace Cogworks.AzureSearch.Exceptions.DocumentsExceptions { public class RemoveDocumentException : DomainException { diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/DomainException.cs b/src/Cogworks.AzureSearch/Exceptions/DomainException.cs similarity index 88% rename from Cogworks.AzureCognitiveSearch/Exceptions/DomainException.cs rename to src/Cogworks.AzureSearch/Exceptions/DomainException.cs index a95f0b6..2ad6010 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/DomainException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/DomainException.cs @@ -1,7 +1,7 @@ using System; using System.Collections; -namespace Cogworks.AzureCognitiveSearch.Exceptions +namespace Cogworks.AzureSearch.Exceptions { public abstract class DomainException : Exception { diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexClearException.cs b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexClearException.cs similarity index 84% rename from Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexClearException.cs rename to src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexClearException.cs index b7f24ab..6da901d 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexClearException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexClearException.cs @@ -1,6 +1,6 @@ using System; -namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +namespace Cogworks.AzureSearch.Exceptions.IndexExceptions { public class IndexClearException : DomainException { diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs similarity index 85% rename from Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs rename to src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs index 4042284..34206ef 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexCreateOrUpdateException.cs @@ -1,6 +1,6 @@ using System; -namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +namespace Cogworks.AzureSearch.Exceptions.IndexExceptions { public class IndexCreateOrUpdateException :DomainException { diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexDeleteException.cs b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexDeleteException.cs similarity index 84% rename from Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexDeleteException.cs rename to src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexDeleteException.cs index 7884c66..12fd6f3 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexDeleteException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexDeleteException.cs @@ -1,6 +1,6 @@ using System; -namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +namespace Cogworks.AzureSearch.Exceptions.IndexExceptions { public class IndexDeleteException : DomainException { diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexExistsException.cs b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexExistsException.cs similarity index 84% rename from Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexExistsException.cs rename to src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexExistsException.cs index 8faf434..cdad8db 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexExistsException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexExistsException.cs @@ -1,6 +1,6 @@ using System; -namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +namespace Cogworks.AzureSearch.Exceptions.IndexExceptions { public class IndexExistsException : DomainException { diff --git a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexInitializerException.cs b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexInitializerException.cs similarity index 85% rename from Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexInitializerException.cs rename to src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexInitializerException.cs index 2b44ae6..2229de2 100644 --- a/Cogworks.AzureCognitiveSearch/Exceptions/IndexExceptions/IndexInitializerException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexInitializerException.cs @@ -1,6 +1,6 @@ using System; -namespace Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions +namespace Cogworks.AzureSearch.Exceptions.IndexExceptions { public class IndexInitializerException : DomainException { diff --git a/src/Cogworks.AzureSearch/Indexes/AzureIndex.cs b/src/Cogworks.AzureSearch/Indexes/AzureIndex.cs index 1256ce4..f62aad0 100644 --- a/src/Cogworks.AzureSearch/Indexes/AzureIndex.cs +++ b/src/Cogworks.AzureSearch/Indexes/AzureIndex.cs @@ -9,21 +9,21 @@ namespace Cogworks.AzureSearch.Indexes { internal class AzureIndex : IAzureIndex where TAzureModel : class, IAzureModel, new() { - private readonly IAzureDocumentOperation _azureSearchRepository; + private readonly IAzureDocumentOperation _documentOperation; - public AzureIndex(IAzureDocumentOperation azureSearchRepository) - => _azureSearchRepository = azureSearchRepository; + public AzureIndex(IAzureDocumentOperation documentOperation) + => _documentOperation = documentOperation; public async Task AddOrUpdateDocumentAsync(TAzureModel model) - => await _azureSearchRepository.AddOrUpdateDocumentAsync(model); + => await _documentOperation.AddOrUpdateDocumentAsync(model); public async Task TryRemoveDocumentAsync(TAzureModel model) - => await _azureSearchRepository.TryRemoveDocumentAsync(model); + => await _documentOperation.TryRemoveDocumentAsync(model); public async Task AddOrUpdateDocumentsAsync(IEnumerable models) - => await _azureSearchRepository.AddOrUpdateDocumentsAsync(models); + => await _documentOperation.AddOrUpdateDocumentsAsync(models); public async Task TryRemoveDocumentsAsync(IEnumerable models) - => await _azureSearchRepository.TryRemoveDocumentsAsync(models); + => await _documentOperation.TryRemoveDocumentsAsync(models); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs b/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs index a77c6aa..6267215 100644 --- a/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs +++ b/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs @@ -1,10 +1,11 @@ -using Cogworks.AzureSearch.Interfaces.Initializers; +using System; +using System.Threading.Tasks; +using Cogworks.AzureSearch.Exceptions.IndexExceptions; +using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Models.Dtos; using Cogworks.AzureSearch.Options; -using System; -using System.Threading.Tasks; namespace Cogworks.AzureSearch.Initializers { @@ -20,7 +21,7 @@ public AzureInitializer(AzureSearchIndexOption azureSearchIndexOption, IAzureInd _azureIndexOperation = azureIndexOperation; } - public async Task InitializeAsync() + public async Task InitializeAsync() { if (_azureSearchIndexOption.Recreate) { @@ -29,7 +30,7 @@ public async Task InitializeAsync() try { - return await _azureIndexOperation.IndexCreateOrUpdateAsync(); + await _azureIndexOperation.IndexCreateOrUpdateAsync(); } catch (Exception) { @@ -39,7 +40,14 @@ public async Task InitializeAsync() } } - return await _azureIndexOperation.IndexCreateOrUpdateAsync(); + try + { + await _azureIndexOperation.IndexCreateOrUpdateAsync(); + } + catch (Exception exception) + { + throw new IndexInitializerException(exception.Message, exception.InnerException); + } } } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Indexes/IAzureIndex.cs b/src/Cogworks.AzureSearch/Interfaces/Indexes/IAzureIndex.cs index 713fdd4..3fc1a52 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Indexes/IAzureIndex.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Indexes/IAzureIndex.cs @@ -1,7 +1,8 @@ -using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Models.Dtos; + using System.Collections.Generic; using System.Threading.Tasks; +using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Models.Dtos; namespace Cogworks.AzureSearch.Interfaces.Indexes { diff --git a/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs b/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs index bc728f0..a4cb608 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs @@ -6,6 +6,6 @@ namespace Cogworks.AzureSearch.Interfaces.Initializers { public interface IAzureInitializer where TAzureModel : class, IAzureModel, new() { - Task InitializeAsync(); + Task InitializeAsync(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureDocumentOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureDocumentOperation.cs index 3d8ab88..001b608 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureDocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureDocumentOperation.cs @@ -1,7 +1,7 @@ -using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Models.Dtos; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; +using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Models.Dtos; namespace Cogworks.AzureSearch.Interfaces.Operations { diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs index 6e31944..5a2095f 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs @@ -8,10 +8,10 @@ namespace Cogworks.AzureSearch.Interfaces.Operations { Task IndexExistsAsync(); - Task IndexDeleteAsync(); + Task IndexDeleteAsync(); - Task IndexCreateOrUpdateAsync(); + Task IndexCreateOrUpdateAsync(); - Task IndexClearAsync(); + Task IndexClearAsync(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Repositories/IAzureSearchRepository.cs b/src/Cogworks.AzureSearch/Interfaces/Repositories/IAzureSearchRepository.cs index 0d902e5..0c2242e 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Repositories/IAzureSearchRepository.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Repositories/IAzureSearchRepository.cs @@ -7,7 +7,7 @@ namespace Cogworks.AzureSearch.Interfaces.Repositories public interface IAzureSearchRepository : IAzureDocumentOperation, IAzureIndexOperation, - IAzureDocumentSearch + IAzureSearch where TAzureModel : class, IAzureModel, new() { } diff --git a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureDocumentSearch.cs b/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureDocumentSearch.cs deleted file mode 100644 index b7d94a6..0000000 --- a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureDocumentSearch.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Cogworks.AzureSearch.Models; -using System.Threading.Tasks; - -namespace Cogworks.AzureSearch.Interfaces.Searches -{ - public interface IAzureDocumentSearch where TAzureModel : class, IAzureModel, new() - { - Models.Dtos.SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters); - - Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters); - } -} \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs b/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs index 35f6955..0af5302 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs @@ -1,6 +1,6 @@ -using Cogworks.AzureSearch.Models; +using System.Threading.Tasks; +using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Models.Dtos; -using System.Threading.Tasks; namespace Cogworks.AzureSearch.Interfaces.Searches { diff --git a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs index 773116b..f72c2e2 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs @@ -1,15 +1,17 @@ -using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search.Models; -using System.Threading.Tasks; +using System.Threading.Tasks; +using Azure; +using Azure.Search.Documents; +using Azure.Search.Documents.Models; +using Cogworks.AzureSearch.Models; namespace Cogworks.AzureSearch.Interfaces.Wrappers { public interface IDocumentOperationWrapper where TAzureModel : class, IAzureModel, new() { - DocumentSearchResult Search(string searchText, SearchParameters parameters = null); + SearchResults Search(string searchText, SearchOptions parameters = null); - Task> SearchAsync(string searchText, SearchParameters parameters = null); + Task> SearchAsync(string searchText, SearchOptions parameters = null); - Task IndexAsync(IndexBatch indexBatch); + Task> IndexAsync(IndexDocumentsBatch indexBatch); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs index b477e66..545ffcf 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs @@ -1,8 +1,6 @@ -using System.Collections; -using System.Collections.Generic; +using System.Threading.Tasks; +using Azure.Search.Documents.Indexes.Models; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search.Models; -using System.Threading.Tasks; namespace Cogworks.AzureSearch.Interfaces.Wrappers { @@ -12,8 +10,8 @@ public interface IIndexOperationWrapper Task DeleteAsync(string indexName); - Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new(); + Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new(); - Task CreateOrUpdateAsync(Index customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new(); + Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new(); } } \ No newline at end of file diff --git a/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs b/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs similarity index 93% rename from Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs rename to src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs index b94f76a..9ac36c5 100644 --- a/Cogworks.AzureCognitiveSearch/Mappers/AzureSearchParametersMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs @@ -1,11 +1,11 @@ using System.Linq; using Azure.Search.Documents; using Azure.Search.Documents.Models; -using Cogworks.AzureCognitiveSearch.Enums; -using Cogworks.AzureCognitiveSearch.Extensions; -using Cogworks.AzureCognitiveSearch.Models; +using Cogworks.AzureSearch.Enums; +using Cogworks.AzureSearch.Extensions; +using Cogworks.AzureSearch.Models; -namespace Cogworks.AzureCognitiveSearch.Mappers +namespace Cogworks.AzureSearch.Mappers { public static class AzureSearchParametersMapper { diff --git a/Cogworks.AzureCognitiveSearch/Mappers/SearchResultMapper.cs b/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs similarity index 87% rename from Cogworks.AzureCognitiveSearch/Mappers/SearchResultMapper.cs rename to src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs index f555192..898721f 100644 --- a/Cogworks.AzureCognitiveSearch/Mappers/SearchResultMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs @@ -1,8 +1,8 @@ using System.Linq; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; +using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Models.Dtos; -namespace Cogworks.AzureCognitiveSearch.Mappers +namespace Cogworks.AzureSearch.Mappers { public static class SearchResultMapper { diff --git a/src/Cogworks.AzureSearch/Models/AzureIndexDefinition.cs b/src/Cogworks.AzureSearch/Models/AzureIndexDefinition.cs index 72026d3..f130ef4 100644 --- a/src/Cogworks.AzureSearch/Models/AzureIndexDefinition.cs +++ b/src/Cogworks.AzureSearch/Models/AzureIndexDefinition.cs @@ -1,5 +1,4 @@ -using System.Runtime.CompilerServices; -using Microsoft.Azure.Search.Models; +using Azure.Search.Documents.Indexes.Models; namespace Cogworks.AzureSearch.Models { @@ -7,12 +6,12 @@ namespace Cogworks.AzureSearch.Models { public string IndexName { get; } - public Index CustomIndexDefinition { get; } + public SearchIndex CustomIndexDefinition { get; } public AzureIndexDefinition(string indexName) => IndexName = indexName; - public AzureIndexDefinition(Index customIndex) + public AzureIndexDefinition(SearchIndex customIndex) => (CustomIndexDefinition, IndexName) = (customIndex, customIndex.Name); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Models/AzureSearchParameters.cs b/src/Cogworks.AzureSearch/Models/AzureSearchParameters.cs index 8bef2ab..9e9e0d6 100644 --- a/src/Cogworks.AzureSearch/Models/AzureSearchParameters.cs +++ b/src/Cogworks.AzureSearch/Models/AzureSearchParameters.cs @@ -1,5 +1,5 @@ -using Cogworks.AzureSearch.Enums; -using System.Collections.Generic; +using System.Collections.Generic; +using Cogworks.AzureSearch.Enums; namespace Cogworks.AzureSearch.Models { @@ -7,11 +7,11 @@ public class AzureSearchParameters { public bool IncludeTotalResultCount { get; set; } - public IList Facets { get; set; } + public IEnumerable Facets { get; set; } public string Filter { get; set; } - public IList HighlightFields { get; set; } + public IEnumerable HighlightFields { get; set; } public string HighlightPostTag { get; set; } @@ -19,17 +19,17 @@ public class AzureSearchParameters public double? MinimumCoverage { get; set; } - public IList OrderBy { get; set; } + public IEnumerable OrderBy { get; set; } public AzureQueryType QueryType { get; set; } public string ScoringProfile { get; set; } - public IList SearchFields { get; set; } + public IEnumerable SearchFields { get; set; } public AzureSearchModeType SearchMode { get; set; } - public IList Select { get; set; } + public IEnumerable Select { get; set; } public int Skip { get; set; } diff --git a/src/Cogworks.AzureSearch/Models/Dtos/AzureDocumentOperationResult.cs b/src/Cogworks.AzureSearch/Models/Dtos/AzureDocumentOperationResult.cs index 43d8c04..ed82355 100644 --- a/src/Cogworks.AzureSearch/Models/Dtos/AzureDocumentOperationResult.cs +++ b/src/Cogworks.AzureSearch/Models/Dtos/AzureDocumentOperationResult.cs @@ -8,6 +8,8 @@ public class AzureDocumentOperationResult public string Message { get; set; } + public string InnerMessage { get; set; } + public int StatusCode { get; set; } } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs b/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs index 044bc0d..6c6bd91 100644 --- a/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs +++ b/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs @@ -1,4 +1,6 @@ -using Microsoft.Azure.Search; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Search.Documents; namespace Cogworks.AzureSearch.Options { @@ -8,15 +10,39 @@ public class AzureSearchClientOption public string Credentials { get; } - public AzureSearchClientOption(string serviceName, string credentials) + public string ServiceUrlEndpoint { get; } + + public SearchClientOptions ClientOptions { get; } + + + + public AzureSearchClientOption(string serviceName, string credentials, string serviceUrlEndpoint) { ServiceName = serviceName; Credentials = credentials; + ServiceUrlEndpoint = serviceUrlEndpoint; + ClientOptions = GetOptions(); } - public SearchServiceClient GetSearchServiceClient() - => new SearchServiceClient( - ServiceName, - new SearchCredentials(Credentials)); - } + + private static SearchClientOptions GetOptions() + { + var clientOptions = new SearchClientOptions(); + + + clientOptions.AddPolicy( + new SearchIdPipelinePolicy(), + HttpPipelinePosition.PerCall); + + return clientOptions; + } + + private class SearchIdPipelinePolicy : HttpPipelineSynchronousPolicy + { + public override void OnSendingRequest(HttpMessage message) + => message.Request + .Headers + .SetValue("x-ms-azs-return-searchid", "true"); + } +} } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Repositories/AzureSearchRepository.cs b/src/Cogworks.AzureSearch/Repositories/AzureSearchRepository.cs index b790963..a3e83c9 100644 --- a/src/Cogworks.AzureSearch/Repositories/AzureSearchRepository.cs +++ b/src/Cogworks.AzureSearch/Repositories/AzureSearchRepository.cs @@ -1,303 +1,59 @@ -using Cogworks.AzureSearch.Extensions; +using System.Collections.Generic; +using System.Threading.Tasks; +using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Interfaces.Repositories; -using Cogworks.AzureSearch.Interfaces.Wrappers; +using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Models.Dtos; -using Microsoft.Azure.Search; -using Microsoft.Azure.Search.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Cogworks.AzureSearch.Repositories { internal class AzureSearchRepository : IAzureSearchRepository where TAzureModel : class, IAzureModel, new() { - private readonly AzureIndexDefinition _azureIndexDefinition; - private readonly IIndexOperationWrapper _indexOperationWrapper; - private readonly IDocumentOperationWrapper _documentOperationWrapper; - - private const int BatchOperationSize = 500; + private readonly IAzureIndexOperation _indexOperation; + private readonly IAzureDocumentOperation _documentOperation; + private readonly IAzureSearch _search; public AzureSearchRepository( - AzureIndexDefinition azureIndexDefinition, - IIndexOperationWrapper indexOperationWrapper, - IDocumentOperationWrapper documentOperationWrapper) + IAzureIndexOperation indexOperation, + IAzureDocumentOperation documentOperation, + IAzureSearch search) { - _azureIndexDefinition = azureIndexDefinition; - _indexOperationWrapper = indexOperationWrapper; - _documentOperationWrapper = documentOperationWrapper; - } - - public async Task IndexExistsAsync() - => await _indexOperationWrapper.ExistsAsync(_azureIndexDefinition.IndexName); - - public async Task IndexDeleteAsync() - { - var result = new AzureIndexOperationResult(); - - try - { - await _indexOperationWrapper.DeleteAsync(_azureIndexDefinition.IndexName); - - result.Succeeded = true; - result.Message = $"Index {_azureIndexDefinition.IndexName} successfully deleted."; - } - catch (Exception e) - { - result.Message = $"An issue occurred on deleting index: {_azureIndexDefinition.IndexName}. More information: {e.Message}"; - } - - return result; - } - - // TODO: add throwing domain exception on exception instead of returning dto - public async Task IndexCreateOrUpdateAsync() - { - var result = new AzureIndexOperationResult(); - - try - { - - var createdIndex = _azureIndexDefinition.CustomIndexDefinition != null - ? await _indexOperationWrapper.CreateOrUpdateAsync(_azureIndexDefinition.CustomIndexDefinition, true) - : await _indexOperationWrapper.CreateOrUpdateAsync(_azureIndexDefinition.IndexName) ; - - result.Message = $"Index {_azureIndexDefinition.IndexName} successfully created or updated."; - result.Succeeded = true; - } - catch (Exception exception) - { - result.Message = $"An issue occurred on creating or updating index: {_azureIndexDefinition.IndexName}. More information: {exception.Message}"; - } - - return result; - } - - public async Task IndexClearAsync() - { - try - { - if (await IndexExistsAsync()) - { - var deleteOperationResult = await IndexDeleteAsync(); - - if (!deleteOperationResult.Succeeded) - { - return new AzureIndexOperationResult - { - Succeeded = false, - Message = $"An issue occurred on clearing index: {_azureIndexDefinition.IndexName}. Could not delete existing index." - }; - } - } - } - catch (Exception) - { - // ignore - } - - var indexCreateOrUpdateResult = await IndexCreateOrUpdateAsync(); - - return new AzureIndexOperationResult - { - Succeeded = indexCreateOrUpdateResult.Succeeded, - Message = indexCreateOrUpdateResult.Succeeded - ? $"Index {_azureIndexDefinition.IndexName} successfully cleared." - : $"An issue occurred on clearing index: {_azureIndexDefinition.IndexName}. Could not create index." - }; + _indexOperation = indexOperation; + _documentOperation = documentOperation; + _search = search; } public async Task AddOrUpdateDocumentAsync(TAzureModel model) - { - var azureBatchDocumentsOperationResult = await AddOrUpdateDocumentsAsync(new[] { model }); - - return azureBatchDocumentsOperationResult.Succeeded - ? azureBatchDocumentsOperationResult.SucceededDocuments.FirstOrDefault() - : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); - } + => await _documentOperation.AddOrUpdateDocumentAsync(model); public async Task AddOrUpdateDocumentsAsync(IEnumerable models) - { - if (!models.HasAny()) - { - return new AzureBatchDocumentsOperationResult() - { - Succeeded = true, - Message = "No documents found to index." - }; - } - - var chunkedBatchActions = models - .Select(model => new IndexAction(model, IndexActionType.Upload)) - .ChunkBy(BatchOperationSize) - .ToList(); - - var indexResults = new List(); - - foreach (var batchActions in chunkedBatchActions) - { - var batch = IndexBatch.New(batchActions); - - try - { - var result = await _documentOperationWrapper.IndexAsync(batch); - indexResults.AddRange(result.Results); - } - catch (IndexBatchException indexBatchException) - { - indexResults.AddRange(indexBatchException.IndexingResults); - } - catch (Exception exception) - { - // todo: handle it proper - } - } - - return GetBatchOperationStatus(indexResults, "adding or updating"); - } + => await _documentOperation.AddOrUpdateDocumentsAsync(models); public async Task TryRemoveDocumentAsync(TAzureModel model) - { - var azureBatchDocumentsOperationResult = await TryRemoveDocumentsAsync(new[] { model }); - - return azureBatchDocumentsOperationResult.Succeeded - ? azureBatchDocumentsOperationResult.SucceededDocuments.FirstOrDefault() - : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); - } + => await _documentOperation.TryRemoveDocumentAsync(model); public async Task TryRemoveDocumentsAsync(IEnumerable models) - { - if (!models.HasAny()) - { - return new AzureBatchDocumentsOperationResult() - { - Succeeded = true, - Message = "No documents found to delete." - }; - } - - var chunkedBatchActions = models - .Select(model => new IndexAction(model, IndexActionType.Delete)) - .ChunkBy(BatchOperationSize) - .ToList(); + => await _documentOperation.TryRemoveDocumentsAsync(models); - var indexResults = new List(); + public async Task IndexExistsAsync() + => await _indexOperation.IndexExistsAsync(); - foreach (var batchActions in chunkedBatchActions) - { - var batch = IndexBatch.New(batchActions); + public async Task IndexDeleteAsync() + => await _indexOperation.IndexDeleteAsync(); - try - { - var result = await _documentOperationWrapper.IndexAsync(batch); - indexResults.AddRange(result.Results); - } - catch (IndexBatchException indexBatchException) - { - indexResults.AddRange(indexBatchException.IndexingResults); - } - catch (Exception exception) - { - // todo: handle it proper - } - } + public async Task IndexCreateOrUpdateAsync() + => await _indexOperation.IndexCreateOrUpdateAsync(); - return GetBatchOperationStatus(indexResults, "removing"); - } + public async Task IndexClearAsync() + => await _indexOperation.IndexClearAsync(); - public Models.Dtos.SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) - { - var searchText = GetSearchText(keyword); - var parameters = GetSearchParameters(azureSearchParameters); - var results = _documentOperationWrapper.Search($"{searchText}", parameters); - - return GetSearchResult(results, azureSearchParameters.Skip, azureSearchParameters.Take); - } + public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) + => _search.Search(keyword, azureSearchParameters); - public async Task> SearchAsync(string keyword, + public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) - { - var searchText = GetSearchText(keyword); - var parameters = GetSearchParameters(azureSearchParameters); - var results = await _documentOperationWrapper.SearchAsync($"{searchText}", parameters); - - return GetSearchResult(results, azureSearchParameters.Skip, azureSearchParameters.Take); - } - - private static string GetSearchText(string keyword) - => keyword.EscapeHyphen().HasValue() - ? keyword.EscapeHyphen() - : "*"; - - private static SearchParameters GetSearchParameters(AzureSearchParameters azureSearchParameters) - => new SearchParameters - { - Facets = azureSearchParameters.Facets, - Filter = azureSearchParameters.Filter, - HighlightFields = azureSearchParameters.HighlightFields, - HighlightPostTag = azureSearchParameters.HighlightPostTag, - HighlightPreTag = azureSearchParameters.HighlightPreTag, - IncludeTotalResultCount = azureSearchParameters.IncludeTotalResultCount, - MinimumCoverage = azureSearchParameters.MinimumCoverage, - OrderBy = azureSearchParameters.OrderBy, - QueryType = azureSearchParameters.QueryType == Enums.AzureQueryType.Full - ? QueryType.Full - : QueryType.Simple, - ScoringProfile = azureSearchParameters.ScoringProfile, - SearchFields = azureSearchParameters.SearchFields, - SearchMode = azureSearchParameters.SearchMode == Enums.AzureSearchModeType.Any - ? SearchMode.Any - : SearchMode.All, - Select = azureSearchParameters.Select, - Skip = azureSearchParameters.Skip, - Top = azureSearchParameters.Take - }; - - private Models.Dtos.SearchResult GetSearchResult(DocumentSearchResult results, int skip, int take) - { - var resultsCount = results.Count ?? 0; - - var searchedDocuments = results.Results - .Select(resultDocument => new SearchResultItem( - resultDocument.Document, - resultDocument.Highlights, - resultDocument.Score - )) - .ToArray(); - - return new Models.Dtos.SearchResult() - { - HasMoreItems = skip + take < resultsCount, - TotalCount = resultsCount, - Results = searchedDocuments - }; - } - - private AzureBatchDocumentsOperationResult GetBatchOperationStatus(IEnumerable indexingResults, string operationType) - { - var successfullyItems = indexingResults.Where(x => x.Succeeded).ToList(); - var failedItems = indexingResults.Where(x => !x.Succeeded).ToList(); - - return new AzureBatchDocumentsOperationResult - { - Succeeded = !failedItems.Any(), - SucceededDocuments = successfullyItems.Select(successfullyItem => new AzureDocumentOperationResult - { - Succeeded = true, - Message = $"Successfully {operationType} document.", - ModelId = successfullyItem.Key, - StatusCode = successfullyItem.StatusCode - }).ToList(), - FailedDocuments = failedItems.Select(failedItem => new AzureDocumentOperationResult - { - Message = $"Failed {operationType} document.", - ModelId = failedItem.Key, - StatusCode = failedItem.StatusCode - }).ToList(), - }; - } + => await _search.SearchAsync(keyword, azureSearchParameters); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs index fb16f7c..9c499c6 100644 --- a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs @@ -1,22 +1,49 @@ -using Cogworks.AzureSearch.Interfaces.Searches; +using System.Linq; +using System.Threading.Tasks; +using Cogworks.AzureSearch.Extensions; +using Cogworks.AzureSearch.Interfaces.Searches; +using Cogworks.AzureSearch.Interfaces.Wrappers; +using Cogworks.AzureSearch.Mappers; using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Models.Dtos; -using System.Threading.Tasks; namespace Cogworks.AzureSearch.Searchers { - public class AzureSearch : IAzureSearch + internal class AzureSearch : IAzureSearch where TAzureModel : class, IAzureModel, new() { - private readonly IAzureDocumentSearch _azureSearchRepository; + private readonly IDocumentOperationWrapper _documentOperationWrapper; - public AzureSearch(IAzureDocumentSearch azureSearchRepository) - => _azureSearchRepository = azureSearchRepository; + public AzureSearch(IDocumentOperationWrapper documentOperationWrapper) + => _documentOperationWrapper = documentOperationWrapper; public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) - => _azureSearchRepository.Search(keyword, azureSearchParameters); + { + var searchText = GetSearchText(keyword); + var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); + var results = _documentOperationWrapper.Search($"{searchText}", parameters); + + return SearchResultMapper.Map( + results, + azureSearchParameters.Skip, + azureSearchParameters.Take); + } public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) - => await _azureSearchRepository.SearchAsync(keyword, azureSearchParameters); + { + var searchText = GetSearchText(keyword); + var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); + var results = await _documentOperationWrapper.SearchAsync(searchText, parameters); + + return SearchResultMapper.Map( + results, + azureSearchParameters.Skip, + azureSearchParameters.Take); + } + + private static string GetSearchText(string keyword) + => keyword.EscapeHyphen().HasValue() + ? keyword.EscapeHyphen() + : "*"; } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs new file mode 100644 index 0000000..97edabf --- /dev/null +++ b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs @@ -0,0 +1,22 @@ +using Cogworks.AzureSearch.Interfaces.Searches; +using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Models.Dtos; +using System.Threading.Tasks; + +namespace Cogworks.AzureSearch.Searchers +{ + public abstract class BaseDomainSearch + where TAzureModel : class, IAzureModel, new() + { + protected IAzureSearch Searcher { get; } + + protected BaseDomainSearch(IAzureSearch search) + => Searcher = search; + + public virtual SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) + => Searcher.Search(keyword, azureSearchParameters); + + public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) + => await Searcher.SearchAsync(keyword, azureSearchParameters); + } +} diff --git a/Cogworks.AzureCognitiveSearch/Services/AzureDocumentOperationService.cs b/src/Cogworks.AzureSearch/Services/AzureDocumentOperationService.cs similarity index 93% rename from Cogworks.AzureCognitiveSearch/Services/AzureDocumentOperationService.cs rename to src/Cogworks.AzureSearch/Services/AzureDocumentOperationService.cs index f7774a9..2de212a 100644 --- a/Cogworks.AzureCognitiveSearch/Services/AzureDocumentOperationService.cs +++ b/src/Cogworks.AzureSearch/Services/AzureDocumentOperationService.cs @@ -3,14 +3,14 @@ using System.Linq; using System.Threading.Tasks; using Azure.Search.Documents.Models; -using Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions; -using Cogworks.AzureCognitiveSearch.Extensions; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; - -namespace Cogworks.AzureCognitiveSearch.Services +using Cogworks.AzureSearch.Exceptions.DocumentsExceptions; +using Cogworks.AzureSearch.Extensions; +using Cogworks.AzureSearch.Interfaces.Operations; +using Cogworks.AzureSearch.Interfaces.Wrappers; +using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Models.Dtos; + +namespace Cogworks.AzureSearch.Services { public class AzureDocumentOperationService : IAzureDocumentOperation where TAzureModel : class, IAzureModel, new() diff --git a/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs b/src/Cogworks.AzureSearch/Services/AzureIndexOperationService.cs similarity index 86% rename from Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs rename to src/Cogworks.AzureSearch/Services/AzureIndexOperationService.cs index 087d05f..ab641e5 100644 --- a/Cogworks.AzureCognitiveSearch/Services/AzureIndexOperationService.cs +++ b/src/Cogworks.AzureSearch/Services/AzureIndexOperationService.cs @@ -1,13 +1,13 @@ using System; using System.Threading.Tasks; -using Cogworks.AzureCognitiveSearch.Exceptions; -using Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Models.Dtos; +using Cogworks.AzureSearch.Exceptions; +using Cogworks.AzureSearch.Exceptions.IndexExceptions; +using Cogworks.AzureSearch.Interfaces.Operations; +using Cogworks.AzureSearch.Interfaces.Wrappers; +using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Models.Dtos; -namespace Cogworks.AzureCognitiveSearch.Services +namespace Cogworks.AzureSearch.Services { public class AzureIndexOperationService : IAzureIndexOperation where TAzureModel : class, IAzureModel, new() diff --git a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs index fba1cda..58a4278 100644 --- a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs @@ -1,30 +1,43 @@ -using Cogworks.AzureSearch.Interfaces.Wrappers; + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Search.Documents; +using Azure.Search.Documents.Models; +using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Options; -using Microsoft.Azure.Search; -using Microsoft.Azure.Search.Models; -using System.Threading.Tasks; namespace Cogworks.AzureSearch.Wrappers { internal class DocumentOperationWrapper : IDocumentOperationWrapper where TAzureModel : class, IAzureModel, new() { - private readonly IDocumentsOperations _documentOperation; + private readonly SearchClient _searchClient; + + + public DocumentOperationWrapper( + AzureIndexDefinition azureIndexDefinition, + AzureSearchClientOption azureSearchClientOption) + { + var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); + + _searchClient = new SearchClient( + endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), + indexName: azureIndexDefinition.IndexName, + credential: azureKeyCredential, + options: azureSearchClientOption.ClientOptions - public DocumentOperationWrapper(AzureIndexDefinition azureIndexDefinition, AzureSearchClientOption azureSearchClientOption) - => _documentOperation = azureSearchClientOption.GetSearchServiceClient() - .Indexes - .GetClient(azureIndexDefinition.IndexName) - .Documents; + ); + } - public DocumentSearchResult Search(string searchText, SearchParameters parameters = null) - => _documentOperation.Search(searchText, parameters); + public SearchResults Search(string searchText, SearchOptions parameters = null) + => _searchClient.Search(searchText, parameters); - public async Task> SearchAsync(string searchText, SearchParameters parameters = null) - => await _documentOperation.SearchAsync(searchText, parameters); + public async Task> SearchAsync(string searchText, SearchOptions parameters = null) + => await _searchClient.SearchAsync(searchText, parameters); - public async Task IndexAsync(IndexBatch indexBatch) - => await _documentOperation.IndexAsync(indexBatch); + public async Task> IndexAsync(IndexDocumentsBatch indexBatch) + => await _searchClient.IndexDocumentsAsync(indexBatch); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs index a30e497..7e10169 100644 --- a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs @@ -1,48 +1,56 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Search.Documents.Indexes; +using Azure.Search.Documents.Indexes.Models; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Options; -using Microsoft.Azure.Search; -using Microsoft.Azure.Search.Models; -using System.Threading.Tasks; namespace Cogworks.AzureSearch.Wrappers { internal class IndexOperationWrapper : IIndexOperationWrapper { - private readonly IIndexesOperations _indexOperation; + private readonly SearchIndexClient _searchIndexClient; public IndexOperationWrapper(AzureSearchClientOption azureSearchClientOption) - => _indexOperation = azureSearchClientOption.GetSearchServiceClient().Indexes; + { + var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); + + _searchIndexClient = new SearchIndexClient( + endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), + credential: azureKeyCredential); + } public async Task ExistsAsync(string indexName) - => await _indexOperation.ExistsAsync(indexName); + => (await _searchIndexClient.GetIndexAsync(indexName)).Value != null; public async Task DeleteAsync(string indexName) - => await _indexOperation.DeleteAsync(indexName); + => await _searchIndexClient.DeleteIndexAsync(indexName); - public async Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new() + public async Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new() { - var indexDefinition = new Index - { - Name = indexName, - Fields = FieldBuilder.BuildForType(), + var fieldBuilder = new FieldBuilder(); + var searchFields = fieldBuilder.Build(typeof(TAzureModel)); - }; + var definition = new SearchIndex( + indexName, + searchFields); - return await _indexOperation.CreateOrUpdateAsync(indexDefinition); + return await _searchIndexClient.CreateOrUpdateIndexAsync(definition); } - public async Task CreateOrUpdateAsync(Index customIndexDefinition, bool overrideFields = true) where TAzureModel : class, IAzureModel, new() + public async Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new() { if (overrideFields) { - customIndexDefinition.Fields = FieldBuilder.BuildForType(); + var fieldBuilder = new FieldBuilder(); + var searchFields = fieldBuilder.Build(typeof(TAzureModel)); + + customIndexDefinition.Fields = searchFields; } - return await _indexOperation.CreateOrUpdateAsync(customIndexDefinition); + return await _searchIndexClient.CreateOrUpdateIndexAsync(customIndexDefinition); } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj deleted file mode 100644 index fd9584e..0000000 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Cogworks.AzureCognitiveSearch.UnitTests.csproj +++ /dev/null @@ -1,51 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs deleted file mode 100644 index 9c7ff0d..0000000 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestDocumentModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Azure.Search.Documents.Indexes; -using Cogworks.AzureCognitiveSearch.Models; - -namespace Cogworks.AzureCognitiveSearch.UnitTests.Models -{ - public class TestDocumentModel : IAzureModel - { - [SimpleField(IsKey = true, IsFilterable = true)] - [SearchableField()] - public string Id { get; set; } - - [SimpleField(IsFilterable = true)] - [SearchableField()] - - public string Name { get; set; } - } -} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs deleted file mode 100644 index 3cf67fa..0000000 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/DocumentOperationTests.cs +++ /dev/null @@ -1,365 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using AutoFixture; -using Azure.Search.Documents.Models; -using Cogworks.AzureCognitiveSearch.Exceptions.DocumentsExceptions; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Repositories; -using Cogworks.AzureCognitiveSearch.UnitTests.Models; -using NSubstitute; -using NSubstitute.ExceptionExtensions; -using Xunit; - -namespace Cogworks.AzureCognitiveSearch.UnitTests.Operations -{ - public class DocumentOperationTests : TestBase - { - private readonly IAzureDocumentOperation _azureDocumentOperation; - - public DocumentOperationTests() - => _azureDocumentOperation = new AzureSearchRepository( - AzureIndexOperationService, - AzureDocumentOperationService, - Search); - - [Theory] - [InlineData(1)] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_AddOrUpdateDocuments(int documentsCount) - { - // Arrange - var testDocuments = Enumerable.Range(0, documentsCount) - .Select(_ => Fixture.Create()) - .ToArray(); - - - var indexResults = testDocuments - .Select(testDocument => SearchModelFactory.IndexingResult( - key: testDocument.Id, - errorMessage: string.Empty, - succeeded: true, - status: 200)) - .ToList(); - - var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Returns(new TestResponse(documentIndexResult)); - - // Act - var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); - - // Assert - Assert.NotNull(result); - Assert.True(result.Succeeded); - Assert.NotEmpty(result.SucceededDocuments); - Assert.Empty(result.FailedDocuments); - Assert.All( - result.SucceededDocuments, - succeedItem => - { - Assert.True(succeedItem.Succeeded); - Assert.Equal(200, succeedItem.StatusCode); - Assert.Equal("Successfully adding or updating document.", succeedItem.Message); - Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); - }); - } - - [Theory] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_Fail_When_AddOrUpdateDocumentsPartiallyFail(int documentsCount) - { - // Arrange - var testDocuments = Enumerable.Range(0, documentsCount) - .Select(_ => Fixture.Create()) - .ToArray(); - - - var indexResults = testDocuments - .Select((document, index) => new - { - Document = document, - Succeded = index % (documentsCount / 2) == 0 - }) - .Select(item => SearchModelFactory.IndexingResult( - key: item.Document.Id, - errorMessage: !item.Succeded - ? "Internal Unit Error." - : string.Empty, - succeeded: item.Succeded, - status: item.Succeded - ? 200 - : 404)) - .ToList(); - - var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Returns(new TestResponse(documentIndexResult)); - - // Act - var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); - - // Assert - Assert.NotNull(result); - Assert.False(result.Succeeded); - Assert.NotEmpty(result.SucceededDocuments); - Assert.NotEmpty(result.FailedDocuments); - Assert.All( - result.SucceededDocuments, - succeedItem => - { - Assert.True(succeedItem.Succeeded); - Assert.Equal(200, succeedItem.StatusCode); - Assert.Equal("Successfully adding or updating document.", succeedItem.Message); - Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); - }); - - Assert.All( - result.FailedDocuments, - succeedItem => - { - Assert.False(succeedItem.Succeeded); - Assert.Equal(404, succeedItem.StatusCode); - Assert.Equal("Failed adding or updating document.", succeedItem.Message); - Assert.Equal("Internal Unit Error.", succeedItem.InnerMessage); - Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); - }); - } - - [Fact] - public async Task Should_Succeeded_When_TryToAddEmptyDocuments() - { - // Arrange - var testDocuments = Enumerable.Empty(); - - var documentIndexResult = new TestResponse( - SearchModelFactory.IndexDocumentsResult( - Enumerable.Empty())); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Returns(documentIndexResult); - - // Act - var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); - - // Assert - Assert.NotNull(result); - Assert.True(result.Succeeded); - Assert.Empty(result.SucceededDocuments); - Assert.Empty(result.FailedDocuments); - Assert.Equal("No documents found to index.", result.Message); - } - - [Fact] - public async Task Should_Succeeded_When_TryToRemoveEmptyDocuments() - { - // Arrange - var testDocuments = Enumerable.Empty(); - - var documentIndexResult = new TestResponse( - SearchModelFactory.IndexDocumentsResult( - Enumerable.Empty())); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Returns(documentIndexResult); - - // Act - var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); - - // Assert - Assert.NotNull(result); - Assert.True(result.Succeeded); - Assert.Empty(result.SucceededDocuments); - Assert.Empty(result.FailedDocuments); - Assert.Equal("No documents found to delete.", result.Message); - } - - [Theory] - [InlineData(1)] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_Succeeded_When_TryRemoveDocuments(int documentsCount) - { - // Arrange - var testDocuments = Enumerable.Range(0, documentsCount) - .Select(_ => Fixture.Create()) - .ToArray(); - - var indexResults = testDocuments - .Select(testDocument => SearchModelFactory.IndexingResult( - key: testDocument.Id, - errorMessage: string.Empty, - succeeded: true, - status: 200)) - .ToList(); - - var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Returns(new TestResponse(documentIndexResult)); - - // Act - var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); - - // Assert - Assert.NotNull(result); - Assert.True(result.Succeeded); - Assert.NotEmpty(result.SucceededDocuments); - Assert.Empty(result.FailedDocuments); - Assert.All( - result.SucceededDocuments, - succeedItem => - { - Assert.True(succeedItem.Succeeded); - Assert.Equal(200, succeedItem.StatusCode); - Assert.Equal("Successfully removing document.", succeedItem.Message); - Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); - }); - } - - [Theory] - [InlineData(1)] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_Fail_When_TryRemoveNotExistingDocuments(int documentsCount) - { - // Arrange - var testDocuments = Enumerable.Range(0, documentsCount) - .Select(_ => Fixture.Create()) - .ToArray(); - - var indexResults = testDocuments - .Select(testDocument => SearchModelFactory.IndexingResult( - key: testDocument.Id, - errorMessage: string.Empty, - succeeded: false, - status: 404)) - .ToList(); - - var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Returns(new TestResponse(documentIndexResult)); - - // Act - var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); - - // Assert - Assert.NotNull(result); - Assert.False(result.Succeeded); - Assert.Empty(result.SucceededDocuments); - Assert.NotEmpty(result.FailedDocuments); - Assert.All( - result.FailedDocuments, - failedItem => - { - Assert.False(failedItem.Succeeded); - Assert.Equal(404, failedItem.StatusCode); - Assert.Equal("Failed removing document.", failedItem.Message); - Assert.Contains(testDocuments, item => item.Id == failedItem.ModelId); - }); - } - - [Theory] - [InlineData(1)] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_ThrowDomainException_When_IssueWith_TryAddOrUpdateDocuments(int documentsCount) - { - // Arrange - - var testDocuments = Enumerable.Range(0, documentsCount) - .Select(_ => Fixture.Create()) - .ToArray(); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Throws(_ => new AddOrUpdateDocumentException("Test Error", Fixture.Create())); - - // Assert - var domainException = await Assert.ThrowsAsync(async () => - await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments)); - - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - } - - [Theory] - [InlineData(1)] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_Not_ThrowDomainException_When_No_IssueWith_TryAddOrUpdateDocuments(int documentsCount) - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(true); - - // Act - var domainExceptionResult = await Record.ExceptionAsync(() => Should_AddOrUpdateDocuments(documentsCount)); - - // Assert - Assert.Null(domainExceptionResult); - } - - [Theory] - [InlineData(1)] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_ThrowDomainException_When_IssueWith_TryRemoveDocuments(int documentsCount) - { - // Arrange - - var testDocuments = Enumerable.Range(0, documentsCount) - .Select(_ => Fixture.Create()) - .ToArray(); - - _ = DocumentOperationWrapper - .IndexAsync(Arg.Any>()) - .Throws(_ => new AddOrUpdateDocumentException("Test Error", Fixture.Create())); - - // Assert - var domainException = await Assert.ThrowsAsync(async () => - await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments)); - - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - } - - [Theory] - [InlineData(1)] - [InlineData(100)] - [InlineData(500)] - [InlineData(1000)] - public async Task Should_Not_ThrowDomainException_When_No_IssueWith_TryRemoveDocuments(int documentsCount) - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(true); - - // Act - var domainExceptionResult = await Record.ExceptionAsync(() => Should_Succeeded_When_TryRemoveDocuments(documentsCount)); - - // Assert - Assert.Null(domainExceptionResult); - } - } -} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs deleted file mode 100644 index 165cf08..0000000 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Operations/IndexOperationTests.cs +++ /dev/null @@ -1,302 +0,0 @@ -using System; -using System.Threading.Tasks; -using AutoFixture; -using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureCognitiveSearch.Exceptions.IndexExceptions; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Repositories; -using Cogworks.AzureCognitiveSearch.Services; -using Cogworks.AzureCognitiveSearch.UnitTests.Models; -using NSubstitute; -using NSubstitute.ExceptionExtensions; -using Xunit; - -namespace Cogworks.AzureCognitiveSearch.UnitTests.Operations -{ - public class IndexOperationTests : TestBase - { - private readonly IAzureIndexOperation _azureIndexOperation; - - public IndexOperationTests() - => _azureIndexOperation = new AzureSearchRepository( - AzureIndexOperationService, - AzureDocumentOperationService, - Search); - - #region Exists Tests - - [Fact] - public async Task Should_ReturnTrue_When_IndexExists() - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(true); - - // Act - var result = await _azureIndexOperation.IndexExistsAsync(); - - // Assert - Assert.True(result); - } - - [Fact] - public async Task Should_ReturnFalse_When_IndexNotExists() - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(false); - - // Act - var result = await _azureIndexOperation.IndexExistsAsync(); - - // Assert - Assert.False(result); - } - - [Fact] - public async Task Should_ThrowException_When_IssuesWithConnection() - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Throws(_ => new IndexExistsException( - "Test Error", - Fixture.Create())); - - // Assert - var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexExistsAsync()); - - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - } - - [Fact] - public async Task Should_Not_ThrowException_When_NoIssueWithConnection() - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(true); - - // Act - var indexNotExistsResult = await Record.ExceptionAsync(Should_ReturnFalse_When_IndexNotExists); - var indexExistsResult = await Record.ExceptionAsync(Should_ReturnTrue_When_IndexExists); - - // Assert - Assert.Null(indexNotExistsResult); - Assert.Null(indexExistsResult); - } - - #endregion Exists Tests - - #region Delete Tests - - [Fact] - public async Task Should_DeleteIndex_When_IndexExists() - { - // Act - - var deleteResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); - - // Assert - Assert.Null(deleteResult); - } - - [Fact] - public async Task Should_Not_ThrowException_When_DeletingExistingIndex() - { - // Act - var indexDeletingResult = await Record.ExceptionAsync(Should_DeleteIndex_When_IndexExists); - - // Assert - Assert.Null(indexDeletingResult); - } - - [Fact] - public async Task Should_ThrowException_When_IssuesWithConnection_On_DeletingIndex() - { - // Arrange - _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) - .Throws(_ => new IndexDeleteException( - "Test Error", - Fixture.Create())); - - // Act - var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); - - // Assert - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - } - - #endregion Delete Tests - - #region Index Create or Update Tests - - [Fact] - public async Task Should_CreateOrUpdateIndex() - { - // Arrange - var createdOrUpdatedIndex = new SearchIndex(TestDocumentModelDefinition.IndexName); - - _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) - .Returns(createdOrUpdatedIndex); - - // Act - var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); - - // Assert - Assert.Null(indexResult); - - } - - [Fact] - public async Task Should_CreateOrUpdateCustomIndex() - { - // Arrange - var index = new SearchIndex(Fixture.Create()); - - var customModelDefinition = new AzureIndexDefinition(index); - - var customIndexOperationService = new AzureIndexOperationService( - customModelDefinition, - IndexOperationWrapper); - - var azureIndexOperation = new AzureSearchRepository( - customIndexOperationService, - AzureDocumentOperationService, - Search); - - // Act - var indexResult = await Record.ExceptionAsync(async () => await azureIndexOperation.IndexCreateOrUpdateAsync()); - - // Assert - Assert.Null(indexResult); - } - - [Fact] - public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingIndex() - { - // Arrange - _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) - .Throws(_ => new IndexCreateOrUpdateException( - "Test Error", - Fixture.Create())); - - // Act - var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); - - // Assert - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - } - - [Fact] - public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomIndex() - { - // Arrange - var index = new SearchIndex(Fixture.Create()); - - var customModelDefinition = new AzureIndexDefinition(index); - - var customIndexOperationService = new AzureIndexOperationService( - customModelDefinition, - IndexOperationWrapper); - - var azureIndexOperation = new AzureSearchRepository( - customIndexOperationService, - AzureDocumentOperationService, - Search); - - _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) - .Throws(_ => new IndexCreateOrUpdateException( - "Test Error", - Fixture.Create())); - - // Act - var domainException = await Assert.ThrowsAsync(async () => await azureIndexOperation.IndexCreateOrUpdateAsync()); - - // Assert - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - } - - #endregion Index Create or Update Tests - - #region Index Clear Tests - - [Fact] - public async Task Should_ClearIndex_When_IndexExists() - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(true); - - // Act - var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); - - // Assert - Assert.Null(indexResult); - } - - [Fact] - public async Task Should_ClearIndex_When_IndexNotExists() - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(false); - - // Act - var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); - - // Assert - Assert.Null(indexResult); - } - - [Fact] - public async Task Should_ThrowException_When_IssueWithConnectionOnClearingIndex() - { - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Returns(true); - - _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) - .Throws(_ => new IndexClearException( - "Test Error", - Fixture.Create())); - - // Act - var domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); - - // Assert - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - - - // Arrange - _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Throws(_ => new IndexExistsException( - "Test Error", - Fixture.Create())); - - _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) - .Throws(_ => new IndexCreateOrUpdateException( - "Test Error", - Fixture.Create())); - - // Act - domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); - - // Assert - Assert.NotNull(domainException); - Assert.Equal("Test Error", domainException.Message); - Assert.NotNull(domainException.InnerException); - } - - #endregion Index Clear Tests - } -} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs deleted file mode 100644 index b9669e7..0000000 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/TestBase.cs +++ /dev/null @@ -1,45 +0,0 @@ -using AutoFixture; -using AutoFixture.AutoNSubstitute; -using Cogworks.AzureCognitiveSearch.Interfaces.Operations; -using Cogworks.AzureCognitiveSearch.Interfaces.Searches; -using Cogworks.AzureCognitiveSearch.Interfaces.Wrappers; -using Cogworks.AzureCognitiveSearch.Models; -using Cogworks.AzureCognitiveSearch.Services; -using Cogworks.AzureCognitiveSearch.UnitTests.Models; -using NSubstitute; - -namespace Cogworks.AzureCognitiveSearch.UnitTests -{ - public abstract class TestBase - { - protected const string AzureWrapperException = "some internal exception"; - - protected readonly IFixture Fixture = new Fixture() - .Customize(new AutoNSubstituteCustomization()); - - protected readonly IIndexOperationWrapper IndexOperationWrapper; - protected readonly IDocumentOperationWrapper DocumentOperationWrapper; - protected readonly AzureIndexDefinition TestDocumentModelDefinition; - protected readonly IAzureSearch Search; - - protected readonly IAzureDocumentOperation AzureDocumentOperationService; - protected readonly IAzureIndexOperation AzureIndexOperationService; - - protected TestBase() - { - TestDocumentModelDefinition = Fixture.Create>(); - - IndexOperationWrapper = Substitute.For(); - DocumentOperationWrapper = Substitute.For>(); - - Search = Substitute.For>(); - - AzureDocumentOperationService = new AzureDocumentOperationService( - DocumentOperationWrapper); - - AzureIndexOperationService = new AzureIndexOperationService( - TestDocumentModelDefinition, - IndexOperationWrapper); - } - } -} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index ec981c2..18f334d 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -11,9 +11,9 @@ using System; using Cogworks.AzureSearch.AutofacIoc.UnitTests.Models; using Cogworks.AzureSearch.AutofacIoc.UnitTests.Searchers; -using Microsoft.Azure.Search.Models; using Xunit; -using Index = Microsoft.Azure.Search.Models.Index; +using Azure.Search.Documents.Indexes.Models; +using Azure.Search.Documents.Models; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests { @@ -31,35 +31,32 @@ public AutofacIocExtensionTests() _containerBuilder = new ContainerBuilder(); _azureSearchBuilder = _containerBuilder.RegisterAzureSearch() - .RegisterClientOptions("test", "test") + .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) .RegisterIndexDefinitions(SecondDocumentIndexName) - .RegisterIndexDefinitions(customIndex: new Index { Name = ThirdDocumentIndexName }); + .RegisterIndexDefinitions(customIndex: new SearchIndex(ThirdDocumentIndexName)); } [Theory] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] + [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] - [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] + [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] - [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] + [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] - [InlineData(typeof(IAzureSearch))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { // Arrange @@ -82,21 +79,18 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -114,7 +108,6 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -158,10 +151,13 @@ public void Should_ReturnCustomSearchService() // ReSharper disable once PossibleNullReferenceException using (var scope = _containerBuilder.Build().BeginLifetimeScope()) { + var customTestSearch = scope.Resolve(); // Assert Assert.NotNull(customTestSearch); + + } } diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests.csproj index 6474551..cfc453a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests.csproj +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests.csproj @@ -37,6 +37,5 @@ - \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs index a7cbf3a..23a36c4 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { public class FirstTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs index 0d7c116..93944d8 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { public class NotRegisteredTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs index d3d8715..9600a4f 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { public class SecondTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs index 32f03e9..02413b3 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { public class ThirdTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs index a85711d..96ddf1e 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -1,5 +1,7 @@ using Cogworks.AzureSearch.AutofacIoc.UnitTests.Models; using Cogworks.AzureSearch.Interfaces.Searches; +using Cogworks.AzureSearch.Interfaces.Wrappers; +using Cogworks.AzureSearch.Searchers; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Searchers { @@ -8,9 +10,9 @@ public interface ICustomTestSearch void SomeCustomSearchExample(); } - public class CustomTestSearch : AzureSearch.Searchers.AzureSearch, ICustomTestSearch + public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureDocumentSearch azureSearchRepository) : base(azureSearchRepository) + public CustomTestSearch(IAzureSearch search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Cogworks.AzureSearch.LightInject.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Cogworks.AzureSearch.LightInject.UnitTests.csproj index 41f91f0..5eb1c65 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Cogworks.AzureSearch.LightInject.UnitTests.csproj +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Cogworks.AzureSearch.LightInject.UnitTests.csproj @@ -36,6 +36,5 @@ - \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index a21403a..9fa2130 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -11,8 +11,8 @@ using LightInject; using NSubstitute; using System; +using Azure.Search.Documents.Indexes.Models; using Xunit; -using Index = Microsoft.Azure.Search.Models.Index; namespace Cogworks.AzureSearch.LightInject.UnitTests { @@ -30,32 +30,29 @@ public LightInjectIocExtensionTests() _container = new ServiceContainer(); _azureSearchBuilder = _container.RegisterAzureSearch() - .RegisterClientOptions("test", "test") + .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) .RegisterIndexDefinitions(SecondDocumentIndexName) - .RegisterIndexDefinitions(customIndex: new Index { Name = ThirdDocumentIndexName }); ; + .RegisterIndexDefinitions(customIndex: new SearchIndex(ThirdDocumentIndexName)); ; } [Theory] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] + [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] - [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] + [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] - [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -81,21 +78,18 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -113,7 +107,6 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs index b0e2e35..9bd312f 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { public class FirstTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs index 2442364..6df63a7 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { public class NotRegisteredTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs index dfe1aef..92ed6ee 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { public class SecondTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs index 0c3f998..bb9f038 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { public class ThirdTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs index 408aa3e..54af0df 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs @@ -1,5 +1,6 @@ using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.LightInject.UnitTests.Models; +using Cogworks.AzureSearch.Searchers; namespace Cogworks.AzureSearch.LightInject.UnitTests.Searchers { @@ -8,9 +9,9 @@ public interface ICustomTestSearch void SomeCustomSearchExample(); } - public class CustomTestSearch : AzureSearch.Searchers.AzureSearch, ICustomTestSearch + public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureDocumentSearch azureSearchRepository) : base(azureSearchRepository) + public CustomTestSearch(IAzureSearch search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests.csproj index 9708802..494fc15 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests.csproj +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests.csproj @@ -37,6 +37,5 @@ - \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index cd0aefb..e45d64f 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -9,10 +9,10 @@ using Microsoft.Extensions.DependencyInjection; using NSubstitute; using System; +using Azure.Search.Documents.Indexes.Models; using Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models; using Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Searchers; using Xunit; -using Index = Microsoft.Azure.Search.Models.Index; namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests { @@ -30,32 +30,29 @@ public MicrosoftIocExtensionTests() _serviceContainer = new ServiceCollection(); _azureSearchBuilder = _serviceContainer.RegisterAzureSearch() - .RegisterClientOptions("test", "test") + .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) .RegisterIndexDefinitions(SecondDocumentIndexName) - .RegisterIndexDefinitions(customIndex: new Index { Name = ThirdDocumentIndexName }); + .RegisterIndexDefinitions(customIndex: new SearchIndex(ThirdDocumentIndexName)); } [Theory] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -81,21 +78,18 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -113,7 +107,6 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs index 6d1dae5..de0966f 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { public class FirstTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs index 8aeb17b..cc04d90 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { public class NotRegisteredTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs index c13b11d..e199052 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { public class SecondTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs index 623bd62..061aaca 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { public class ThirdTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs index 5f1475c..2c88691 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -1,5 +1,6 @@ using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models; +using Cogworks.AzureSearch.Searchers; namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Searchers { @@ -8,9 +9,9 @@ public interface ICustomTestSearch void SomeCustomSearchExample(); } - public class CustomTestSearch : AzureSearch.Searchers.AzureSearch, ICustomTestSearch + public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureDocumentSearch azureSearchRepository) : base(azureSearchRepository) + public CustomTestSearch(IAzureSearch search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj index 5411aca..729f31a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj @@ -15,7 +15,7 @@ Properties Cogworks.AzureSearch.UmbracoIoc.UnitTests Cogworks.AzureSearch.UmbracoIoc.UnitTests - v4.8 + v4.7.2 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15.0 @@ -50,6 +50,12 @@ ..\..\..\packages\AutoFixture.AutoNSubstitute.4.13.0\lib\net452\AutoFixture.AutoNSubstitute.dll + + ..\..\..\packages\Azure.Core.1.9.0\lib\net461\Azure.Core.dll + + + ..\..\..\packages\Azure.Search.Documents.11.2.0\lib\netstandard2.0\Azure.Search.Documents.dll + ..\..\..\packages\DotLiquid.2.0.333\lib\net45\DotLiquid.dll @@ -74,17 +80,8 @@ ..\..\..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll - - ..\..\..\packages\Microsoft.Azure.Search.10.1.0\lib\net461\Microsoft.Azure.Search.dll - - - ..\..\..\packages\Microsoft.Azure.Search.Common.10.1.0\lib\net461\Microsoft.Azure.Search.Common.dll - - - ..\..\..\packages\Microsoft.Azure.Search.Data.10.1.0\lib\net461\Microsoft.Azure.Search.Data.dll - - - ..\..\..\packages\Microsoft.Azure.Search.Service.10.1.0\lib\net461\Microsoft.Azure.Search.Service.dll + + ..\..\..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll @@ -96,9 +93,6 @@ ..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.20\lib\net461\Microsoft.Rest.ClientRuntime.dll - - ..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.18\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll - ..\..\..\packages\Microsoft.Spatial.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll @@ -169,6 +163,9 @@ ..\..\..\packages\Superpower.2.0.0\lib\net45\Superpower.dll + + ..\..\..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll + ..\..\..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll @@ -183,29 +180,54 @@ ..\..\..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.Entity.dll - - ..\..\..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\..\..\packages\System.Diagnostics.DiagnosticSource.4.6.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\..\..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + + + ..\..\..\packages\System.Memory.Data.1.0.1\lib\net461\System.Memory.Data.dll + ..\..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + + ..\..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + ..\..\..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll + + ..\..\..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + ..\..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll True True + + ..\..\..\packages\System.Text.Encodings.Web.4.6.0\lib\netstandard2.0\System.Text.Encodings.Web.dll + + + ..\..\..\packages\System.Text.Json.4.6.0\lib\net461\System.Text.Json.dll + + + ..\..\..\packages\System.Threading.Channels.4.6.0\lib\netstandard2.0\System.Threading.Channels.dll + + + ..\..\..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + ..\..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -252,7 +274,7 @@ Cogworks.AzureSearch.Umbraco.IocExtension - {64b55c63-5070-430f-a92d-747ff2cd57a6} + {94f77e26-4e02-4ed5-bd54-45e3aaa70090} Cogworks.AzureSearch diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs index 392acc6..e4a5199 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs @@ -1,15 +1,17 @@ -using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; +using Cogworks.AzureSearch.Models; namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { public class FirstTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs index 281b7dc..c91e9a8 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -1,15 +1,17 @@ -using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; +using Cogworks.AzureSearch.Models; namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { public class NotRegisteredTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs index 76a2040..98c50d5 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs @@ -1,15 +1,17 @@ -using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; +using Cogworks.AzureSearch.Models; namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { public class SecondTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs index 59fdf9f..f6ef5a8 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs @@ -1,15 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { public class ThirdTestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs index 0c5fb4d..2aba0d4 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -1,4 +1,5 @@ using Cogworks.AzureSearch.Interfaces.Searches; +using Cogworks.AzureSearch.Searchers; using Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models; namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Searchers @@ -8,9 +9,9 @@ public interface ICustomTestSearch void SomeCustomSearchExample(); } - public class CustomTestSearch : AzureSearch.Searchers.AzureSearch, ICustomTestSearch + public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureDocumentSearch azureSearchRepository) : base(azureSearchRepository) + public CustomTestSearch(IAzureSearch search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index d0c86c9..c187cd7 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -12,7 +12,7 @@ using LightInject; using NSubstitute; using System; -using Microsoft.Azure.Search.Models; +using Azure.Search.Documents.Indexes.Models; using Umbraco.Core.Composing; using Umbraco.Core.Composing.LightInject; using Xunit; @@ -35,11 +35,11 @@ public UmbracoIocExtensionTests() _composing = new Composition(lightInjectContainer, null, null, null, null); _azureSearchBuilder = _composing.RegisterAzureSearch() - .RegisterClientOptions("test", "test") + .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) .RegisterIndexDefinitions(SecondDocumentIndexName) - .RegisterIndexDefinitions(customIndex: new Index { Name = ThirdDocumentIndexName }); + .RegisterIndexDefinitions(customIndex: new SearchIndex(ThirdDocumentIndexName)); } @@ -48,21 +48,18 @@ public UmbracoIocExtensionTests() [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -88,21 +85,18 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] @@ -120,7 +114,6 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureDocumentSearch))] [InlineData(typeof(IAzureIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/app.config b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/app.config index fcc6ad7..0a5f76e 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/app.config +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/app.config @@ -10,6 +10,26 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/packages.config b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/packages.config index 56aa20e..b911f8d 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/packages.config +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/packages.config @@ -1,60 +1,67 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Cogworks.AzureSearch.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Cogworks.AzureSearch.UnitTests.csproj index feddd21..b1ab222 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Cogworks.AzureSearch.UnitTests.csproj +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Cogworks.AzureSearch.UnitTests.csproj @@ -6,6 +6,18 @@ false + + + + + + + + + + + + @@ -36,10 +48,4 @@ - - - - - - \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs index 61a95e2..5b92a03 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs @@ -1,15 +1,18 @@ -using Cogworks.AzureSearch.Models; -using Microsoft.Azure.Search; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using Azure.Search.Documents.Indexes; +using Cogworks.AzureSearch.Models; namespace Cogworks.AzureSearch.UnitTests.Models { public class TestDocumentModel : IAzureModel { - [Key, IsFilterable, IsRetrievable(true), IsSearchable] + [SimpleField(IsKey = true, IsFilterable = true)] + [SearchableField()] public string Id { get; set; } - [IsFilterable, IsSearchable] + [SimpleField(IsFilterable = true)] + [SearchableField()] + public string Name { get; set; } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestResponse.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs similarity index 85% rename from tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestResponse.cs rename to tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs index 5f4302c..49d60b3 100644 --- a/tests/UnitTests/Cogworks.AzureCognitiveSearch.UnitTests/Models/TestResponse.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs @@ -2,7 +2,7 @@ using Azure; using Azure.Search.Documents.Models; -namespace Cogworks.AzureCognitiveSearch.UnitTests.Models +namespace Cogworks.AzureSearch.UnitTests.Models { public class TestResponse : Response diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs index 703f075..9843f5c 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs @@ -1,11 +1,14 @@ -using AutoFixture; +using System; +using System.Linq; +using System.Threading.Tasks; +using AutoFixture; +using Azure.Search.Documents.Models; +using Cogworks.AzureSearch.Exceptions.DocumentsExceptions; using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.UnitTests.Models; -using Microsoft.Azure.Search.Models; using NSubstitute; -using System.Linq; -using System.Threading.Tasks; +using NSubstitute.ExceptionExtensions; using Xunit; namespace Cogworks.AzureSearch.UnitTests.Operations @@ -16,9 +19,9 @@ public class DocumentOperationTests : TestBase public DocumentOperationTests() => _azureDocumentOperation = new AzureSearchRepository( - TestDocumentModelDefinition, - IndexOperationWrapper, - DocumentOperationWrapper); + AzureIndexOperationService, + AzureDocumentOperationService, + Search); [Theory] [InlineData(1)] @@ -32,14 +35,20 @@ public async Task Should_AddOrUpdateDocuments(int documentsCount) .Select(_ => Fixture.Create()) .ToArray(); + var indexResults = testDocuments - .Select(testDocument => new IndexingResult(testDocument.Id, succeeded: true, statusCode: 200)) + .Select(testDocument => SearchModelFactory.IndexingResult( + key: testDocument.Id, + errorMessage: string.Empty, + succeeded: true, + status: 200)) .ToList(); - var documentIndexResult = new DocumentIndexResult(indexResults); + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); - _ = DocumentOperationWrapper.IndexAsync(Arg.Any>()) - .Returns(documentIndexResult); + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); // Act var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); @@ -60,15 +69,83 @@ public async Task Should_AddOrUpdateDocuments(int documentsCount) }); } + [Theory] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Fail_When_AddOrUpdateDocumentsPartiallyFail(int documentsCount) + { + // Arrange + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + + var indexResults = testDocuments + .Select((document, index) => new + { + Document = document, + Succeded = index % (documentsCount / 2) == 0 + }) + .Select(item => SearchModelFactory.IndexingResult( + key: item.Document.Id, + errorMessage: !item.Succeded + ? "Internal Unit Error." + : string.Empty, + succeeded: item.Succeded, + status: item.Succeded + ? 200 + : 404)) + .ToList(); + + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); + + // Act + var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); + + // Assert + Assert.NotNull(result); + Assert.False(result.Succeeded); + Assert.NotEmpty(result.SucceededDocuments); + Assert.NotEmpty(result.FailedDocuments); + Assert.All( + result.SucceededDocuments, + succeedItem => + { + Assert.True(succeedItem.Succeeded); + Assert.Equal(200, succeedItem.StatusCode); + Assert.Equal("Successfully adding or updating document.", succeedItem.Message); + Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); + }); + + Assert.All( + result.FailedDocuments, + succeedItem => + { + Assert.False(succeedItem.Succeeded); + Assert.Equal(404, succeedItem.StatusCode); + Assert.Equal("Failed adding or updating document.", succeedItem.Message); + Assert.Equal("Internal Unit Error.", succeedItem.InnerMessage); + Assert.Contains(testDocuments, item => item.Id == succeedItem.ModelId); + }); + } + [Fact] public async Task Should_Succeeded_When_TryToAddEmptyDocuments() { // Arrange var testDocuments = Enumerable.Empty(); - var documentIndexResult = new DocumentIndexResult(); + var documentIndexResult = new TestResponse( + SearchModelFactory.IndexDocumentsResult( + Enumerable.Empty())); - _ = DocumentOperationWrapper.IndexAsync(Arg.Any>()) + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) .Returns(documentIndexResult); // Act @@ -88,9 +165,12 @@ public async Task Should_Succeeded_When_TryToRemoveEmptyDocuments() // Arrange var testDocuments = Enumerable.Empty(); - var documentIndexResult = new DocumentIndexResult(); + var documentIndexResult = new TestResponse( + SearchModelFactory.IndexDocumentsResult( + Enumerable.Empty())); - _ = DocumentOperationWrapper.IndexAsync(Arg.Any>()) + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) .Returns(documentIndexResult); // Act @@ -117,13 +197,18 @@ public async Task Should_Succeeded_When_TryRemoveDocuments(int documentsCount) .ToArray(); var indexResults = testDocuments - .Select(testDocument => new IndexingResult(testDocument.Id, succeeded: true, statusCode: 200)) + .Select(testDocument => SearchModelFactory.IndexingResult( + key: testDocument.Id, + errorMessage: string.Empty, + succeeded: true, + status: 200)) .ToList(); - var documentIndexResult = new DocumentIndexResult(indexResults); + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); - _ = DocumentOperationWrapper.IndexAsync(Arg.Any>()) - .Returns(documentIndexResult); + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); // Act var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); @@ -157,13 +242,18 @@ public async Task Should_Fail_When_TryRemoveNotExistingDocuments(int documentsCo .ToArray(); var indexResults = testDocuments - .Select(testDocument => new IndexingResult(testDocument.Id, succeeded: false, statusCode: 404)) + .Select(testDocument => SearchModelFactory.IndexingResult( + key: testDocument.Id, + errorMessage: string.Empty, + succeeded: false, + status: 404)) .ToList(); - var documentIndexResult = new DocumentIndexResult(indexResults); + var documentIndexResult = SearchModelFactory.IndexDocumentsResult(indexResults); - _ = DocumentOperationWrapper.IndexAsync(Arg.Any>()) - .Returns(documentIndexResult); + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Returns(new TestResponse(documentIndexResult)); // Act var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); @@ -183,5 +273,93 @@ public async Task Should_Fail_When_TryRemoveNotExistingDocuments(int documentsCo Assert.Contains(testDocuments, item => item.Id == failedItem.ModelId); }); } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_ThrowDomainException_When_IssueWith_TryAddOrUpdateDocuments(int documentsCount) + { + // Arrange + + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Throws(_ => new AddOrUpdateDocumentException("Test Error", Fixture.Create())); + + // Assert + var domainException = await Assert.ThrowsAsync(async () => + await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments)); + + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Not_ThrowDomainException_When_No_IssueWith_TryAddOrUpdateDocuments(int documentsCount) + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + // Act + var domainExceptionResult = await Record.ExceptionAsync(() => Should_AddOrUpdateDocuments(documentsCount)); + + // Assert + Assert.Null(domainExceptionResult); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_ThrowDomainException_When_IssueWith_TryRemoveDocuments(int documentsCount) + { + // Arrange + + var testDocuments = Enumerable.Range(0, documentsCount) + .Select(_ => Fixture.Create()) + .ToArray(); + + _ = DocumentOperationWrapper + .IndexAsync(Arg.Any>()) + .Throws(_ => new AddOrUpdateDocumentException("Test Error", Fixture.Create())); + + // Assert + var domainException = await Assert.ThrowsAsync(async () => + await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments)); + + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + } + + [Theory] + [InlineData(1)] + [InlineData(100)] + [InlineData(500)] + [InlineData(1000)] + public async Task Should_Not_ThrowDomainException_When_No_IssueWith_TryRemoveDocuments(int documentsCount) + { + // Arrange + _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) + .Returns(true); + + // Act + var domainExceptionResult = await Record.ExceptionAsync(() => Should_Succeeded_When_TryRemoveDocuments(documentsCount)); + + // Assert + Assert.Null(domainExceptionResult); + } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs index 9aa7baf..e493284 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs @@ -1,13 +1,15 @@ -using Cogworks.AzureSearch.Interfaces.Operations; +using System; +using System.Threading.Tasks; +using AutoFixture; +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Exceptions.IndexExceptions; +using Cogworks.AzureSearch.Interfaces.Operations; +using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Repositories; +using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.UnitTests.Models; -using Microsoft.Azure.Search.Models; -using Microsoft.Rest.Azure; using NSubstitute; using NSubstitute.ExceptionExtensions; -using System.Threading.Tasks; -using AutoFixture; -using Cogworks.AzureSearch.Models; using Xunit; namespace Cogworks.AzureSearch.UnitTests.Operations @@ -18,9 +20,9 @@ public class IndexOperationTests : TestBase public IndexOperationTests() => _azureIndexOperation = new AzureSearchRepository( - TestDocumentModelDefinition, - IndexOperationWrapper, - DocumentOperationWrapper); + AzureIndexOperationService, + AzureDocumentOperationService, + Search); #region Exists Tests @@ -57,10 +59,16 @@ public async Task Should_ThrowException_When_IssuesWithConnection() { // Arrange _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Throws(_ => new CloudException(AzureWrapperException)); + .Throws(_ => new IndexExistsException( + "Test Error", + Fixture.Create())); // Assert - _ = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexExistsAsync()); + var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexExistsAsync()); + + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); } [Fact] @@ -87,28 +95,11 @@ public async Task Should_Not_ThrowException_When_NoIssueWithConnection() public async Task Should_DeleteIndex_When_IndexExists() { // Act - var deleteResult = await _azureIndexOperation.IndexDeleteAsync(); - - // Assert - Assert.NotNull(deleteResult); - Assert.True(deleteResult.Succeeded); - Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully deleted.", deleteResult.Message); - } - - [Fact] - public async Task Should_Not_DeleteIndex_When_IndexNotExists() - { - // Arrange - _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) - .Throws(_ => new CloudException(AzureWrapperException)); - // Act - var deleteResult = await _azureIndexOperation.IndexDeleteAsync(); + var deleteResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); // Assert - Assert.NotNull(deleteResult); - Assert.False(deleteResult.Succeeded); - Assert.Equal($"An issue occurred on deleting index: {TestDocumentModelDefinition.IndexName}. More information: {AzureWrapperException}", deleteResult.Message); + Assert.Null(deleteResult); } [Fact] @@ -122,13 +113,21 @@ public async Task Should_Not_ThrowException_When_DeletingExistingIndex() } [Fact] - public async Task Should_Not_ThrowException_When_DeletingNotExistingIndex() + public async Task Should_ThrowException_When_IssuesWithConnection_On_DeletingIndex() { + // Arrange + _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) + .Throws(_ => new IndexDeleteException( + "Test Error", + Fixture.Create())); + // Act - var indexDeletingResult = await Record.ExceptionAsync(Should_Not_DeleteIndex_When_IndexNotExists); + var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); // Assert - Assert.Null(indexDeletingResult); + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); } #endregion Delete Tests @@ -139,86 +138,90 @@ public async Task Should_Not_ThrowException_When_DeletingNotExistingIndex() public async Task Should_CreateOrUpdateIndex() { // Arrange - var createdOrUpdatedIndex = new Index - { - Name = TestDocumentModelDefinition.IndexName - }; + var createdOrUpdatedIndex = new SearchIndex(TestDocumentModelDefinition.IndexName); _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) .Returns(createdOrUpdatedIndex); // Act - var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); + var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); // Assert - Assert.NotNull(operationResult); - Assert.True(operationResult.Succeeded); - Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully created or updated.", operationResult.Message); + Assert.Null(indexResult); + } [Fact] public async Task Should_CreateOrUpdateCustomIndex() { // Arrange - var createdOrUpdatedIndex = new Index - { - Name = TestDocumentModelDefinition.IndexName - }; + var index = new SearchIndex(Fixture.Create()); - _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) - .Returns(createdOrUpdatedIndex); + var customModelDefinition = new AzureIndexDefinition(index); + + var customIndexOperationService = new AzureIndexOperationService( + customModelDefinition, + IndexOperationWrapper); + + var azureIndexOperation = new AzureSearchRepository( + customIndexOperationService, + AzureDocumentOperationService, + Search); // Act - var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); + var indexResult = await Record.ExceptionAsync(async () => await azureIndexOperation.IndexCreateOrUpdateAsync()); // Assert - Assert.NotNull(operationResult); - Assert.True(operationResult.Succeeded); - Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully created or updated.", operationResult.Message); + Assert.Null(indexResult); } [Fact] - public async Task Should_Not_ThrowException_When_IssueOnCreatingOrUpdatingIndex() + public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingIndex() { // Arrange _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) - .Throws(_ => new CloudException(AzureWrapperException)); + .Throws(_ => new IndexCreateOrUpdateException( + "Test Error", + Fixture.Create())); // Act - var operationResult = await _azureIndexOperation.IndexCreateOrUpdateAsync(); + var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); // Assert - Assert.NotNull(operationResult); - Assert.False(operationResult.Succeeded); - Assert.Equal($"An issue occurred on creating or updating index: {TestDocumentModelDefinition.IndexName}. More information: {AzureWrapperException}", operationResult.Message); + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); } [Fact] - public async Task Should_Not_ThrowException_When_IssueOnCreatingOrUpdatingCustomIndex() + public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomIndex() { // Arrange - var index = new Index - { - Name = Fixture.Create() - }; + var index = new SearchIndex(Fixture.Create()); var customModelDefinition = new AzureIndexDefinition(index); - var azureIndexOperation = new AzureSearchRepository( + var customIndexOperationService = new AzureIndexOperationService( customModelDefinition, - IndexOperationWrapper, - DocumentOperationWrapper); + IndexOperationWrapper); - _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) - .Throws(_ => new CloudException(AzureWrapperException)); + var azureIndexOperation = new AzureSearchRepository( + customIndexOperationService, + AzureDocumentOperationService, + Search); + + _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) + .Throws(_ => new IndexCreateOrUpdateException( + "Test Error", + Fixture.Create())); // Act - var operationResult = await azureIndexOperation.IndexCreateOrUpdateAsync(); + var domainException = await Assert.ThrowsAsync(async () => await azureIndexOperation.IndexCreateOrUpdateAsync()); // Assert - Assert.NotNull(operationResult); - Assert.False(operationResult.Succeeded); - Assert.Equal($"An issue occurred on creating or updating index: {customModelDefinition.IndexName}. More information: {AzureWrapperException}", operationResult.Message); + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); } #endregion Index Create or Update Tests @@ -232,13 +235,11 @@ public async Task Should_ClearIndex_When_IndexExists() _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) .Returns(true); - // Act - var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); + // Act + var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); // Assert - Assert.NotNull(indexOperationResult); - Assert.True(indexOperationResult.Succeeded); - Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully cleared.", indexOperationResult.Message); + Assert.Null(indexResult); } [Fact] @@ -249,46 +250,51 @@ public async Task Should_ClearIndex_When_IndexNotExists() .Returns(false); // Act - var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); + var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); // Assert - Assert.NotNull(indexOperationResult); - Assert.True(indexOperationResult.Succeeded); - Assert.Equal($"Index {TestDocumentModelDefinition.IndexName} successfully cleared.", indexOperationResult.Message); + Assert.Null(indexResult); } [Fact] - public async Task Should_Not_ThrowException_When_IssueWithConnectionOnClearingIndex() + public async Task Should_ThrowException_When_IssueWithConnectionOnClearingIndex() { // Arrange _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) .Returns(true); _ = IndexOperationWrapper.DeleteAsync(Arg.Any()) - .Throws(_ => new CloudException(AzureWrapperException)); + .Throws(_ => new IndexClearException( + "Test Error", + Fixture.Create())); // Act - var indexOperationResult = await _azureIndexOperation.IndexClearAsync(); + var domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); // Assert - Assert.NotNull(indexOperationResult); - Assert.False(indexOperationResult.Succeeded); - Assert.Equal($"An issue occurred on clearing index: {TestDocumentModelDefinition.IndexName}. Could not delete existing index.", indexOperationResult.Message); + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); + // Arrange _ = IndexOperationWrapper.ExistsAsync(Arg.Any()) - .Throws(_ => new CloudException(AzureWrapperException)); + .Throws(_ => new IndexExistsException( + "Test Error", + Fixture.Create())); _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any()) - .Throws(_ => new CloudException(AzureWrapperException)); + .Throws(_ => new IndexCreateOrUpdateException( + "Test Error", + Fixture.Create())); // Act - indexOperationResult = await _azureIndexOperation.IndexClearAsync(); + domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); // Assert - Assert.NotNull(indexOperationResult); - Assert.False(indexOperationResult.Succeeded); - Assert.Equal($"An issue occurred on clearing index: {TestDocumentModelDefinition.IndexName}. Could not create index.", indexOperationResult.Message); + Assert.NotNull(domainException); + Assert.Equal("Test Error", domainException.Message); + Assert.NotNull(domainException.InnerException); } #endregion Index Clear Tests diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs index 27d8482..bb9ab69 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs @@ -1,7 +1,10 @@ using AutoFixture; using AutoFixture.AutoNSubstitute; +using Cogworks.AzureSearch.Interfaces.Operations; +using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.UnitTests.Models; using NSubstitute; @@ -17,6 +20,10 @@ public abstract class TestBase protected readonly IIndexOperationWrapper IndexOperationWrapper; protected readonly IDocumentOperationWrapper DocumentOperationWrapper; protected readonly AzureIndexDefinition TestDocumentModelDefinition; + protected readonly IAzureSearch Search; + + protected readonly IAzureDocumentOperation AzureDocumentOperationService; + protected readonly IAzureIndexOperation AzureIndexOperationService; protected TestBase() { @@ -24,6 +31,15 @@ protected TestBase() IndexOperationWrapper = Substitute.For(); DocumentOperationWrapper = Substitute.For>(); + + Search = Substitute.For>(); + + AzureDocumentOperationService = new AzureDocumentOperationService( + DocumentOperationWrapper); + + AzureIndexOperationService = new AzureIndexOperationService( + TestDocumentModelDefinition, + IndexOperationWrapper); } } } \ No newline at end of file From abe83c3f329d27e75fb4f2068e735451d48a90a2 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 11:51:41 +0200 Subject: [PATCH 13/31] fix: changed target framework --- ...ks.AzureSearch.Umbraco.IocExtension.nuspec | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec index 9108e3c..3702b15 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec @@ -1,29 +1,30 @@ - + - - Cogworks.AzureSearch.Umbraco.IocExtension - $version$ - Cogworks.AzureSearch.Umbraco.IocExtension - Cogworks - Cogworks - https://github.com/thecogworks/Cogworks.AzureSearch - - Apache-2.0 - false - A wrapper to Azure Search allowing to easily setup Azure Search indexes, searchers and using it with DI/IoC approach (currently with support for Umbraco, LightInject and Autofac). - The Cogworks Limited 2020 - Azure Search, Umbraco - - - - - - - - - - - - - + + Cogworks.AzureSearch.Umbraco.IocExtension + $version$ + Cogworks.AzureSearch.Umbraco.IocExtension + Cogworks + Cogworks + https://github.com/thecogworks/Cogworks.AzureSearch + + Apache-2.0 + false + A wrapper to Azure Search allowing to easily setup Azure Search indexes, searchers and using it with DI/IoC approach (currently with support for Umbraco, LightInject and Autofac). + The Cogworks Limited 2020 + Azure Search, Umbraco + + + + + + + + + + + + + + \ No newline at end of file From 11d40eff3be8a0cc06754597f77f21a3253d002e Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 12:10:13 +0200 Subject: [PATCH 14/31] refactor: removed unused usings --- .../Properties/AssemblyInfo.cs | 1 - src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs | 1 - src/Cogworks.AzureSearch/Exceptions/DomainException.cs | 1 - src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs | 1 - .../Interfaces/Initializers/IAzureInitializer.cs | 1 - .../Interfaces/Operations/IAzureIndexOperation.cs | 1 - .../Mappers/AzureSearchParametersMapper.cs | 3 +-- src/Cogworks.AzureSearch/Searchers/AzureSearch.cs | 3 +-- .../Searchers/CustomTestSearch.cs | 1 - .../Properties/AssemblyInfo.cs | 1 - .../Models/TestDocumentModel.cs | 3 +-- .../Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs | 4 +--- 12 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs index d6649f4..937b250 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs b/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs index 9644b12..f80da32 100644 --- a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs @@ -1,5 +1,4 @@ using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Searchers; diff --git a/src/Cogworks.AzureSearch/Exceptions/DomainException.cs b/src/Cogworks.AzureSearch/Exceptions/DomainException.cs index 2ad6010..b8ad05d 100644 --- a/src/Cogworks.AzureSearch/Exceptions/DomainException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/DomainException.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; namespace Cogworks.AzureSearch.Exceptions { diff --git a/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs b/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs index 6267215..9273f62 100644 --- a/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs +++ b/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs @@ -4,7 +4,6 @@ using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Models.Dtos; using Cogworks.AzureSearch.Options; namespace Cogworks.AzureSearch.Initializers diff --git a/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs b/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs index a4cb608..255fd10 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs @@ -1,5 +1,4 @@ using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Models.Dtos; using System.Threading.Tasks; namespace Cogworks.AzureSearch.Interfaces.Initializers diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs index 5a2095f..8afe277 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs @@ -1,6 +1,5 @@ using System.Threading.Tasks; using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Models.Dtos; namespace Cogworks.AzureSearch.Interfaces.Operations { diff --git a/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs b/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs index 9ac36c5..7780408 100644 --- a/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs @@ -1,5 +1,4 @@ -using System.Linq; -using Azure.Search.Documents; +using Azure.Search.Documents; using Azure.Search.Documents.Models; using Cogworks.AzureSearch.Enums; using Cogworks.AzureSearch.Extensions; diff --git a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs index 9c499c6..46c0261 100644 --- a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using Cogworks.AzureSearch.Extensions; using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Interfaces.Wrappers; diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs index 96ddf1e..19bc09e 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -1,6 +1,5 @@ using Cogworks.AzureSearch.AutofacIoc.UnitTests.Models; using Cogworks.AzureSearch.Interfaces.Searches; -using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Searchers; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Searchers diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Properties/AssemblyInfo.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Properties/AssemblyInfo.cs index ace1062..546bb9b 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Properties/AssemblyInfo.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("Cogworks.AzureSearch.UmbracoIoc.UnitTests")] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs index 5b92a03..54db421 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs @@ -1,5 +1,4 @@ -using System.ComponentModel.DataAnnotations; -using Azure.Search.Documents.Indexes; +using Azure.Search.Documents.Indexes; using Cogworks.AzureSearch.Models; namespace Cogworks.AzureSearch.UnitTests.Models diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs index 49d60b3..878ad44 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestResponse.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using Azure; -using Azure.Search.Documents.Models; +using Azure; namespace Cogworks.AzureSearch.UnitTests.Models { From 413b81e5f3b271bdb274abad2e87317e956c59a3 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 12:48:25 +0200 Subject: [PATCH 15/31] chore: changed operation class names --- .../Builders/AzureSearchBuilder.cs | 6 +++--- .../Builders/AzureSearchBuilder.cs | 6 +++--- .../Builders/AzureSearchBuilder.cs | 6 +++--- .../Builders/AzureSearchBuilder.cs | 6 +++--- .../AzureDocumentOperation.cs} | 6 +++--- .../AzureIndexOperation.cs} | 8 +++----- .../Operations/IndexOperationTests.cs | 6 +++--- .../UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs | 6 +++--- 8 files changed, 24 insertions(+), 26 deletions(-) rename src/Cogworks.AzureSearch/{Services/AzureDocumentOperationService.cs => Operations/AzureDocumentOperation.cs} (95%) rename src/Cogworks.AzureSearch/{Services/AzureIndexOperationService.cs => Operations/AzureIndexOperation.cs} (90%) diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index 5b1affc..15fef2a 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -10,10 +10,10 @@ using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Operations; using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; -using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; namespace Cogworks.AzureSearch.Autofac.Builders @@ -117,11 +117,11 @@ internal AzureSearchBuilder RegisterSearchers() internal AzureSearchBuilder RegisterOperations() { - _ = _builder.RegisterGeneric(typeof(AzureDocumentOperationService<>)) + _ = _builder.RegisterGeneric(typeof(AzureDocumentOperation<>)) .As(typeof(IAzureDocumentOperation<>)) .InstancePerDependency(); - _ = _builder.RegisterGeneric(typeof(AzureIndexOperationService<>)) + _ = _builder.RegisterGeneric(typeof(AzureIndexOperation<>)) .As(typeof(IAzureIndexOperation<>)) .InstancePerDependency(); diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index 116e170..8886f1a 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -9,10 +9,10 @@ using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Operations; using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; -using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; using LightInject; @@ -116,12 +116,12 @@ internal AzureSearchBuilder RegisterOperations() { _ = _container.Register( typeof(IAzureDocumentOperation<>), - typeof(AzureDocumentOperationService<>), + typeof(AzureDocumentOperation<>), new PerContainerLifetime()); _ = _container.Register( typeof(IAzureIndexOperation<>), - typeof(AzureIndexOperationService<>), + typeof(AzureIndexOperation<>), new PerContainerLifetime()); return this; diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index 53cb7df..516a9e1 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -9,10 +9,10 @@ using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Operations; using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; -using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -100,9 +100,9 @@ internal AzureSearchBuilder RegisterSearchers() internal AzureSearchBuilder RegisterOperations() { - _serviceCollection.TryAddScoped(typeof(IAzureDocumentOperation<>), typeof(AzureDocumentOperationService<>)); + _serviceCollection.TryAddScoped(typeof(IAzureDocumentOperation<>), typeof(AzureDocumentOperation<>)); - _serviceCollection.TryAddScoped(typeof(IAzureIndexOperation<>), typeof(AzureIndexOperationService<>)); + _serviceCollection.TryAddScoped(typeof(IAzureIndexOperation<>), typeof(AzureIndexOperation<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index ecb4477..9e94bdc 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -9,10 +9,10 @@ using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Operations; using Cogworks.AzureSearch.Options; using Cogworks.AzureSearch.Repositories; using Cogworks.AzureSearch.Searchers; -using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.Wrappers; using Umbraco.Core; using Umbraco.Core.Composing; @@ -119,11 +119,11 @@ internal AzureSearchBuilder RegisterOperations() { _composingRegister.Register( typeof(IAzureDocumentOperation<>), - typeof(AzureDocumentOperationService<>)); + typeof(AzureDocumentOperation<>)); _composingRegister.Register( typeof(IAzureIndexOperation<>), - typeof(AzureIndexOperationService<>)); + typeof(AzureIndexOperation<>)); return this; } diff --git a/src/Cogworks.AzureSearch/Services/AzureDocumentOperationService.cs b/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs similarity index 95% rename from src/Cogworks.AzureSearch/Services/AzureDocumentOperationService.cs rename to src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs index 2de212a..b32135b 100644 --- a/src/Cogworks.AzureSearch/Services/AzureDocumentOperationService.cs +++ b/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs @@ -10,16 +10,16 @@ using Cogworks.AzureSearch.Models; using Cogworks.AzureSearch.Models.Dtos; -namespace Cogworks.AzureSearch.Services +namespace Cogworks.AzureSearch.Operations { - public class AzureDocumentOperationService : IAzureDocumentOperation + public class AzureDocumentOperation : IAzureDocumentOperation where TAzureModel : class, IAzureModel, new() { private readonly IDocumentOperationWrapper _documentOperationWrapper; private const int BatchOperationSize = 500; - public AzureDocumentOperationService(IDocumentOperationWrapper documentOperationWrapper) + public AzureDocumentOperation(IDocumentOperationWrapper documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; diff --git a/src/Cogworks.AzureSearch/Services/AzureIndexOperationService.cs b/src/Cogworks.AzureSearch/Operations/AzureIndexOperation.cs similarity index 90% rename from src/Cogworks.AzureSearch/Services/AzureIndexOperationService.cs rename to src/Cogworks.AzureSearch/Operations/AzureIndexOperation.cs index ab641e5..4365bcd 100644 --- a/src/Cogworks.AzureSearch/Services/AzureIndexOperationService.cs +++ b/src/Cogworks.AzureSearch/Operations/AzureIndexOperation.cs @@ -1,21 +1,19 @@ using System; using System.Threading.Tasks; -using Cogworks.AzureSearch.Exceptions; using Cogworks.AzureSearch.Exceptions.IndexExceptions; using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Models.Dtos; -namespace Cogworks.AzureSearch.Services +namespace Cogworks.AzureSearch.Operations { - public class AzureIndexOperationService : IAzureIndexOperation + public class AzureIndexOperation : IAzureIndexOperation where TAzureModel : class, IAzureModel, new() { private readonly AzureIndexDefinition _azureIndexDefinition; private readonly IIndexOperationWrapper _indexOperationWrapper; - public AzureIndexOperationService( + public AzureIndexOperation( AzureIndexDefinition azureIndexDefinition, IIndexOperationWrapper indexOperationWrapper) { diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs index e493284..7021a3a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs @@ -5,8 +5,8 @@ using Cogworks.AzureSearch.Exceptions.IndexExceptions; using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Operations; using Cogworks.AzureSearch.Repositories; -using Cogworks.AzureSearch.Services; using Cogworks.AzureSearch.UnitTests.Models; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -159,7 +159,7 @@ public async Task Should_CreateOrUpdateCustomIndex() var customModelDefinition = new AzureIndexDefinition(index); - var customIndexOperationService = new AzureIndexOperationService( + var customIndexOperationService = new AzureIndexOperation( customModelDefinition, IndexOperationWrapper); @@ -201,7 +201,7 @@ public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomInde var customModelDefinition = new AzureIndexDefinition(index); - var customIndexOperationService = new AzureIndexOperationService( + var customIndexOperationService = new AzureIndexOperation( customModelDefinition, IndexOperationWrapper); diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs index bb9ab69..f83983a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs @@ -4,7 +4,7 @@ using Cogworks.AzureSearch.Interfaces.Searches; using Cogworks.AzureSearch.Interfaces.Wrappers; using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Services; +using Cogworks.AzureSearch.Operations; using Cogworks.AzureSearch.UnitTests.Models; using NSubstitute; @@ -34,10 +34,10 @@ protected TestBase() Search = Substitute.For>(); - AzureDocumentOperationService = new AzureDocumentOperationService( + AzureDocumentOperationService = new AzureDocumentOperation( DocumentOperationWrapper); - AzureIndexOperationService = new AzureIndexOperationService( + AzureIndexOperationService = new AzureIndexOperation( TestDocumentModelDefinition, IndexOperationWrapper); } From 3877cc344be4f7de206af37a8cda801742823bed Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 12:53:30 +0200 Subject: [PATCH 16/31] chore: removed new lines --- .../Builders/AzureSearchBuilder.cs | 1 - .../Mappers/AzureSearchParametersMapper.cs | 4 ---- .../Operations/AzureDocumentOperation.cs | 1 - src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs | 6 +----- .../Wrappers/DocumentOperationWrapper.cs | 1 - 5 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index 9e94bdc..046ef37 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -114,7 +114,6 @@ internal AzureSearchBuilder RegisterSearchers() return this; } - internal AzureSearchBuilder RegisterOperations() { _composingRegister.Register( diff --git a/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs b/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs index 7780408..98c6f4e 100644 --- a/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs @@ -44,14 +44,12 @@ internal static SearchOptions Map(AzureSearchParameters azureSearchParameters) } } - if (azureSearchParameters.HighlightFields.HasAny()) { foreach (var highlightField in azureSearchParameters.HighlightFields) { searchParameters.HighlightFields.Add(highlightField); } - } if (azureSearchParameters.Facets.HasAny()) @@ -60,7 +58,6 @@ internal static SearchOptions Map(AzureSearchParameters azureSearchParameters) { searchParameters.Facets.Add(facet); } - } if (azureSearchParameters.OrderBy.HasAny()) @@ -69,7 +66,6 @@ internal static SearchOptions Map(AzureSearchParameters azureSearchParameters) { searchParameters.OrderBy.Add(order); } - } return searchParameters; diff --git a/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs b/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs index b32135b..2eb3925 100644 --- a/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs @@ -22,7 +22,6 @@ public class AzureDocumentOperation : IAzureDocumentOperation documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; - public async Task AddOrUpdateDocumentAsync(TAzureModel model) { var azureBatchDocumentsOperationResult = await AddOrUpdateDocumentsAsync(new[] { model }); diff --git a/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs b/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs index 6c6bd91..3048734 100644 --- a/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs +++ b/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs @@ -14,8 +14,6 @@ public class AzureSearchClientOption public SearchClientOptions ClientOptions { get; } - - public AzureSearchClientOption(string serviceName, string credentials, string serviceUrlEndpoint) { ServiceName = serviceName; @@ -24,12 +22,10 @@ public AzureSearchClientOption(string serviceName, string credentials, string se ClientOptions = GetOptions(); } - private static SearchClientOptions GetOptions() { var clientOptions = new SearchClientOptions(); - clientOptions.AddPolicy( new SearchIdPipelinePolicy(), HttpPipelinePosition.PerCall); @@ -44,5 +40,5 @@ public override void OnSendingRequest(HttpMessage message) .Headers .SetValue("x-ms-azs-return-searchid", "true"); } -} + } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs index 58a4278..f752236 100644 --- a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs @@ -15,7 +15,6 @@ internal class DocumentOperationWrapper : IDocumentOperationWrapper { private readonly SearchClient _searchClient; - public DocumentOperationWrapper( AzureIndexDefinition azureIndexDefinition, AzureSearchClientOption azureSearchClientOption) From 74a165143ded23738805dabf601ab6462c4f68be Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:00:09 +0200 Subject: [PATCH 17/31] refactor: renamed index --- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 2 +- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Indexes/{AzureIndex.cs => Index.cs} | 4 ++-- .../Indexes/{IAzureIndex.cs => IIndex.cs} | 2 +- .../AutofacIocExtensionTests.cs | 14 +++++++------- .../LightInjectIocExtensionTests.cs | 14 +++++++------- .../MicrosoftIocExtensionTests.cs | 14 +++++++------- .../UmbracoIocExtensionTests.cs | 14 +++++++------- 10 files changed, 38 insertions(+), 38 deletions(-) rename src/Cogworks.AzureSearch/Indexes/{AzureIndex.cs => Index.cs} (85%) rename src/Cogworks.AzureSearch/Interfaces/Indexes/{IAzureIndex.cs => IIndex.cs} (86%) diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index 15fef2a..8163927 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -77,8 +77,8 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo internal AzureSearchBuilder RegisterIndexes() { - _ = _builder.RegisterGeneric(typeof(AzureIndex<>)) - .As(typeof(IAzureIndex<>)) + _ = _builder.RegisterGeneric(typeof(Index<>)) + .As(typeof(IIndex<>)) .InstancePerDependency(); return this; diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index 8886f1a..55b748c 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -78,8 +78,8 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo internal AzureSearchBuilder RegisterIndexes() { _ = _container.Register( - typeof(IAzureIndex<>), - typeof(AzureIndex<>)); + typeof(IIndex<>), + typeof(Index<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index 516a9e1..061b01a 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -68,7 +68,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo internal AzureSearchBuilder RegisterIndexes() { - _serviceCollection.TryAddScoped(typeof(IAzureIndex<>), typeof(AzureIndex<>)); + _serviceCollection.TryAddScoped(typeof(IIndex<>), typeof(Index<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index 046ef37..0c67897 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -79,8 +79,8 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo internal AzureSearchBuilder RegisterIndexes() { _composingRegister.Register( - typeof(IAzureIndex<>), - typeof(AzureIndex<>)); + typeof(IIndex<>), + typeof(Index<>)); return this; } diff --git a/src/Cogworks.AzureSearch/Indexes/AzureIndex.cs b/src/Cogworks.AzureSearch/Indexes/Index.cs similarity index 85% rename from src/Cogworks.AzureSearch/Indexes/AzureIndex.cs rename to src/Cogworks.AzureSearch/Indexes/Index.cs index f62aad0..e907275 100644 --- a/src/Cogworks.AzureSearch/Indexes/AzureIndex.cs +++ b/src/Cogworks.AzureSearch/Indexes/Index.cs @@ -7,11 +7,11 @@ namespace Cogworks.AzureSearch.Indexes { - internal class AzureIndex : IAzureIndex where TAzureModel : class, IAzureModel, new() + internal class Index : IIndex where TAzureModel : class, IAzureModel, new() { private readonly IAzureDocumentOperation _documentOperation; - public AzureIndex(IAzureDocumentOperation documentOperation) + public Index(IAzureDocumentOperation documentOperation) => _documentOperation = documentOperation; public async Task AddOrUpdateDocumentAsync(TAzureModel model) diff --git a/src/Cogworks.AzureSearch/Interfaces/Indexes/IAzureIndex.cs b/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs similarity index 86% rename from src/Cogworks.AzureSearch/Interfaces/Indexes/IAzureIndex.cs rename to src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs index 3fc1a52..4ad41f1 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Indexes/IAzureIndex.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs @@ -6,7 +6,7 @@ namespace Cogworks.AzureSearch.Interfaces.Indexes { - public interface IAzureIndex where TAzureModel : class, IAzureModel, new() + public interface IIndex where TAzureModel : class, IAzureModel, new() { Task AddOrUpdateDocumentAsync(TAzureModel model); diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index 18f334d..a97becd 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -43,19 +43,19 @@ public AutofacIocExtensionTests() [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { @@ -79,19 +79,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) @@ -108,7 +108,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index 9fa2130..61a5d9c 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -42,18 +42,18 @@ public LightInjectIocExtensionTests() [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) @@ -78,19 +78,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) @@ -107,7 +107,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index e45d64f..5f2a980 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -41,19 +41,19 @@ public MicrosoftIocExtensionTests() [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) @@ -78,19 +78,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) @@ -107,7 +107,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index c187cd7..cbd0dc9 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -48,19 +48,19 @@ public UmbracoIocExtensionTests() [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) @@ -85,19 +85,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) @@ -114,7 +114,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] - [InlineData(typeof(IAzureIndex))] + [InlineData(typeof(IIndex))] [InlineData(typeof(IAzureInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) From 51d12011998fac19ddb7564c4c6d49a7aa984e60 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:01:18 +0200 Subject: [PATCH 18/31] refactor: renamed initializer --- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 2 +- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../{AzureInitializer.cs => Initializer.cs} | 4 ++-- .../{IAzureInitializer.cs => IInitializer.cs} | 2 +- .../AutofacIocExtensionTests.cs | 14 +++++++------- .../LightInjectIocExtensionTests.cs | 14 +++++++------- .../MicrosoftIocExtensionTests.cs | 14 +++++++------- .../UmbracoIocExtensionTests.cs | 14 +++++++------- 10 files changed, 38 insertions(+), 38 deletions(-) rename src/Cogworks.AzureSearch/Initializers/{AzureInitializer.cs => Initializer.cs} (87%) rename src/Cogworks.AzureSearch/Interfaces/Initializers/{IAzureInitializer.cs => IInitializer.cs} (62%) diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index 8163927..3e9957d 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -27,8 +27,8 @@ public AzureSearchBuilder(ContainerBuilder builder) internal AzureSearchBuilder RegisterInitializers() { - _builder.RegisterGeneric(typeof(AzureInitializer<>)) - .As(typeof(IAzureInitializer<>)) + _builder.RegisterGeneric(typeof(Initializer<>)) + .As(typeof(IInitializer<>)) .InstancePerDependency(); return this; diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index 55b748c..9126df2 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -28,8 +28,8 @@ public AzureSearchBuilder(IServiceContainer serviceContainer) internal AzureSearchBuilder RegisterInitializers() { _ = _container.Register( - typeof(IAzureInitializer<>), - typeof(AzureInitializer<>)); + typeof(IInitializer<>), + typeof(Initializer<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index 061b01a..e067651 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -28,7 +28,7 @@ public AzureSearchBuilder(IServiceCollection serviceCollection) internal AzureSearchBuilder RegisterInitializers() { - _serviceCollection.TryAddScoped(typeof(IAzureInitializer<>), typeof(AzureInitializer<>)); + _serviceCollection.TryAddScoped(typeof(IInitializer<>), typeof(Initializer<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index 0c67897..1aceebd 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -29,8 +29,8 @@ public AzureSearchBuilder(IRegister composingRegister) internal AzureSearchBuilder RegisterInitializers() { _composingRegister.Register( - typeof(IAzureInitializer<>), - typeof(AzureInitializer<>)); + typeof(IInitializer<>), + typeof(Initializer<>)); return this; } diff --git a/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs b/src/Cogworks.AzureSearch/Initializers/Initializer.cs similarity index 87% rename from src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs rename to src/Cogworks.AzureSearch/Initializers/Initializer.cs index 9273f62..a3e5f32 100644 --- a/src/Cogworks.AzureSearch/Initializers/AzureInitializer.cs +++ b/src/Cogworks.AzureSearch/Initializers/Initializer.cs @@ -8,13 +8,13 @@ namespace Cogworks.AzureSearch.Initializers { - internal class AzureInitializer : IAzureInitializer + internal class Initializer : IInitializer where TAzureModel : class, IAzureModel, new() { private readonly AzureSearchIndexOption _azureSearchIndexOption; private readonly IAzureIndexOperation _azureIndexOperation; - public AzureInitializer(AzureSearchIndexOption azureSearchIndexOption, IAzureIndexOperation azureIndexOperation) + public Initializer(AzureSearchIndexOption azureSearchIndexOption, IAzureIndexOperation azureIndexOperation) { _azureSearchIndexOption = azureSearchIndexOption; _azureIndexOperation = azureIndexOperation; diff --git a/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs b/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs similarity index 62% rename from src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs rename to src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs index 255fd10..86df6fd 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Initializers/IAzureInitializer.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.Interfaces.Initializers { - public interface IAzureInitializer where TAzureModel : class, IAzureModel, new() + public interface IInitializer where TAzureModel : class, IAzureModel, new() { Task InitializeAsync(); } diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index a97becd..d2d6916 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -44,19 +44,19 @@ public AutofacIocExtensionTests() [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { // Arrange @@ -80,19 +80,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { @@ -109,7 +109,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index 61a5d9c..e6ddeb1 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -43,18 +43,18 @@ public LightInjectIocExtensionTests() [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { @@ -79,19 +79,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { @@ -108,7 +108,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index 5f2a980..1629bff 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -42,19 +42,19 @@ public MicrosoftIocExtensionTests() [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { @@ -79,19 +79,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { @@ -108,7 +108,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index cbd0dc9..729eee3 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -49,19 +49,19 @@ public UmbracoIocExtensionTests() [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { @@ -86,19 +86,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IAzureSearchRepository))] [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { @@ -115,7 +115,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IAzureIndexOperation))] [InlineData(typeof(IAzureDocumentOperation))] [InlineData(typeof(IIndex))] - [InlineData(typeof(IAzureInitializer))] + [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { From 13117f39a31ea6007183ee14584730db2120872c Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:02:51 +0200 Subject: [PATCH 19/31] refactor: renamed operations --- .../Builders/AzureSearchBuilder.cs | 12 +++--- .../Builders/AzureSearchBuilder.cs | 12 +++--- .../Builders/AzureSearchBuilder.cs | 8 ++-- .../Builders/AzureSearchBuilder.cs | 12 +++--- src/Cogworks.AzureSearch/Indexes/Index.cs | 4 +- .../Initializers/Initializer.cs | 14 +++---- ...mentOperation.cs => IDocumentOperation.cs} | 2 +- ...reIndexOperation.cs => IIndexOperation.cs} | 2 +- ...archRepository.cs => ISearchRepository.cs} | 6 +-- ...umentOperation.cs => DocumentOperation.cs} | 4 +- ...ureIndexOperation.cs => IndexOperation.cs} | 4 +- ...earchRepository.cs => SearchRepository.cs} | 12 +++--- .../AutofacIocExtensionTests.cs | 42 +++++++++---------- .../LightInjectIocExtensionTests.cs | 42 +++++++++---------- .../MicrosoftIocExtensionTests.cs | 42 +++++++++---------- .../UmbracoIocExtensionTests.cs | 42 +++++++++---------- .../Operations/DocumentOperationTests.cs | 24 +++++------ .../Operations/IndexOperationTests.cs | 42 +++++++++---------- .../TestBase.cs | 8 ++-- 19 files changed, 167 insertions(+), 167 deletions(-) rename src/Cogworks.AzureSearch/Interfaces/Operations/{IAzureDocumentOperation.cs => IDocumentOperation.cs} (84%) rename src/Cogworks.AzureSearch/Interfaces/Operations/{IAzureIndexOperation.cs => IIndexOperation.cs} (73%) rename src/Cogworks.AzureSearch/Interfaces/Repositories/{IAzureSearchRepository.cs => ISearchRepository.cs} (66%) rename src/Cogworks.AzureSearch/Operations/{AzureDocumentOperation.cs => DocumentOperation.cs} (96%) rename src/Cogworks.AzureSearch/Operations/{AzureIndexOperation.cs => IndexOperation.cs} (95%) rename src/Cogworks.AzureSearch/Repositories/{AzureSearchRepository.cs => SearchRepository.cs} (84%) diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index 3e9957d..7b9c92f 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -99,8 +99,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { - _ = _builder.RegisterGeneric(typeof(AzureSearchRepository<>)) - .As(typeof(IAzureSearchRepository<>)) + _ = _builder.RegisterGeneric(typeof(SearchRepository<>)) + .As(typeof(ISearchRepository<>)) .InstancePerDependency(); return this; @@ -117,12 +117,12 @@ internal AzureSearchBuilder RegisterSearchers() internal AzureSearchBuilder RegisterOperations() { - _ = _builder.RegisterGeneric(typeof(AzureDocumentOperation<>)) - .As(typeof(IAzureDocumentOperation<>)) + _ = _builder.RegisterGeneric(typeof(DocumentOperation<>)) + .As(typeof(IDocumentOperation<>)) .InstancePerDependency(); - _ = _builder.RegisterGeneric(typeof(AzureIndexOperation<>)) - .As(typeof(IAzureIndexOperation<>)) + _ = _builder.RegisterGeneric(typeof(IndexOperation<>)) + .As(typeof(IIndexOperation<>)) .InstancePerDependency(); return this; diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index 9126df2..8a3cd96 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -98,8 +98,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { _ = _container.Register( - typeof(IAzureSearchRepository<>), - typeof(AzureSearchRepository<>)); + typeof(ISearchRepository<>), + typeof(SearchRepository<>)); return this; } @@ -115,13 +115,13 @@ internal AzureSearchBuilder RegisterSearchers() internal AzureSearchBuilder RegisterOperations() { _ = _container.Register( - typeof(IAzureDocumentOperation<>), - typeof(AzureDocumentOperation<>), + typeof(IDocumentOperation<>), + typeof(DocumentOperation<>), new PerContainerLifetime()); _ = _container.Register( - typeof(IAzureIndexOperation<>), - typeof(AzureIndexOperation<>), + typeof(IIndexOperation<>), + typeof(IndexOperation<>), new PerContainerLifetime()); return this; diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index e067651..70f865a 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -85,8 +85,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { _serviceCollection.TryAddScoped( - typeof(IAzureSearchRepository<>), - typeof(AzureSearchRepository<>)); + typeof(ISearchRepository<>), + typeof(SearchRepository<>)); return this; } @@ -100,9 +100,9 @@ internal AzureSearchBuilder RegisterSearchers() internal AzureSearchBuilder RegisterOperations() { - _serviceCollection.TryAddScoped(typeof(IAzureDocumentOperation<>), typeof(AzureDocumentOperation<>)); + _serviceCollection.TryAddScoped(typeof(IDocumentOperation<>), typeof(DocumentOperation<>)); - _serviceCollection.TryAddScoped(typeof(IAzureIndexOperation<>), typeof(AzureIndexOperation<>)); + _serviceCollection.TryAddScoped(typeof(IIndexOperation<>), typeof(IndexOperation<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index 1aceebd..b7c12c4 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -99,8 +99,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { _composingRegister.Register( - typeof(IAzureSearchRepository<>), - typeof(AzureSearchRepository<>)); + typeof(ISearchRepository<>), + typeof(SearchRepository<>)); return this; } @@ -117,12 +117,12 @@ internal AzureSearchBuilder RegisterSearchers() internal AzureSearchBuilder RegisterOperations() { _composingRegister.Register( - typeof(IAzureDocumentOperation<>), - typeof(AzureDocumentOperation<>)); + typeof(IDocumentOperation<>), + typeof(DocumentOperation<>)); _composingRegister.Register( - typeof(IAzureIndexOperation<>), - typeof(AzureIndexOperation<>)); + typeof(IIndexOperation<>), + typeof(IndexOperation<>)); return this; } diff --git a/src/Cogworks.AzureSearch/Indexes/Index.cs b/src/Cogworks.AzureSearch/Indexes/Index.cs index e907275..1a336b6 100644 --- a/src/Cogworks.AzureSearch/Indexes/Index.cs +++ b/src/Cogworks.AzureSearch/Indexes/Index.cs @@ -9,9 +9,9 @@ namespace Cogworks.AzureSearch.Indexes { internal class Index : IIndex where TAzureModel : class, IAzureModel, new() { - private readonly IAzureDocumentOperation _documentOperation; + private readonly IDocumentOperation _documentOperation; - public Index(IAzureDocumentOperation documentOperation) + public Index(IDocumentOperation documentOperation) => _documentOperation = documentOperation; public async Task AddOrUpdateDocumentAsync(TAzureModel model) diff --git a/src/Cogworks.AzureSearch/Initializers/Initializer.cs b/src/Cogworks.AzureSearch/Initializers/Initializer.cs index a3e5f32..6772b6b 100644 --- a/src/Cogworks.AzureSearch/Initializers/Initializer.cs +++ b/src/Cogworks.AzureSearch/Initializers/Initializer.cs @@ -12,36 +12,36 @@ internal class Initializer : IInitializer where TAzureModel : class, IAzureModel, new() { private readonly AzureSearchIndexOption _azureSearchIndexOption; - private readonly IAzureIndexOperation _azureIndexOperation; + private readonly IIndexOperation _indexOperation; - public Initializer(AzureSearchIndexOption azureSearchIndexOption, IAzureIndexOperation azureIndexOperation) + public Initializer(AzureSearchIndexOption azureSearchIndexOption, IIndexOperation indexOperation) { _azureSearchIndexOption = azureSearchIndexOption; - _azureIndexOperation = azureIndexOperation; + _indexOperation = indexOperation; } public async Task InitializeAsync() { if (_azureSearchIndexOption.Recreate) { - await _azureIndexOperation.IndexDeleteAsync(); + await _indexOperation.IndexDeleteAsync(); } try { - await _azureIndexOperation.IndexCreateOrUpdateAsync(); + await _indexOperation.IndexCreateOrUpdateAsync(); } catch (Exception) { if (_azureSearchIndexOption.RecreateOnUpdateFailure) { - await _azureIndexOperation.IndexDeleteAsync(); + await _indexOperation.IndexDeleteAsync(); } } try { - await _azureIndexOperation.IndexCreateOrUpdateAsync(); + await _indexOperation.IndexCreateOrUpdateAsync(); } catch (Exception exception) { diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureDocumentOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs similarity index 84% rename from src/Cogworks.AzureSearch/Interfaces/Operations/IAzureDocumentOperation.cs rename to src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs index 001b608..fa152de 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureDocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs @@ -5,7 +5,7 @@ namespace Cogworks.AzureSearch.Interfaces.Operations { - public interface IAzureDocumentOperation where TAzureModel : class, IAzureModel, new() + public interface IDocumentOperation where TAzureModel : class, IAzureModel, new() { Task AddOrUpdateDocumentAsync(TAzureModel model); diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs similarity index 73% rename from src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs rename to src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs index 8afe277..0213dab 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IAzureIndexOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.Interfaces.Operations { - public interface IAzureIndexOperation where TAzureModel : class, IAzureModel, new() + public interface IIndexOperation where TAzureModel : class, IAzureModel, new() { Task IndexExistsAsync(); diff --git a/src/Cogworks.AzureSearch/Interfaces/Repositories/IAzureSearchRepository.cs b/src/Cogworks.AzureSearch/Interfaces/Repositories/ISearchRepository.cs similarity index 66% rename from src/Cogworks.AzureSearch/Interfaces/Repositories/IAzureSearchRepository.cs rename to src/Cogworks.AzureSearch/Interfaces/Repositories/ISearchRepository.cs index 0c2242e..6d29e20 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Repositories/IAzureSearchRepository.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Repositories/ISearchRepository.cs @@ -4,9 +4,9 @@ namespace Cogworks.AzureSearch.Interfaces.Repositories { - public interface IAzureSearchRepository : - IAzureDocumentOperation, - IAzureIndexOperation, + public interface ISearchRepository : + IDocumentOperation, + IIndexOperation, IAzureSearch where TAzureModel : class, IAzureModel, new() { diff --git a/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs b/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs similarity index 96% rename from src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs rename to src/Cogworks.AzureSearch/Operations/DocumentOperation.cs index 2eb3925..e212d60 100644 --- a/src/Cogworks.AzureSearch/Operations/AzureDocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs @@ -12,14 +12,14 @@ namespace Cogworks.AzureSearch.Operations { - public class AzureDocumentOperation : IAzureDocumentOperation + public class DocumentOperation : IDocumentOperation where TAzureModel : class, IAzureModel, new() { private readonly IDocumentOperationWrapper _documentOperationWrapper; private const int BatchOperationSize = 500; - public AzureDocumentOperation(IDocumentOperationWrapper documentOperationWrapper) + public DocumentOperation(IDocumentOperationWrapper documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; public async Task AddOrUpdateDocumentAsync(TAzureModel model) diff --git a/src/Cogworks.AzureSearch/Operations/AzureIndexOperation.cs b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs similarity index 95% rename from src/Cogworks.AzureSearch/Operations/AzureIndexOperation.cs rename to src/Cogworks.AzureSearch/Operations/IndexOperation.cs index 4365bcd..749c00c 100644 --- a/src/Cogworks.AzureSearch/Operations/AzureIndexOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs @@ -7,13 +7,13 @@ namespace Cogworks.AzureSearch.Operations { - public class AzureIndexOperation : IAzureIndexOperation + public class IndexOperation : IIndexOperation where TAzureModel : class, IAzureModel, new() { private readonly AzureIndexDefinition _azureIndexDefinition; private readonly IIndexOperationWrapper _indexOperationWrapper; - public AzureIndexOperation( + public IndexOperation( AzureIndexDefinition azureIndexDefinition, IIndexOperationWrapper indexOperationWrapper) { diff --git a/src/Cogworks.AzureSearch/Repositories/AzureSearchRepository.cs b/src/Cogworks.AzureSearch/Repositories/SearchRepository.cs similarity index 84% rename from src/Cogworks.AzureSearch/Repositories/AzureSearchRepository.cs rename to src/Cogworks.AzureSearch/Repositories/SearchRepository.cs index a3e83c9..1780dc5 100644 --- a/src/Cogworks.AzureSearch/Repositories/AzureSearchRepository.cs +++ b/src/Cogworks.AzureSearch/Repositories/SearchRepository.cs @@ -8,16 +8,16 @@ namespace Cogworks.AzureSearch.Repositories { - internal class AzureSearchRepository : IAzureSearchRepository + internal class SearchRepository : ISearchRepository where TAzureModel : class, IAzureModel, new() { - private readonly IAzureIndexOperation _indexOperation; - private readonly IAzureDocumentOperation _documentOperation; + private readonly IIndexOperation _indexOperation; + private readonly IDocumentOperation _documentOperation; private readonly IAzureSearch _search; - public AzureSearchRepository( - IAzureIndexOperation indexOperation, - IAzureDocumentOperation documentOperation, + public SearchRepository( + IIndexOperation indexOperation, + IDocumentOperation documentOperation, IAzureSearch search) { _indexOperation = indexOperation; diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index d2d6916..907f43d 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -39,21 +39,21 @@ public AutofacIocExtensionTests() } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] @@ -76,21 +76,21 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] @@ -105,9 +105,9 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index e6ddeb1..3f799b7 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -38,21 +38,21 @@ public LightInjectIocExtensionTests() } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] @@ -75,21 +75,21 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] @@ -104,9 +104,9 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index 1629bff..7e43848 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -38,21 +38,21 @@ public MicrosoftIocExtensionTests() } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] @@ -75,21 +75,21 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] @@ -104,9 +104,9 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index 729eee3..12cc4a0 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -45,21 +45,21 @@ public UmbracoIocExtensionTests() } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] @@ -82,21 +82,21 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] @@ -111,9 +111,9 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(IAzureSearchRepository))] - [InlineData(typeof(IAzureIndexOperation))] - [InlineData(typeof(IAzureDocumentOperation))] + [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IIndexOperation))] + [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs index 9843f5c..3058c59 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs @@ -15,12 +15,12 @@ namespace Cogworks.AzureSearch.UnitTests.Operations { public class DocumentOperationTests : TestBase { - private readonly IAzureDocumentOperation _azureDocumentOperation; + private readonly IDocumentOperation _documentOperation; public DocumentOperationTests() - => _azureDocumentOperation = new AzureSearchRepository( - AzureIndexOperationService, - AzureDocumentOperationService, + => _documentOperation = new SearchRepository( + IndexOperationService, + DocumentOperationService, Search); [Theory] @@ -51,7 +51,7 @@ public async Task Should_AddOrUpdateDocuments(int documentsCount) .Returns(new TestResponse(documentIndexResult)); // Act - var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); + var result = await _documentOperation.AddOrUpdateDocumentsAsync(testDocuments); // Assert Assert.NotNull(result); @@ -105,7 +105,7 @@ public async Task Should_Fail_When_AddOrUpdateDocumentsPartiallyFail(int documen .Returns(new TestResponse(documentIndexResult)); // Act - var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); + var result = await _documentOperation.AddOrUpdateDocumentsAsync(testDocuments); // Assert Assert.NotNull(result); @@ -149,7 +149,7 @@ public async Task Should_Succeeded_When_TryToAddEmptyDocuments() .Returns(documentIndexResult); // Act - var result = await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments); + var result = await _documentOperation.AddOrUpdateDocumentsAsync(testDocuments); // Assert Assert.NotNull(result); @@ -174,7 +174,7 @@ public async Task Should_Succeeded_When_TryToRemoveEmptyDocuments() .Returns(documentIndexResult); // Act - var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); + var result = await _documentOperation.TryRemoveDocumentsAsync(testDocuments); // Assert Assert.NotNull(result); @@ -211,7 +211,7 @@ public async Task Should_Succeeded_When_TryRemoveDocuments(int documentsCount) .Returns(new TestResponse(documentIndexResult)); // Act - var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); + var result = await _documentOperation.TryRemoveDocumentsAsync(testDocuments); // Assert Assert.NotNull(result); @@ -256,7 +256,7 @@ public async Task Should_Fail_When_TryRemoveNotExistingDocuments(int documentsCo .Returns(new TestResponse(documentIndexResult)); // Act - var result = await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments); + var result = await _documentOperation.TryRemoveDocumentsAsync(testDocuments); // Assert Assert.NotNull(result); @@ -293,7 +293,7 @@ public async Task Should_ThrowDomainException_When_IssueWith_TryAddOrUpdateDocum // Assert var domainException = await Assert.ThrowsAsync(async () => - await _azureDocumentOperation.AddOrUpdateDocumentsAsync(testDocuments)); + await _documentOperation.AddOrUpdateDocumentsAsync(testDocuments)); Assert.NotNull(domainException); Assert.Equal("Test Error", domainException.Message); @@ -337,7 +337,7 @@ public async Task Should_ThrowDomainException_When_IssueWith_TryRemoveDocuments( // Assert var domainException = await Assert.ThrowsAsync(async () => - await _azureDocumentOperation.TryRemoveDocumentsAsync(testDocuments)); + await _documentOperation.TryRemoveDocumentsAsync(testDocuments)); Assert.NotNull(domainException); Assert.Equal("Test Error", domainException.Message); diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs index 7021a3a..2b770a4 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs @@ -16,12 +16,12 @@ namespace Cogworks.AzureSearch.UnitTests.Operations { public class IndexOperationTests : TestBase { - private readonly IAzureIndexOperation _azureIndexOperation; + private readonly IIndexOperation _indexOperation; public IndexOperationTests() - => _azureIndexOperation = new AzureSearchRepository( - AzureIndexOperationService, - AzureDocumentOperationService, + => _indexOperation = new SearchRepository( + IndexOperationService, + DocumentOperationService, Search); #region Exists Tests @@ -34,7 +34,7 @@ public async Task Should_ReturnTrue_When_IndexExists() .Returns(true); // Act - var result = await _azureIndexOperation.IndexExistsAsync(); + var result = await _indexOperation.IndexExistsAsync(); // Assert Assert.True(result); @@ -48,7 +48,7 @@ public async Task Should_ReturnFalse_When_IndexNotExists() .Returns(false); // Act - var result = await _azureIndexOperation.IndexExistsAsync(); + var result = await _indexOperation.IndexExistsAsync(); // Assert Assert.False(result); @@ -64,7 +64,7 @@ public async Task Should_ThrowException_When_IssuesWithConnection() Fixture.Create())); // Assert - var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexExistsAsync()); + var domainException = await Assert.ThrowsAsync(async () => await _indexOperation.IndexExistsAsync()); Assert.NotNull(domainException); Assert.Equal("Test Error", domainException.Message); @@ -96,7 +96,7 @@ public async Task Should_DeleteIndex_When_IndexExists() { // Act - var deleteResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); + var deleteResult = await Record.ExceptionAsync(async () => await _indexOperation.IndexDeleteAsync()); // Assert Assert.Null(deleteResult); @@ -122,7 +122,7 @@ public async Task Should_ThrowException_When_IssuesWithConnection_On_DeletingInd Fixture.Create())); // Act - var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexDeleteAsync()); + var domainException = await Assert.ThrowsAsync(async () => await _indexOperation.IndexDeleteAsync()); // Assert Assert.NotNull(domainException); @@ -144,7 +144,7 @@ public async Task Should_CreateOrUpdateIndex() .Returns(createdOrUpdatedIndex); // Act - var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); + var indexResult = await Record.ExceptionAsync(async () => await _indexOperation.IndexCreateOrUpdateAsync()); // Assert Assert.Null(indexResult); @@ -159,13 +159,13 @@ public async Task Should_CreateOrUpdateCustomIndex() var customModelDefinition = new AzureIndexDefinition(index); - var customIndexOperationService = new AzureIndexOperation( + var customIndexOperationService = new IndexOperation( customModelDefinition, IndexOperationWrapper); - var azureIndexOperation = new AzureSearchRepository( + var azureIndexOperation = new SearchRepository( customIndexOperationService, - AzureDocumentOperationService, + DocumentOperationService, Search); // Act @@ -185,7 +185,7 @@ public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingIndex() Fixture.Create())); // Act - var domainException = await Assert.ThrowsAsync(async () => await _azureIndexOperation.IndexCreateOrUpdateAsync()); + var domainException = await Assert.ThrowsAsync(async () => await _indexOperation.IndexCreateOrUpdateAsync()); // Assert Assert.NotNull(domainException); @@ -201,13 +201,13 @@ public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomInde var customModelDefinition = new AzureIndexDefinition(index); - var customIndexOperationService = new AzureIndexOperation( + var customIndexOperationService = new IndexOperation( customModelDefinition, IndexOperationWrapper); - var azureIndexOperation = new AzureSearchRepository( + var azureIndexOperation = new SearchRepository( customIndexOperationService, - AzureDocumentOperationService, + DocumentOperationService, Search); _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) @@ -236,7 +236,7 @@ public async Task Should_ClearIndex_When_IndexExists() .Returns(true); // Act - var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + var indexResult = await Record.ExceptionAsync(async () => await _indexOperation.IndexClearAsync()); // Assert Assert.Null(indexResult); @@ -250,7 +250,7 @@ public async Task Should_ClearIndex_When_IndexNotExists() .Returns(false); // Act - var indexResult = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + var indexResult = await Record.ExceptionAsync(async () => await _indexOperation.IndexClearAsync()); // Assert Assert.Null(indexResult); @@ -269,7 +269,7 @@ public async Task Should_ThrowException_When_IssueWithConnectionOnClearingIndex( Fixture.Create())); // Act - var domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + var domainException = await Record.ExceptionAsync(async () => await _indexOperation.IndexClearAsync()); // Assert Assert.NotNull(domainException); @@ -289,7 +289,7 @@ public async Task Should_ThrowException_When_IssueWithConnectionOnClearingIndex( Fixture.Create())); // Act - domainException = await Record.ExceptionAsync(async () => await _azureIndexOperation.IndexClearAsync()); + domainException = await Record.ExceptionAsync(async () => await _indexOperation.IndexClearAsync()); // Assert Assert.NotNull(domainException); diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs index f83983a..39852c2 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs @@ -22,8 +22,8 @@ public abstract class TestBase protected readonly AzureIndexDefinition TestDocumentModelDefinition; protected readonly IAzureSearch Search; - protected readonly IAzureDocumentOperation AzureDocumentOperationService; - protected readonly IAzureIndexOperation AzureIndexOperationService; + protected readonly IDocumentOperation DocumentOperationService; + protected readonly IIndexOperation IndexOperationService; protected TestBase() { @@ -34,10 +34,10 @@ protected TestBase() Search = Substitute.For>(); - AzureDocumentOperationService = new AzureDocumentOperation( + DocumentOperationService = new DocumentOperation( DocumentOperationWrapper); - AzureIndexOperationService = new AzureIndexOperation( + IndexOperationService = new IndexOperation( TestDocumentModelDefinition, IndexOperationWrapper); } From 1d03a50f1a93593002146612fe5157b8a48cfa8b Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:05:02 +0200 Subject: [PATCH 20/31] refactor: renamed repository --- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../{ISearchRepository.cs => IRepository.cs} | 2 +- .../{SearchRepository.cs => Repository.cs} | 4 ++-- .../AutofacIocExtensionTests.cs | 14 +++++++------- .../LightInjectIocExtensionTests.cs | 14 +++++++------- .../MicrosoftIocExtensionTests.cs | 14 +++++++------- .../UmbracoIocExtensionTests.cs | 14 +++++++------- .../Operations/DocumentOperationTests.cs | 2 +- .../Operations/IndexOperationTests.cs | 6 +++--- 12 files changed, 43 insertions(+), 43 deletions(-) rename src/Cogworks.AzureSearch/Interfaces/Repositories/{ISearchRepository.cs => IRepository.cs} (87%) rename src/Cogworks.AzureSearch/Repositories/{SearchRepository.cs => Repository.cs} (95%) diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index 7b9c92f..67b08e5 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -99,8 +99,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { - _ = _builder.RegisterGeneric(typeof(SearchRepository<>)) - .As(typeof(ISearchRepository<>)) + _ = _builder.RegisterGeneric(typeof(Repository<>)) + .As(typeof(IRepository<>)) .InstancePerDependency(); return this; diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index 8a3cd96..a8b2e0e 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -98,8 +98,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { _ = _container.Register( - typeof(ISearchRepository<>), - typeof(SearchRepository<>)); + typeof(IRepository<>), + typeof(Repository<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index 70f865a..c3893e0 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -85,8 +85,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { _serviceCollection.TryAddScoped( - typeof(ISearchRepository<>), - typeof(SearchRepository<>)); + typeof(IRepository<>), + typeof(Repository<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index b7c12c4..6b6b485 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -99,8 +99,8 @@ internal AzureSearchBuilder RegisterWrappers() internal AzureSearchBuilder RegisterRepositories() { _composingRegister.Register( - typeof(ISearchRepository<>), - typeof(SearchRepository<>)); + typeof(IRepository<>), + typeof(Repository<>)); return this; } diff --git a/src/Cogworks.AzureSearch/Interfaces/Repositories/ISearchRepository.cs b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs similarity index 87% rename from src/Cogworks.AzureSearch/Interfaces/Repositories/ISearchRepository.cs rename to src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs index 6d29e20..75cf724 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Repositories/ISearchRepository.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs @@ -4,7 +4,7 @@ namespace Cogworks.AzureSearch.Interfaces.Repositories { - public interface ISearchRepository : + public interface IRepository : IDocumentOperation, IIndexOperation, IAzureSearch diff --git a/src/Cogworks.AzureSearch/Repositories/SearchRepository.cs b/src/Cogworks.AzureSearch/Repositories/Repository.cs similarity index 95% rename from src/Cogworks.AzureSearch/Repositories/SearchRepository.cs rename to src/Cogworks.AzureSearch/Repositories/Repository.cs index 1780dc5..b7cc97f 100644 --- a/src/Cogworks.AzureSearch/Repositories/SearchRepository.cs +++ b/src/Cogworks.AzureSearch/Repositories/Repository.cs @@ -8,14 +8,14 @@ namespace Cogworks.AzureSearch.Repositories { - internal class SearchRepository : ISearchRepository + internal class Repository : IRepository where TAzureModel : class, IAzureModel, new() { private readonly IIndexOperation _indexOperation; private readonly IDocumentOperation _documentOperation; private readonly IAzureSearch _search; - public SearchRepository( + public Repository( IIndexOperation indexOperation, IDocumentOperation documentOperation, IAzureSearch search) diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index 907f43d..7bae278 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -39,19 +39,19 @@ public AutofacIocExtensionTests() } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] @@ -76,19 +76,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] @@ -105,7 +105,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index 3f799b7..93232ed 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -38,19 +38,19 @@ public LightInjectIocExtensionTests() } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IAzureSearch))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] @@ -75,19 +75,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] @@ -104,7 +104,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index 7e43848..e8a9d8b 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -38,19 +38,19 @@ public MicrosoftIocExtensionTests() } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] @@ -75,19 +75,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] @@ -104,7 +104,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index 12cc4a0..aa32f5d 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -45,19 +45,19 @@ public UmbracoIocExtensionTests() } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] @@ -82,19 +82,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IAzureSearch))] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] @@ -111,7 +111,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp } [Theory] - [InlineData(typeof(ISearchRepository))] + [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs index 3058c59..eaacd75 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs @@ -18,7 +18,7 @@ public class DocumentOperationTests : TestBase private readonly IDocumentOperation _documentOperation; public DocumentOperationTests() - => _documentOperation = new SearchRepository( + => _documentOperation = new Repository( IndexOperationService, DocumentOperationService, Search); diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs index 2b770a4..aedce16 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs @@ -19,7 +19,7 @@ public class IndexOperationTests : TestBase private readonly IIndexOperation _indexOperation; public IndexOperationTests() - => _indexOperation = new SearchRepository( + => _indexOperation = new Repository( IndexOperationService, DocumentOperationService, Search); @@ -163,7 +163,7 @@ public async Task Should_CreateOrUpdateCustomIndex() customModelDefinition, IndexOperationWrapper); - var azureIndexOperation = new SearchRepository( + var azureIndexOperation = new Repository( customIndexOperationService, DocumentOperationService, Search); @@ -205,7 +205,7 @@ public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomInde customModelDefinition, IndexOperationWrapper); - var azureIndexOperation = new SearchRepository( + var azureIndexOperation = new Repository( customIndexOperationService, DocumentOperationService, Search); From 4c1ed8bb880c992037a0669f7092203280b89496 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:07:42 +0200 Subject: [PATCH 21/31] refactor: renamed mappers --- .../{AzureSearchParametersMapper.cs => ParametersMapper.cs} | 2 +- src/Cogworks.AzureSearch/Searchers/AzureSearch.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Cogworks.AzureSearch/Mappers/{AzureSearchParametersMapper.cs => ParametersMapper.cs} (98%) diff --git a/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs b/src/Cogworks.AzureSearch/Mappers/ParametersMapper.cs similarity index 98% rename from src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs rename to src/Cogworks.AzureSearch/Mappers/ParametersMapper.cs index 98c6f4e..058a0bd 100644 --- a/src/Cogworks.AzureSearch/Mappers/AzureSearchParametersMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/ParametersMapper.cs @@ -6,7 +6,7 @@ namespace Cogworks.AzureSearch.Mappers { - public static class AzureSearchParametersMapper + public static class ParametersMapper { internal static SearchOptions Map(AzureSearchParameters azureSearchParameters) { diff --git a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs index 46c0261..8a3e4a3 100644 --- a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs @@ -19,7 +19,7 @@ public AzureSearch(IDocumentOperationWrapper documentOperationWrapp public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) { var searchText = GetSearchText(keyword); - var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); + var parameters = ParametersMapper.Map(azureSearchParameters); var results = _documentOperationWrapper.Search($"{searchText}", parameters); return SearchResultMapper.Map( @@ -31,7 +31,7 @@ public SearchResult Search(string keyword, AzureSearchParameters az public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) { var searchText = GetSearchText(keyword); - var parameters = AzureSearchParametersMapper.Map(azureSearchParameters); + var parameters = ParametersMapper.Map(azureSearchParameters); var results = await _documentOperationWrapper.SearchAsync(searchText, parameters); return SearchResultMapper.Map( From e6856eaff1b93c16141b777bdc6858907f644cb6 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:11:16 +0200 Subject: [PATCH 22/31] refactor: renamed models --- .../Builders/AzureSearchBuilder.cs | 12 ++-- .../Builders/AzureSearchBuilder.cs | 12 ++-- .../Builders/AzureSearchBuilder.cs | 12 ++-- .../Builders/AzureSearchBuilder.cs | 12 ++-- .../Builder/IAzureSearchBuilder.cs | 8 +-- src/Cogworks.AzureSearch/Indexes/Index.cs | 10 ++-- .../Initializers/Initializer.cs | 2 +- .../Interfaces/Indexes/IIndex.cs | 10 ++-- .../Interfaces/Initializers/IInitializer.cs | 2 +- .../Operations/IDocumentOperation.cs | 10 ++-- .../Interfaces/Operations/IIndexOperation.cs | 2 +- .../Interfaces/Repositories/IRepository.cs | 2 +- .../Interfaces/Searches/IAzureSearch.cs | 6 +- .../Wrappers/IDocumentOperationWrapper.cs | 2 +- .../Wrappers/IIndexOperationWrapper.cs | 4 +- .../Mappers/ParametersMapper.cs | 56 +++++++++---------- .../Mappers/SearchResultMapper.cs | 2 +- .../AzureBatchDocumentsOperationResult.cs | 16 ------ .../Dtos/BatchDocumentsOperationResult.cs | 16 ++++++ ...onResult.cs => DocumentOperationResult.cs} | 2 +- ...ationResult.cs => IndexOperationResult.cs} | 2 +- .../Models/Dtos/SearchResult.cs | 2 +- .../Models/Dtos/SearchResultItem.cs | 2 +- .../Models/{IAzureModel.cs => IModel.cs} | 2 +- ...zureModelIdentity.cs => IModelIdentity.cs} | 2 +- ...eIndexDefinition.cs => IndexDefinition.cs} | 6 +- ...earchParameters.cs => SearchParameters.cs} | 2 +- .../Operations/DocumentOperation.cs | 22 ++++---- .../Operations/IndexOperation.cs | 18 +++--- .../Repositories/Repository.cs | 18 +++--- .../Searchers/AzureSearch.cs | 18 +++--- .../Searchers/BaseDomainSearch.cs | 10 ++-- .../Wrappers/DocumentOperationWrapper.cs | 6 +- .../Wrappers/IndexOperationWrapper.cs | 4 +- .../AutofacIocExtensionTests.cs | 6 +- .../Models/FirstTestDocumentModel.cs | 2 +- .../Models/NotRegistredTestDocumentModel.cs | 2 +- .../Models/SecondTestDocumentModel.cs | 2 +- .../Models/ThirdTestDocumentModel.cs | 2 +- .../Searchers/CustomTestSearch.cs | 2 +- .../LightInjectIocExtensionTests.cs | 6 +- .../Models/FirstTestDocumentModel.cs | 2 +- .../Models/NotRegistredTestDocumentModel.cs | 2 +- .../Models/SecondTestDocumentModel.cs | 2 +- .../Models/ThirdTestDocumentModel.cs | 2 +- .../Searchers/CustomTestSearch.cs | 2 +- .../MicrosoftIocExtensionTests.cs | 6 +- .../Models/FirstTestDocumentModel.cs | 2 +- .../Models/NotRegistredTestDocumentModel.cs | 2 +- .../Models/SecondTestDocumentModel.cs | 2 +- .../Models/ThirdTestDocumentModel.cs | 2 +- .../Searchers/CustomTestSearch.cs | 2 +- .../Models/FirstTestDocumentModel.cs | 2 +- .../Models/NotRegistredTestDocumentModel.cs | 2 +- .../Models/SecondTestDocumentModel.cs | 2 +- .../Models/ThirdTestDocumentModel.cs | 2 +- .../Searchers/CustomTestSearch.cs | 2 +- .../UmbracoIocExtensionTests.cs | 6 +- .../Models/TestDocumentModel.cs | 2 +- .../Operations/IndexOperationTests.cs | 4 +- .../TestBase.cs | 4 +- 61 files changed, 193 insertions(+), 193 deletions(-) delete mode 100644 src/Cogworks.AzureSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs create mode 100644 src/Cogworks.AzureSearch/Models/Dtos/BatchDocumentsOperationResult.cs rename src/Cogworks.AzureSearch/Models/Dtos/{AzureDocumentOperationResult.cs => DocumentOperationResult.cs} (86%) rename src/Cogworks.AzureSearch/Models/Dtos/{AzureIndexOperationResult.cs => IndexOperationResult.cs} (77%) rename src/Cogworks.AzureSearch/Models/{IAzureModel.cs => IModel.cs} (62%) rename src/Cogworks.AzureSearch/Models/{IAzureModelIdentity.cs => IModelIdentity.cs} (61%) rename src/Cogworks.AzureSearch/Models/{AzureIndexDefinition.cs => IndexDefinition.cs} (60%) rename src/Cogworks.AzureSearch/Models/{AzureSearchParameters.cs => SearchParameters.cs} (95%) diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index 67b08e5..f263d37 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -56,9 +56,9 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred } public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { - _ = _builder.Register(_ => new AzureIndexDefinition(indexName)) + _ = _builder.Register(_ => new IndexDefinition(indexName)) .AsSelf() .SingleInstance(); @@ -66,9 +66,9 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) } public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { - _ = _builder.Register(_ => new AzureIndexDefinition(customIndex)) + _ = _builder.Register(_ => new IndexDefinition(customIndex)) .AsSelf() .SingleInstance(); @@ -129,7 +129,7 @@ internal AzureSearchBuilder RegisterOperations() } public IAzureSearchBuilder RegisterDomainSearcher() - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { @@ -142,7 +142,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index a8b2e0e..b7915b8 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -56,20 +56,20 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred } public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { _ = _container.Register( - _ => new AzureIndexDefinition(indexName), + _ => new IndexDefinition(indexName), new PerContainerLifetime()); return this; } public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { _ = _container.Register( - _ => new AzureIndexDefinition(customIndex), + _ => new IndexDefinition(customIndex), new PerContainerLifetime()); return this; @@ -128,7 +128,7 @@ internal AzureSearchBuilder RegisterOperations() } public IAzureSearchBuilder RegisterDomainSearcher() - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { @@ -138,7 +138,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index c3893e0..9e6e773 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -51,17 +51,17 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred } public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { - _serviceCollection.TryAddSingleton(_ => new AzureIndexDefinition(indexName)); + _serviceCollection.TryAddSingleton(_ => new IndexDefinition(indexName)); return this; } public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { - _serviceCollection.TryAddSingleton(_ => new AzureIndexDefinition(customIndex)); + _serviceCollection.TryAddSingleton(_ => new IndexDefinition(customIndex)); return this; } @@ -108,7 +108,7 @@ internal AzureSearchBuilder RegisterOperations() } public IAzureSearchBuilder RegisterDomainSearcher() - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { @@ -118,7 +118,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index 6b6b485..4a28861 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -57,20 +57,20 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred } public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { _composingRegister.Register( - _ => new AzureIndexDefinition(indexName), + _ => new IndexDefinition(indexName), Lifetime.Singleton); return this; } public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() { _composingRegister.Register( - _ => new AzureIndexDefinition(customIndex), + _ => new IndexDefinition(customIndex), Lifetime.Singleton); return this; @@ -128,7 +128,7 @@ internal AzureSearchBuilder RegisterOperations() } public IAzureSearchBuilder RegisterDomainSearcher() - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { @@ -138,7 +138,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class { diff --git a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs b/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs index f80da32..d77c3aa 100644 --- a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs @@ -11,18 +11,18 @@ public interface IAzureSearchBuilder IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl); IAzureSearchBuilder RegisterIndexDefinitions(string indexName) - where TDocument : class, IAzureModel, new(); + where TDocument : class, IModel, new(); IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) - where TDocument : class, IAzureModel, new(); + where TDocument : class, IModel, new(); IAzureSearchBuilder RegisterDomainSearcher() - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class; IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TDocument : class, IAzureModel, new() + where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class; } diff --git a/src/Cogworks.AzureSearch/Indexes/Index.cs b/src/Cogworks.AzureSearch/Indexes/Index.cs index 1a336b6..76cbc03 100644 --- a/src/Cogworks.AzureSearch/Indexes/Index.cs +++ b/src/Cogworks.AzureSearch/Indexes/Index.cs @@ -7,23 +7,23 @@ namespace Cogworks.AzureSearch.Indexes { - internal class Index : IIndex where TAzureModel : class, IAzureModel, new() + internal class Index : IIndex where TAzureModel : class, IModel, new() { private readonly IDocumentOperation _documentOperation; public Index(IDocumentOperation documentOperation) => _documentOperation = documentOperation; - public async Task AddOrUpdateDocumentAsync(TAzureModel model) + public async Task AddOrUpdateDocumentAsync(TAzureModel model) => await _documentOperation.AddOrUpdateDocumentAsync(model); - public async Task TryRemoveDocumentAsync(TAzureModel model) + public async Task TryRemoveDocumentAsync(TAzureModel model) => await _documentOperation.TryRemoveDocumentAsync(model); - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) => await _documentOperation.AddOrUpdateDocumentsAsync(models); - public async Task TryRemoveDocumentsAsync(IEnumerable models) + public async Task TryRemoveDocumentsAsync(IEnumerable models) => await _documentOperation.TryRemoveDocumentsAsync(models); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Initializers/Initializer.cs b/src/Cogworks.AzureSearch/Initializers/Initializer.cs index 6772b6b..9782164 100644 --- a/src/Cogworks.AzureSearch/Initializers/Initializer.cs +++ b/src/Cogworks.AzureSearch/Initializers/Initializer.cs @@ -9,7 +9,7 @@ namespace Cogworks.AzureSearch.Initializers { internal class Initializer : IInitializer - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { private readonly AzureSearchIndexOption _azureSearchIndexOption; private readonly IIndexOperation _indexOperation; diff --git a/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs b/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs index 4ad41f1..e8699e6 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs @@ -6,14 +6,14 @@ namespace Cogworks.AzureSearch.Interfaces.Indexes { - public interface IIndex where TAzureModel : class, IAzureModel, new() + public interface IIndex where TAzureModel : class, IModel, new() { - Task AddOrUpdateDocumentAsync(TAzureModel model); + Task AddOrUpdateDocumentAsync(TAzureModel model); - Task AddOrUpdateDocumentsAsync(IEnumerable models); + Task AddOrUpdateDocumentsAsync(IEnumerable models); - Task TryRemoveDocumentAsync(TAzureModel model); + Task TryRemoveDocumentAsync(TAzureModel model); - Task TryRemoveDocumentsAsync(IEnumerable models); + Task TryRemoveDocumentsAsync(IEnumerable models); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs b/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs index 86df6fd..185543b 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.Interfaces.Initializers { - public interface IInitializer where TAzureModel : class, IAzureModel, new() + public interface IInitializer where TAzureModel : class, IModel, new() { Task InitializeAsync(); } diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs index fa152de..64570b0 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs @@ -5,14 +5,14 @@ namespace Cogworks.AzureSearch.Interfaces.Operations { - public interface IDocumentOperation where TAzureModel : class, IAzureModel, new() + public interface IDocumentOperation where TAzureModel : class, IModel, new() { - Task AddOrUpdateDocumentAsync(TAzureModel model); + Task AddOrUpdateDocumentAsync(TAzureModel model); - Task AddOrUpdateDocumentsAsync(IEnumerable models); + Task AddOrUpdateDocumentsAsync(IEnumerable models); - Task TryRemoveDocumentAsync(TAzureModel model); + Task TryRemoveDocumentAsync(TAzureModel model); - Task TryRemoveDocumentsAsync(IEnumerable models); + Task TryRemoveDocumentsAsync(IEnumerable models); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs index 0213dab..4cd15c3 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.Interfaces.Operations { - public interface IIndexOperation where TAzureModel : class, IAzureModel, new() + public interface IIndexOperation where TAzureModel : class, IModel, new() { Task IndexExistsAsync(); diff --git a/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs index 75cf724..90f0618 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs @@ -8,7 +8,7 @@ public interface IRepository : IDocumentOperation, IIndexOperation, IAzureSearch - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs b/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs index 0af5302..637c68c 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs @@ -4,10 +4,10 @@ namespace Cogworks.AzureSearch.Interfaces.Searches { - public interface IAzureSearch where TAzureModel : class, IAzureModel, new() + public interface IAzureSearch where TAzureModel : class, IModel, new() { - SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters); + SearchResult Search(string keyword, SearchParameters searchParameters); - Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters); + Task> SearchAsync(string keyword, SearchParameters searchParameters); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs index f72c2e2..90b5b60 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs @@ -6,7 +6,7 @@ namespace Cogworks.AzureSearch.Interfaces.Wrappers { - public interface IDocumentOperationWrapper where TAzureModel : class, IAzureModel, new() + public interface IDocumentOperationWrapper where TAzureModel : class, IModel, new() { SearchResults Search(string searchText, SearchOptions parameters = null); diff --git a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs index 545ffcf..4c1ed7d 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs @@ -10,8 +10,8 @@ public interface IIndexOperationWrapper Task DeleteAsync(string indexName); - Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new(); + Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IModel, new(); - Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new(); + Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IModel, new(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Mappers/ParametersMapper.cs b/src/Cogworks.AzureSearch/Mappers/ParametersMapper.cs index 058a0bd..f860f83 100644 --- a/src/Cogworks.AzureSearch/Mappers/ParametersMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/ParametersMapper.cs @@ -8,67 +8,67 @@ namespace Cogworks.AzureSearch.Mappers { public static class ParametersMapper { - internal static SearchOptions Map(AzureSearchParameters azureSearchParameters) + internal static SearchOptions Map(SearchParameters searchParameters) { - var searchParameters = new SearchOptions + var searchOptions = new SearchOptions { - Filter = azureSearchParameters.Filter, - HighlightPostTag = azureSearchParameters.HighlightPostTag, - HighlightPreTag = azureSearchParameters.HighlightPreTag, - IncludeTotalCount = azureSearchParameters.IncludeTotalResultCount, - MinimumCoverage = azureSearchParameters.MinimumCoverage, - QueryType = azureSearchParameters.QueryType == AzureQueryType.Full + Filter = searchParameters.Filter, + HighlightPostTag = searchParameters.HighlightPostTag, + HighlightPreTag = searchParameters.HighlightPreTag, + IncludeTotalCount = searchParameters.IncludeTotalResultCount, + MinimumCoverage = searchParameters.MinimumCoverage, + QueryType = searchParameters.QueryType == AzureQueryType.Full ? SearchQueryType.Full : SearchQueryType.Simple, - ScoringProfile = azureSearchParameters.ScoringProfile, - SearchMode = azureSearchParameters.SearchMode == AzureSearchModeType.Any + ScoringProfile = searchParameters.ScoringProfile, + SearchMode = searchParameters.SearchMode == AzureSearchModeType.Any ? SearchMode.Any : SearchMode.All, - Skip = azureSearchParameters.Skip, - Size = azureSearchParameters.Take + Skip = searchParameters.Skip, + Size = searchParameters.Take }; - if (azureSearchParameters.Select.HasAny()) + if (searchParameters.Select.HasAny()) { - foreach (var selectField in azureSearchParameters.Select) + foreach (var selectField in searchParameters.Select) { - searchParameters.Select.Add(selectField); + searchOptions.Select.Add(selectField); } } - if (azureSearchParameters.SearchFields.HasAny()) + if (searchParameters.SearchFields.HasAny()) { - foreach (var searchField in azureSearchParameters.SearchFields) + foreach (var searchField in searchParameters.SearchFields) { - searchParameters.SearchFields.Add(searchField); + searchOptions.SearchFields.Add(searchField); } } - if (azureSearchParameters.HighlightFields.HasAny()) + if (searchParameters.HighlightFields.HasAny()) { - foreach (var highlightField in azureSearchParameters.HighlightFields) + foreach (var highlightField in searchParameters.HighlightFields) { - searchParameters.HighlightFields.Add(highlightField); + searchOptions.HighlightFields.Add(highlightField); } } - if (azureSearchParameters.Facets.HasAny()) + if (searchParameters.Facets.HasAny()) { - foreach (var facet in azureSearchParameters.Facets) + foreach (var facet in searchParameters.Facets) { - searchParameters.Facets.Add(facet); + searchOptions.Facets.Add(facet); } } - if (azureSearchParameters.OrderBy.HasAny()) + if (searchParameters.OrderBy.HasAny()) { - foreach (var order in azureSearchParameters.OrderBy) + foreach (var order in searchParameters.OrderBy) { - searchParameters.OrderBy.Add(order); + searchOptions.OrderBy.Add(order); } } - return searchParameters; + return searchOptions; } } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs b/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs index 898721f..a07ad9f 100644 --- a/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs @@ -9,7 +9,7 @@ public static class SearchResultMapper public static SearchResult Map( Azure.Search.Documents.Models.SearchResults results, int skip, - int take) where TAzureModel : class, IAzureModel, new() + int take) where TAzureModel : class, IModel, new() { var resultsCount = results.TotalCount ?? 0; diff --git a/src/Cogworks.AzureSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs b/src/Cogworks.AzureSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs deleted file mode 100644 index 18bbc85..0000000 --- a/src/Cogworks.AzureSearch/Models/Dtos/AzureBatchDocumentsOperationResult.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Cogworks.AzureSearch.Models.Dtos -{ - public class AzureBatchDocumentsOperationResult - { - public bool Succeeded { get; set; } - - public string Message { get; set; } - - public IEnumerable SucceededDocuments { get; set; } = Enumerable.Empty(); - - public IEnumerable FailedDocuments { get; set; } = Enumerable.Empty(); - } -} \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Models/Dtos/BatchDocumentsOperationResult.cs b/src/Cogworks.AzureSearch/Models/Dtos/BatchDocumentsOperationResult.cs new file mode 100644 index 0000000..1ce391f --- /dev/null +++ b/src/Cogworks.AzureSearch/Models/Dtos/BatchDocumentsOperationResult.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Cogworks.AzureSearch.Models.Dtos +{ + public class BatchDocumentsOperationResult + { + public bool Succeeded { get; set; } + + public string Message { get; set; } + + public IEnumerable SucceededDocuments { get; set; } = Enumerable.Empty(); + + public IEnumerable FailedDocuments { get; set; } = Enumerable.Empty(); + } +} \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Models/Dtos/AzureDocumentOperationResult.cs b/src/Cogworks.AzureSearch/Models/Dtos/DocumentOperationResult.cs similarity index 86% rename from src/Cogworks.AzureSearch/Models/Dtos/AzureDocumentOperationResult.cs rename to src/Cogworks.AzureSearch/Models/Dtos/DocumentOperationResult.cs index ed82355..2db601c 100644 --- a/src/Cogworks.AzureSearch/Models/Dtos/AzureDocumentOperationResult.cs +++ b/src/Cogworks.AzureSearch/Models/Dtos/DocumentOperationResult.cs @@ -1,6 +1,6 @@ namespace Cogworks.AzureSearch.Models.Dtos { - public class AzureDocumentOperationResult + public class DocumentOperationResult { public bool Succeeded { get; set; } diff --git a/src/Cogworks.AzureSearch/Models/Dtos/AzureIndexOperationResult.cs b/src/Cogworks.AzureSearch/Models/Dtos/IndexOperationResult.cs similarity index 77% rename from src/Cogworks.AzureSearch/Models/Dtos/AzureIndexOperationResult.cs rename to src/Cogworks.AzureSearch/Models/Dtos/IndexOperationResult.cs index d7202d9..2200949 100644 --- a/src/Cogworks.AzureSearch/Models/Dtos/AzureIndexOperationResult.cs +++ b/src/Cogworks.AzureSearch/Models/Dtos/IndexOperationResult.cs @@ -1,6 +1,6 @@ namespace Cogworks.AzureSearch.Models.Dtos { - public class AzureIndexOperationResult + public class IndexOperationResult { public bool Succeeded { get; set; } diff --git a/src/Cogworks.AzureSearch/Models/Dtos/SearchResult.cs b/src/Cogworks.AzureSearch/Models/Dtos/SearchResult.cs index ae9906c..0a30132 100644 --- a/src/Cogworks.AzureSearch/Models/Dtos/SearchResult.cs +++ b/src/Cogworks.AzureSearch/Models/Dtos/SearchResult.cs @@ -2,7 +2,7 @@ namespace Cogworks.AzureSearch.Models.Dtos { - public class SearchResult where TModel : class, IAzureModel, new() + public class SearchResult where TModel : class, IModel, new() { public long TotalCount { get; set; } diff --git a/src/Cogworks.AzureSearch/Models/Dtos/SearchResultItem.cs b/src/Cogworks.AzureSearch/Models/Dtos/SearchResultItem.cs index 7baba89..ae977cd 100644 --- a/src/Cogworks.AzureSearch/Models/Dtos/SearchResultItem.cs +++ b/src/Cogworks.AzureSearch/Models/Dtos/SearchResultItem.cs @@ -2,7 +2,7 @@ namespace Cogworks.AzureSearch.Models.Dtos { - public class SearchResultItem where TModel : class, IAzureModel, new() + public class SearchResultItem where TModel : class, IModel, new() { public TModel Document { get; } diff --git a/src/Cogworks.AzureSearch/Models/IAzureModel.cs b/src/Cogworks.AzureSearch/Models/IModel.cs similarity index 62% rename from src/Cogworks.AzureSearch/Models/IAzureModel.cs rename to src/Cogworks.AzureSearch/Models/IModel.cs index e54c5bd..bfe8fc7 100644 --- a/src/Cogworks.AzureSearch/Models/IAzureModel.cs +++ b/src/Cogworks.AzureSearch/Models/IModel.cs @@ -1,6 +1,6 @@ namespace Cogworks.AzureSearch.Models { - public interface IAzureModel + public interface IModel { } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Models/IAzureModelIdentity.cs b/src/Cogworks.AzureSearch/Models/IModelIdentity.cs similarity index 61% rename from src/Cogworks.AzureSearch/Models/IAzureModelIdentity.cs rename to src/Cogworks.AzureSearch/Models/IModelIdentity.cs index aba8890..1d909cd 100644 --- a/src/Cogworks.AzureSearch/Models/IAzureModelIdentity.cs +++ b/src/Cogworks.AzureSearch/Models/IModelIdentity.cs @@ -1,6 +1,6 @@ namespace Cogworks.AzureSearch.Models { - public interface IAzureModelIdentity : IAzureModel + public interface IModelIdentity : IModel { string Id { get; set; } } diff --git a/src/Cogworks.AzureSearch/Models/AzureIndexDefinition.cs b/src/Cogworks.AzureSearch/Models/IndexDefinition.cs similarity index 60% rename from src/Cogworks.AzureSearch/Models/AzureIndexDefinition.cs rename to src/Cogworks.AzureSearch/Models/IndexDefinition.cs index f130ef4..0978f31 100644 --- a/src/Cogworks.AzureSearch/Models/AzureIndexDefinition.cs +++ b/src/Cogworks.AzureSearch/Models/IndexDefinition.cs @@ -2,16 +2,16 @@ namespace Cogworks.AzureSearch.Models { - public class AzureIndexDefinition where TAzureModel : class, IAzureModel, new() + public class IndexDefinition where TAzureModel : class, IModel, new() { public string IndexName { get; } public SearchIndex CustomIndexDefinition { get; } - public AzureIndexDefinition(string indexName) + public IndexDefinition(string indexName) => IndexName = indexName; - public AzureIndexDefinition(SearchIndex customIndex) + public IndexDefinition(SearchIndex customIndex) => (CustomIndexDefinition, IndexName) = (customIndex, customIndex.Name); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Models/AzureSearchParameters.cs b/src/Cogworks.AzureSearch/Models/SearchParameters.cs similarity index 95% rename from src/Cogworks.AzureSearch/Models/AzureSearchParameters.cs rename to src/Cogworks.AzureSearch/Models/SearchParameters.cs index 9e9e0d6..4dfdd42 100644 --- a/src/Cogworks.AzureSearch/Models/AzureSearchParameters.cs +++ b/src/Cogworks.AzureSearch/Models/SearchParameters.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.Models { - public class AzureSearchParameters + public class SearchParameters { public bool IncludeTotalResultCount { get; set; } diff --git a/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs b/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs index e212d60..570c3e3 100644 --- a/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs @@ -13,7 +13,7 @@ namespace Cogworks.AzureSearch.Operations { public class DocumentOperation : IDocumentOperation - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { private readonly IDocumentOperationWrapper _documentOperationWrapper; @@ -22,7 +22,7 @@ public class DocumentOperation : IDocumentOperation public DocumentOperation(IDocumentOperationWrapper documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; - public async Task AddOrUpdateDocumentAsync(TAzureModel model) + public async Task AddOrUpdateDocumentAsync(TAzureModel model) { var azureBatchDocumentsOperationResult = await AddOrUpdateDocumentsAsync(new[] { model }); @@ -31,11 +31,11 @@ public async Task AddOrUpdateDocumentAsync(TAzureM : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); } - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) { if (!models.HasAny()) { - return new AzureBatchDocumentsOperationResult() + return new BatchDocumentsOperationResult() { Succeeded = true, Message = "No documents found to index." @@ -67,7 +67,7 @@ public async Task AddOrUpdateDocumentsAsync( return GetBatchOperationStatus(indexResults, "adding or updating"); } - public async Task TryRemoveDocumentAsync(TAzureModel model) + public async Task TryRemoveDocumentAsync(TAzureModel model) { var azureBatchDocumentsOperationResult = await TryRemoveDocumentsAsync(new[] { model }); @@ -76,11 +76,11 @@ public async Task TryRemoveDocumentAsync(TAzureMod : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); } - public async Task TryRemoveDocumentsAsync(IEnumerable models) + public async Task TryRemoveDocumentsAsync(IEnumerable models) { if (!models.HasAny()) { - return new AzureBatchDocumentsOperationResult() + return new BatchDocumentsOperationResult() { Succeeded = true, Message = "No documents found to delete." @@ -112,22 +112,22 @@ public async Task TryRemoveDocumentsAsync(IE return GetBatchOperationStatus(indexResults, "removing"); } - private static AzureBatchDocumentsOperationResult GetBatchOperationStatus(IEnumerable indexingResults, string operationType) + private static BatchDocumentsOperationResult GetBatchOperationStatus(IEnumerable indexingResults, string operationType) { var successfullyItems = indexingResults.Where(x => x.Succeeded).ToList(); var failedItems = indexingResults.Where(x => !x.Succeeded).ToList(); - return new AzureBatchDocumentsOperationResult + return new BatchDocumentsOperationResult { Succeeded = !failedItems.Any(), - SucceededDocuments = successfullyItems.Select(successfullyItem => new AzureDocumentOperationResult + SucceededDocuments = successfullyItems.Select(successfullyItem => new DocumentOperationResult { Succeeded = true, Message = $"Successfully {operationType} document.", ModelId = successfullyItem.Key, StatusCode = successfullyItem.Status }).ToList(), - FailedDocuments = failedItems.Select(failedItem => new AzureDocumentOperationResult + FailedDocuments = failedItems.Select(failedItem => new DocumentOperationResult { Message = $"Failed {operationType} document.", InnerMessage = failedItem.ErrorMessage, diff --git a/src/Cogworks.AzureSearch/Operations/IndexOperation.cs b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs index 749c00c..730bae6 100644 --- a/src/Cogworks.AzureSearch/Operations/IndexOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs @@ -8,16 +8,16 @@ namespace Cogworks.AzureSearch.Operations { public class IndexOperation : IIndexOperation - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { - private readonly AzureIndexDefinition _azureIndexDefinition; + private readonly IndexDefinition _indexDefinition; private readonly IIndexOperationWrapper _indexOperationWrapper; public IndexOperation( - AzureIndexDefinition azureIndexDefinition, + IndexDefinition indexDefinition, IIndexOperationWrapper indexOperationWrapper) { - _azureIndexDefinition = azureIndexDefinition; + _indexDefinition = indexDefinition; _indexOperationWrapper = indexOperationWrapper; } @@ -25,7 +25,7 @@ public async Task IndexExistsAsync() { try { - return await _indexOperationWrapper.ExistsAsync(_azureIndexDefinition.IndexName); + return await _indexOperationWrapper.ExistsAsync(_indexDefinition.IndexName); } catch (Exception exception) { @@ -37,7 +37,7 @@ public async Task IndexDeleteAsync() { try { - await _indexOperationWrapper.DeleteAsync(_azureIndexDefinition.IndexName); + await _indexOperationWrapper.DeleteAsync(_indexDefinition.IndexName); } catch (Exception exception) { @@ -50,9 +50,9 @@ public async Task IndexCreateOrUpdateAsync() try { - _ = _azureIndexDefinition.CustomIndexDefinition != null - ? await _indexOperationWrapper.CreateOrUpdateAsync(_azureIndexDefinition.CustomIndexDefinition, true) - : await _indexOperationWrapper.CreateOrUpdateAsync(_azureIndexDefinition.IndexName); + _ = _indexDefinition.CustomIndexDefinition != null + ? await _indexOperationWrapper.CreateOrUpdateAsync(_indexDefinition.CustomIndexDefinition, true) + : await _indexOperationWrapper.CreateOrUpdateAsync(_indexDefinition.IndexName); } catch (Exception exception) diff --git a/src/Cogworks.AzureSearch/Repositories/Repository.cs b/src/Cogworks.AzureSearch/Repositories/Repository.cs index b7cc97f..9d27e37 100644 --- a/src/Cogworks.AzureSearch/Repositories/Repository.cs +++ b/src/Cogworks.AzureSearch/Repositories/Repository.cs @@ -9,7 +9,7 @@ namespace Cogworks.AzureSearch.Repositories { internal class Repository : IRepository - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { private readonly IIndexOperation _indexOperation; private readonly IDocumentOperation _documentOperation; @@ -25,16 +25,16 @@ public Repository( _search = search; } - public async Task AddOrUpdateDocumentAsync(TAzureModel model) + public async Task AddOrUpdateDocumentAsync(TAzureModel model) => await _documentOperation.AddOrUpdateDocumentAsync(model); - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) => await _documentOperation.AddOrUpdateDocumentsAsync(models); - public async Task TryRemoveDocumentAsync(TAzureModel model) + public async Task TryRemoveDocumentAsync(TAzureModel model) => await _documentOperation.TryRemoveDocumentAsync(model); - public async Task TryRemoveDocumentsAsync(IEnumerable models) + public async Task TryRemoveDocumentsAsync(IEnumerable models) => await _documentOperation.TryRemoveDocumentsAsync(models); public async Task IndexExistsAsync() @@ -49,11 +49,11 @@ public async Task IndexCreateOrUpdateAsync() public async Task IndexClearAsync() => await _indexOperation.IndexClearAsync(); - public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) - => _search.Search(keyword, azureSearchParameters); + public SearchResult Search(string keyword, SearchParameters searchParameters) + => _search.Search(keyword, searchParameters); public async Task> SearchAsync(string keyword, - AzureSearchParameters azureSearchParameters) - => await _search.SearchAsync(keyword, azureSearchParameters); + SearchParameters searchParameters) + => await _search.SearchAsync(keyword, searchParameters); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs index 8a3e4a3..76e1e55 100644 --- a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs @@ -9,35 +9,35 @@ namespace Cogworks.AzureSearch.Searchers { internal class AzureSearch : IAzureSearch - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { private readonly IDocumentOperationWrapper _documentOperationWrapper; public AzureSearch(IDocumentOperationWrapper documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; - public SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) + public SearchResult Search(string keyword, SearchParameters searchParameters) { var searchText = GetSearchText(keyword); - var parameters = ParametersMapper.Map(azureSearchParameters); + var parameters = ParametersMapper.Map(searchParameters); var results = _documentOperationWrapper.Search($"{searchText}", parameters); return SearchResultMapper.Map( results, - azureSearchParameters.Skip, - azureSearchParameters.Take); + searchParameters.Skip, + searchParameters.Take); } - public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) + public async Task> SearchAsync(string keyword, SearchParameters searchParameters) { var searchText = GetSearchText(keyword); - var parameters = ParametersMapper.Map(azureSearchParameters); + var parameters = ParametersMapper.Map(searchParameters); var results = await _documentOperationWrapper.SearchAsync(searchText, parameters); return SearchResultMapper.Map( results, - azureSearchParameters.Skip, - azureSearchParameters.Take); + searchParameters.Skip, + searchParameters.Take); } private static string GetSearchText(string keyword) diff --git a/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs index 97edabf..3147d2c 100644 --- a/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs @@ -6,17 +6,17 @@ namespace Cogworks.AzureSearch.Searchers { public abstract class BaseDomainSearch - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { protected IAzureSearch Searcher { get; } protected BaseDomainSearch(IAzureSearch search) => Searcher = search; - public virtual SearchResult Search(string keyword, AzureSearchParameters azureSearchParameters) - => Searcher.Search(keyword, azureSearchParameters); + public virtual SearchResult Search(string keyword, SearchParameters searchParameters) + => Searcher.Search(keyword, searchParameters); - public async Task> SearchAsync(string keyword, AzureSearchParameters azureSearchParameters) - => await Searcher.SearchAsync(keyword, azureSearchParameters); + public async Task> SearchAsync(string keyword, SearchParameters searchParameters) + => await Searcher.SearchAsync(keyword, searchParameters); } } diff --git a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs index f752236..4bbe8f0 100644 --- a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs @@ -11,19 +11,19 @@ namespace Cogworks.AzureSearch.Wrappers { internal class DocumentOperationWrapper : IDocumentOperationWrapper - where TAzureModel : class, IAzureModel, new() + where TAzureModel : class, IModel, new() { private readonly SearchClient _searchClient; public DocumentOperationWrapper( - AzureIndexDefinition azureIndexDefinition, + IndexDefinition indexDefinition, AzureSearchClientOption azureSearchClientOption) { var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); _searchClient = new SearchClient( endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), - indexName: azureIndexDefinition.IndexName, + indexName: indexDefinition.IndexName, credential: azureKeyCredential, options: azureSearchClientOption.ClientOptions diff --git a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs index 7e10169..41c564c 100644 --- a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs @@ -28,7 +28,7 @@ public async Task ExistsAsync(string indexName) public async Task DeleteAsync(string indexName) => await _searchIndexClient.DeleteIndexAsync(indexName); - public async Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IAzureModel, new() + public async Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IModel, new() { var fieldBuilder = new FieldBuilder(); var searchFields = fieldBuilder.Build(typeof(TAzureModel)); @@ -40,7 +40,7 @@ public async Task DeleteAsync(string indexName) return await _searchIndexClient.CreateOrUpdateIndexAsync(definition); } - public async Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IAzureModel, new() + public async Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IModel, new() { if (overrideFields) { diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index 7bae278..2107231 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -207,9 +207,9 @@ public void Should_GetDedicatedIndexWithProperName() // ReSharper disable once PossibleNullReferenceException using (var scope = _containerBuilder.Build().BeginLifetimeScope()) { - var firstTestDocumentIndexDefinition = scope.Resolve>(); - var secondTestDocumentIndexDefinition = scope.Resolve>(); - var thirdTestDocumentIndexDefinition = scope.Resolve>(); + var firstTestDocumentIndexDefinition = scope.Resolve>(); + var secondTestDocumentIndexDefinition = scope.Resolve>(); + var thirdTestDocumentIndexDefinition = scope.Resolve>(); // Assert Assert.NotNull(firstTestDocumentIndexDefinition); diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs index 23a36c4..885507a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/FirstTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { - public class FirstTestDocumentModel : IAzureModel + public class FirstTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs index 93944d8..ceb0260 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { - public class NotRegisteredTestDocumentModel : IAzureModel + public class NotRegisteredTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs index 9600a4f..df0eaf3 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/SecondTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { - public class SecondTestDocumentModel : IAzureModel + public class SecondTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs index 02413b3..e5d407c 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Models/ThirdTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.AutofacIoc.UnitTests.Models { - public class ThirdTestDocumentModel : IAzureModel + public class ThirdTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs index 19bc09e..eb6011d 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -21,7 +21,7 @@ public void SomeCustomSearchExample() // ... // End of custom filters - // _ = base.Search("test", new AzureSearchParameters()); + // _ = base.Search("test", new SearchParameters()); } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index 93232ed..1be7866 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -201,9 +201,9 @@ public void Should_GetDedicatedIndexWithProperName() // ReSharper disable once PossibleNullReferenceException using (var scope = _container.BeginScope()) { - var firstTestDocumentIndexDefinition = scope.GetInstance>(); - var secondTestDocumentIndexDefinition = scope.GetInstance>(); - var thirdTestDocumentIndexDefinition = scope.GetInstance>(); + var firstTestDocumentIndexDefinition = scope.GetInstance>(); + var secondTestDocumentIndexDefinition = scope.GetInstance>(); + var thirdTestDocumentIndexDefinition = scope.GetInstance>(); // Assert Assert.NotNull(firstTestDocumentIndexDefinition); diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs index 9bd312f..f695fb0 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/FirstTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { - public class FirstTestDocumentModel : IAzureModel + public class FirstTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs index 6df63a7..211e1e2 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { - public class NotRegisteredTestDocumentModel : IAzureModel + public class NotRegisteredTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs index 92ed6ee..8cfe990 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/SecondTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { - public class SecondTestDocumentModel : IAzureModel + public class SecondTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs index bb9f038..86ac7b6 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Models/ThirdTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.LightInject.UnitTests.Models { - public class ThirdTestDocumentModel : IAzureModel + public class ThirdTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs index 54af0df..d190374 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs @@ -21,7 +21,7 @@ public void SomeCustomSearchExample() // ... // End of custom filters - // _ = base.Search("test", new AzureSearchParameters()); + // _ = base.Search("test", new SearchParameters()); } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index e8a9d8b..9404dee 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -203,9 +203,9 @@ public void Should_GetDedicatedIndexWithProperName() // ReSharper disable once PossibleNullReferenceException using (var serviceProvider = _serviceContainer.BuildServiceProvider()) { - var firstTestDocumentIndexDefinition = serviceProvider.GetService>(); - var secondTestDocumentIndexDefinition = serviceProvider.GetService>(); - var thirdTestDocumentIndexDefinition = serviceProvider.GetService>(); + var firstTestDocumentIndexDefinition = serviceProvider.GetService>(); + var secondTestDocumentIndexDefinition = serviceProvider.GetService>(); + var thirdTestDocumentIndexDefinition = serviceProvider.GetService>(); // Assert Assert.NotNull(firstTestDocumentIndexDefinition); diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs index de0966f..d7e0167 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/FirstTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { - public class FirstTestDocumentModel : IAzureModel + public class FirstTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs index cc04d90..1fed359 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { - public class NotRegisteredTestDocumentModel : IAzureModel + public class NotRegisteredTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs index e199052..cdc0813 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/SecondTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { - public class SecondTestDocumentModel : IAzureModel + public class SecondTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs index 061aaca..52be652 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Models/ThirdTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models { - public class ThirdTestDocumentModel : IAzureModel + public class ThirdTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs index 2c88691..c755eb1 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -21,7 +21,7 @@ public void SomeCustomSearchExample() // ... // End of custom filters - // _ = base.Search("test", new AzureSearchParameters()); + // _ = base.Search("test", new SearchParameters()); } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs index e4a5199..f8490c4 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/FirstTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { - public class FirstTestDocumentModel : IAzureModel + public class FirstTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs index c91e9a8..a3c14e7 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/NotRegistredTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { - public class NotRegisteredTestDocumentModel : IAzureModel + public class NotRegisteredTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs index 98c50d5..0b526e9 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/SecondTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { - public class SecondTestDocumentModel : IAzureModel + public class SecondTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs index f6ef5a8..a22238a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Models/ThirdTestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests.Models { - public class ThirdTestDocumentModel : IAzureModel + public class ThirdTestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs index 2aba0d4..220b5a9 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -21,7 +21,7 @@ public void SomeCustomSearchExample() // ... // End of custom filters - // _ = base.Search("test", new AzureSearchParameters()); + // _ = base.Search("test", new SearchParameters()); } } } \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index aa32f5d..b347768 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -212,9 +212,9 @@ public void Should_GetDedicatedIndexWithProperName() using (var scope = container.BeginScope()) { - var firstTestDocumentIndexDefinition = scope.GetInstance>(); - var secondTestDocumentIndexDefinition = scope.GetInstance>(); - var thirdTestDocumentIndexDefinition = scope.GetInstance>(); + var firstTestDocumentIndexDefinition = scope.GetInstance>(); + var secondTestDocumentIndexDefinition = scope.GetInstance>(); + var thirdTestDocumentIndexDefinition = scope.GetInstance>(); // Assert Assert.NotNull(firstTestDocumentIndexDefinition); diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs index 54db421..d79bc8a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Models/TestDocumentModel.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.UnitTests.Models { - public class TestDocumentModel : IAzureModel + public class TestDocumentModel : IModel { [SimpleField(IsKey = true, IsFilterable = true)] [SearchableField()] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs index aedce16..18d201d 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs @@ -157,7 +157,7 @@ public async Task Should_CreateOrUpdateCustomIndex() // Arrange var index = new SearchIndex(Fixture.Create()); - var customModelDefinition = new AzureIndexDefinition(index); + var customModelDefinition = new IndexDefinition(index); var customIndexOperationService = new IndexOperation( customModelDefinition, @@ -199,7 +199,7 @@ public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomInde // Arrange var index = new SearchIndex(Fixture.Create()); - var customModelDefinition = new AzureIndexDefinition(index); + var customModelDefinition = new IndexDefinition(index); var customIndexOperationService = new IndexOperation( customModelDefinition, diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs index 39852c2..ce74da3 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs @@ -19,7 +19,7 @@ public abstract class TestBase protected readonly IIndexOperationWrapper IndexOperationWrapper; protected readonly IDocumentOperationWrapper DocumentOperationWrapper; - protected readonly AzureIndexDefinition TestDocumentModelDefinition; + protected readonly IndexDefinition TestDocumentModelDefinition; protected readonly IAzureSearch Search; protected readonly IDocumentOperation DocumentOperationService; @@ -27,7 +27,7 @@ public abstract class TestBase protected TestBase() { - TestDocumentModelDefinition = Fixture.Create>(); + TestDocumentModelDefinition = Fixture.Create>(); IndexOperationWrapper = Substitute.For(); DocumentOperationWrapper = Substitute.For>(); From 96e6e0ab2638007a71711f38c0509e383068c80e Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:12:22 +0200 Subject: [PATCH 23/31] refactor: renamed options --- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- src/Cogworks.AzureSearch/Initializers/Initializer.cs | 10 +++++----- .../{AzureSearchClientOption.cs => ClientOption.cs} | 4 ++-- .../{AzureSearchIndexOption.cs => IndexOption.cs} | 4 ++-- .../Wrappers/DocumentOperationWrapper.cs | 8 ++++---- .../Wrappers/IndexOperationWrapper.cs | 6 +++--- 9 files changed, 24 insertions(+), 24 deletions(-) rename src/Cogworks.AzureSearch/Options/{AzureSearchClientOption.cs => ClientOption.cs} (88%) rename src/Cogworks.AzureSearch/Options/{AzureSearchIndexOption.cs => IndexOption.cs} (68%) diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index f263d37..47c3962 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -36,7 +36,7 @@ internal AzureSearchBuilder RegisterInitializers() public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { - _ = _builder.Register(_ => new AzureSearchIndexOption(recreate, recreateOnUpdateFailure)) + _ = _builder.Register(_ => new IndexOption(recreate, recreateOnUpdateFailure)) .AsSelf() .SingleInstance(); @@ -45,7 +45,7 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { - _ = _builder.Register(_ => new AzureSearchClientOption( + _ = _builder.Register(_ => new ClientOption( serviceName, credentials, serviceEndpointUrl)) diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index b7915b8..60557d1 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -37,7 +37,7 @@ internal AzureSearchBuilder RegisterInitializers() public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { _ = _container.Register( - _ => new AzureSearchIndexOption(recreate, recreateOnUpdateFailure), + _ => new IndexOption(recreate, recreateOnUpdateFailure), new PerContainerLifetime()); return this; @@ -46,7 +46,7 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _ = _container.Register( - _ => new AzureSearchClientOption( + _ => new ClientOption( serviceName, credentials, serviceEndpointUrl), diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index 9e6e773..36f9b7e 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -35,14 +35,14 @@ internal AzureSearchBuilder RegisterInitializers() public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { - _serviceCollection.TryAddSingleton(_ => new AzureSearchIndexOption(recreate, recreateOnUpdateFailure)); + _serviceCollection.TryAddSingleton(_ => new IndexOption(recreate, recreateOnUpdateFailure)); return this; } public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { - _serviceCollection.TryAddSingleton(_ => new AzureSearchClientOption( + _serviceCollection.TryAddSingleton(_ => new ClientOption( serviceName, credentials, serviceEndpointUrl)); diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index 4a28861..20b4610 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -38,7 +38,7 @@ internal AzureSearchBuilder RegisterInitializers() public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { _composingRegister.Register( - _ => new AzureSearchIndexOption(recreate, recreateOnUpdateFailure), + _ => new IndexOption(recreate, recreateOnUpdateFailure), Lifetime.Singleton); return this; @@ -47,7 +47,7 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _composingRegister.Register( - _ => new AzureSearchClientOption( + _ => new ClientOption( serviceName, credentials, serviceEndpointUrl), diff --git a/src/Cogworks.AzureSearch/Initializers/Initializer.cs b/src/Cogworks.AzureSearch/Initializers/Initializer.cs index 9782164..7edd4a9 100644 --- a/src/Cogworks.AzureSearch/Initializers/Initializer.cs +++ b/src/Cogworks.AzureSearch/Initializers/Initializer.cs @@ -11,18 +11,18 @@ namespace Cogworks.AzureSearch.Initializers internal class Initializer : IInitializer where TAzureModel : class, IModel, new() { - private readonly AzureSearchIndexOption _azureSearchIndexOption; + private readonly IndexOption _indexOption; private readonly IIndexOperation _indexOperation; - public Initializer(AzureSearchIndexOption azureSearchIndexOption, IIndexOperation indexOperation) + public Initializer(IndexOption indexOption, IIndexOperation indexOperation) { - _azureSearchIndexOption = azureSearchIndexOption; + _indexOption = indexOption; _indexOperation = indexOperation; } public async Task InitializeAsync() { - if (_azureSearchIndexOption.Recreate) + if (_indexOption.Recreate) { await _indexOperation.IndexDeleteAsync(); } @@ -33,7 +33,7 @@ public async Task InitializeAsync() } catch (Exception) { - if (_azureSearchIndexOption.RecreateOnUpdateFailure) + if (_indexOption.RecreateOnUpdateFailure) { await _indexOperation.IndexDeleteAsync(); } diff --git a/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs b/src/Cogworks.AzureSearch/Options/ClientOption.cs similarity index 88% rename from src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs rename to src/Cogworks.AzureSearch/Options/ClientOption.cs index 3048734..76c76b2 100644 --- a/src/Cogworks.AzureSearch/Options/AzureSearchClientOption.cs +++ b/src/Cogworks.AzureSearch/Options/ClientOption.cs @@ -4,7 +4,7 @@ namespace Cogworks.AzureSearch.Options { - public class AzureSearchClientOption + public class ClientOption { public string ServiceName { get; } @@ -14,7 +14,7 @@ public class AzureSearchClientOption public SearchClientOptions ClientOptions { get; } - public AzureSearchClientOption(string serviceName, string credentials, string serviceUrlEndpoint) + public ClientOption(string serviceName, string credentials, string serviceUrlEndpoint) { ServiceName = serviceName; Credentials = credentials; diff --git a/src/Cogworks.AzureSearch/Options/AzureSearchIndexOption.cs b/src/Cogworks.AzureSearch/Options/IndexOption.cs similarity index 68% rename from src/Cogworks.AzureSearch/Options/AzureSearchIndexOption.cs rename to src/Cogworks.AzureSearch/Options/IndexOption.cs index 4c664d4..8b6d549 100644 --- a/src/Cogworks.AzureSearch/Options/AzureSearchIndexOption.cs +++ b/src/Cogworks.AzureSearch/Options/IndexOption.cs @@ -1,12 +1,12 @@ namespace Cogworks.AzureSearch.Options { - public class AzureSearchIndexOption + public class IndexOption { public bool Recreate { get; } public bool RecreateOnUpdateFailure { get; } - public AzureSearchIndexOption(bool recreate, bool recreateOnUpdateFailure) + public IndexOption(bool recreate, bool recreateOnUpdateFailure) { Recreate = recreate; RecreateOnUpdateFailure = recreateOnUpdateFailure; diff --git a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs index 4bbe8f0..3935424 100644 --- a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs @@ -17,15 +17,15 @@ internal class DocumentOperationWrapper : IDocumentOperationWrapper public DocumentOperationWrapper( IndexDefinition indexDefinition, - AzureSearchClientOption azureSearchClientOption) + ClientOption clientOption) { - var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); + var azureKeyCredential = new AzureKeyCredential(clientOption.Credentials); _searchClient = new SearchClient( - endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), + endpoint: new Uri(clientOption.ServiceUrlEndpoint), indexName: indexDefinition.IndexName, credential: azureKeyCredential, - options: azureSearchClientOption.ClientOptions + options: clientOption.ClientOptions ); } diff --git a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs index 41c564c..8d16f6a 100644 --- a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs @@ -13,12 +13,12 @@ internal class IndexOperationWrapper : IIndexOperationWrapper { private readonly SearchIndexClient _searchIndexClient; - public IndexOperationWrapper(AzureSearchClientOption azureSearchClientOption) + public IndexOperationWrapper(ClientOption clientOption) { - var azureKeyCredential = new AzureKeyCredential(azureSearchClientOption.Credentials); + var azureKeyCredential = new AzureKeyCredential(clientOption.Credentials); _searchIndexClient = new SearchIndexClient( - endpoint: new Uri(azureSearchClientOption.ServiceUrlEndpoint), + endpoint: new Uri(clientOption.ServiceUrlEndpoint), credential: azureKeyCredential); } From b8f80ccb03645a8a31ef2fbbdd8a6db41a5d70c2 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:19:25 +0200 Subject: [PATCH 24/31] refactor: renamed searcher --- README.md | 10 +++++----- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Builders/AzureSearchBuilder.cs | 2 +- .../Builders/AzureSearchBuilder.cs | 4 ++-- .../Interfaces/Repositories/IRepository.cs | 2 +- .../Searches/{IAzureSearch.cs => ISearcher.cs} | 2 +- .../Repositories/Repository.cs | 4 ++-- .../Searchers/BaseDomainSearch.cs | 4 ++-- .../Searchers/{AzureSearch.cs => Searcher.cs} | 4 ++-- .../AutofacIocExtensionTests.cs | 14 +++++++------- .../Searchers/CustomTestSearch.cs | 2 +- .../LightInjectIocExtensionTests.cs | 14 +++++++------- .../Searchers/CustomTestSearch.cs | 2 +- .../MicrosoftIocExtensionTests.cs | 14 +++++++------- .../Searchers/CustomTestSearch.cs | 2 +- .../Searchers/CustomTestSearch.cs | 2 +- .../UmbracoIocExtensionTests.cs | 14 +++++++------- .../Cogworks.AzureSearch.UnitTests/TestBase.cs | 4 ++-- 19 files changed, 54 insertions(+), 54 deletions(-) rename src/Cogworks.AzureSearch/Interfaces/Searches/{IAzureSearch.cs => ISearcher.cs} (80%) rename src/Cogworks.AzureSearch/Searchers/{AzureSearch.cs => Searcher.cs} (91%) diff --git a/README.md b/README.md index 8e7afb6..ffe2c50 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ public class SomeDocumentService Content = "Some content" }); - + public async Task AddOrUpdateItems() { var items = new List @@ -81,7 +81,7 @@ public class SomeDocumentService Id = "some-id" }); - + public async Task RemoveItems() { var items = new List @@ -107,9 +107,9 @@ public class SomeDocumentService ```csharp public class SomeService { - private readonly IAzureSearch _documentSearch; + private readonly ISearcher _documentSearch; - public SomeService(IAzureSearch documentSearch) + public SomeService(ISearcher documentSearch) => _documentSearch = documentSearch; public void Search() @@ -207,7 +207,7 @@ public class SomeStartupService ``` ## License - + - Cogworks.AzureSearch is licensed under the [Apache License, Version 2.0](https://opensource.org/licenses/Apache-2.0) ## Code of Conduct diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs index 47c3962..1a7ee87 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs @@ -108,8 +108,8 @@ internal AzureSearchBuilder RegisterRepositories() internal AzureSearchBuilder RegisterSearchers() { - _ = _builder.RegisterGeneric(typeof(AzureSearch<>)) - .As(typeof(IAzureSearch<>)) + _ = _builder.RegisterGeneric(typeof(Searcher<>)) + .As(typeof(ISearcher<>)) .InstancePerDependency(); return this; diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs index 60557d1..87323a4 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs @@ -107,8 +107,8 @@ internal AzureSearchBuilder RegisterRepositories() internal AzureSearchBuilder RegisterSearchers() { _ = _container.Register( - typeof(IAzureSearch<>), - typeof(AzureSearch<>)); + typeof(ISearcher<>), + typeof(Searcher<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs index 36f9b7e..bba21ef 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs @@ -93,7 +93,7 @@ internal AzureSearchBuilder RegisterRepositories() internal AzureSearchBuilder RegisterSearchers() { - _serviceCollection.TryAddScoped(typeof(IAzureSearch<>), typeof(AzureSearch<>)); + _serviceCollection.TryAddScoped(typeof(ISearcher<>), typeof(Searcher<>)); return this; } diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs index 20b4610..6afa0dc 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs @@ -108,8 +108,8 @@ internal AzureSearchBuilder RegisterRepositories() internal AzureSearchBuilder RegisterSearchers() { _composingRegister.Register( - typeof(IAzureSearch<>), - typeof(AzureSearch<>)); + typeof(ISearcher<>), + typeof(Searcher<>)); return this; } diff --git a/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs index 90f0618..4fd1927 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs @@ -7,7 +7,7 @@ namespace Cogworks.AzureSearch.Interfaces.Repositories public interface IRepository : IDocumentOperation, IIndexOperation, - IAzureSearch + ISearcher where TAzureModel : class, IModel, new() { } diff --git a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs b/src/Cogworks.AzureSearch/Interfaces/Searches/ISearcher.cs similarity index 80% rename from src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs rename to src/Cogworks.AzureSearch/Interfaces/Searches/ISearcher.cs index 637c68c..0b087fb 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Searches/IAzureSearch.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Searches/ISearcher.cs @@ -4,7 +4,7 @@ namespace Cogworks.AzureSearch.Interfaces.Searches { - public interface IAzureSearch where TAzureModel : class, IModel, new() + public interface ISearcher where TAzureModel : class, IModel, new() { SearchResult Search(string keyword, SearchParameters searchParameters); diff --git a/src/Cogworks.AzureSearch/Repositories/Repository.cs b/src/Cogworks.AzureSearch/Repositories/Repository.cs index 9d27e37..ec6a101 100644 --- a/src/Cogworks.AzureSearch/Repositories/Repository.cs +++ b/src/Cogworks.AzureSearch/Repositories/Repository.cs @@ -13,12 +13,12 @@ internal class Repository : IRepository { private readonly IIndexOperation _indexOperation; private readonly IDocumentOperation _documentOperation; - private readonly IAzureSearch _search; + private readonly ISearcher _search; public Repository( IIndexOperation indexOperation, IDocumentOperation documentOperation, - IAzureSearch search) + ISearcher search) { _indexOperation = indexOperation; _documentOperation = documentOperation; diff --git a/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs index 3147d2c..b4f0d02 100644 --- a/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs @@ -8,9 +8,9 @@ namespace Cogworks.AzureSearch.Searchers public abstract class BaseDomainSearch where TAzureModel : class, IModel, new() { - protected IAzureSearch Searcher { get; } + protected ISearcher Searcher { get; } - protected BaseDomainSearch(IAzureSearch search) + protected BaseDomainSearch(ISearcher search) => Searcher = search; public virtual SearchResult Search(string keyword, SearchParameters searchParameters) diff --git a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs b/src/Cogworks.AzureSearch/Searchers/Searcher.cs similarity index 91% rename from src/Cogworks.AzureSearch/Searchers/AzureSearch.cs rename to src/Cogworks.AzureSearch/Searchers/Searcher.cs index 76e1e55..cdb7c3e 100644 --- a/src/Cogworks.AzureSearch/Searchers/AzureSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/Searcher.cs @@ -8,12 +8,12 @@ namespace Cogworks.AzureSearch.Searchers { - internal class AzureSearch : IAzureSearch + internal class Searcher : ISearcher where TAzureModel : class, IModel, new() { private readonly IDocumentOperationWrapper _documentOperationWrapper; - public AzureSearch(IDocumentOperationWrapper documentOperationWrapper) + public Searcher(IDocumentOperationWrapper documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; public SearchResult Search(string keyword, SearchParameters searchParameters) diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index 2107231..7741b05 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -42,19 +42,19 @@ public AutofacIocExtensionTests() [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) @@ -81,19 +81,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { // Arrange @@ -110,7 +110,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { // NotRegisteredTestDocumentModel diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs index eb6011d..6fb7151 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -11,7 +11,7 @@ public interface ICustomTestSearch public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureSearch search) : base(search) + public CustomTestSearch(ISearcher search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index 1be7866..2e34e6c 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -41,13 +41,13 @@ public LightInjectIocExtensionTests() [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] [InlineData(typeof(IRepository))] @@ -55,7 +55,7 @@ public LightInjectIocExtensionTests() [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { // Arrange @@ -80,19 +80,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { // Arrange @@ -109,7 +109,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { // Arrange diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs index d190374..a1ba737 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/Searchers/CustomTestSearch.cs @@ -11,7 +11,7 @@ public interface ICustomTestSearch public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureSearch search) : base(search) + public CustomTestSearch(ISearcher search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index 9404dee..d44b27a 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -43,19 +43,19 @@ public MicrosoftIocExtensionTests() [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { // Arrange @@ -80,19 +80,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { // Arrange @@ -109,7 +109,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { // NotRegisteredTestDocumentModel diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs index c755eb1..f648c39 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -11,7 +11,7 @@ public interface ICustomTestSearch public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureSearch search) : base(search) + public CustomTestSearch(ISearcher search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs index 220b5a9..5b54c5b 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Searchers/CustomTestSearch.cs @@ -11,7 +11,7 @@ public interface ICustomTestSearch public class CustomTestSearch : BaseDomainSearch, ICustomTestSearch { - public CustomTestSearch(IAzureSearch search) : base(search) + public CustomTestSearch(ISearcher search) : base(search) { } diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index b347768..a7f0f50 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -50,19 +50,19 @@ public UmbracoIocExtensionTests() [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { // Arrange @@ -87,19 +87,19 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] [InlineData(typeof(IRepository))] [InlineData(typeof(IIndexOperation))] [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectType) { // Arrange @@ -116,7 +116,7 @@ public void Should_Not_ThrowException_When_IndexRegistered(Type desiredObjectTyp [InlineData(typeof(IDocumentOperation))] [InlineData(typeof(IIndex))] [InlineData(typeof(IInitializer))] - [InlineData(typeof(IAzureSearch))] + [InlineData(typeof(ISearcher))] public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType) { // Arrange diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs index ce74da3..bcee22b 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs @@ -20,7 +20,7 @@ public abstract class TestBase protected readonly IIndexOperationWrapper IndexOperationWrapper; protected readonly IDocumentOperationWrapper DocumentOperationWrapper; protected readonly IndexDefinition TestDocumentModelDefinition; - protected readonly IAzureSearch Search; + protected readonly ISearcher Search; protected readonly IDocumentOperation DocumentOperationService; protected readonly IIndexOperation IndexOperationService; @@ -32,7 +32,7 @@ protected TestBase() IndexOperationWrapper = Substitute.For(); DocumentOperationWrapper = Substitute.For>(); - Search = Substitute.For>(); + Search = Substitute.For>(); DocumentOperationService = new DocumentOperation( DocumentOperationWrapper); From 4a8f0c46638ca64e74a23ef242fbc4a6d3a12f2c Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:21:41 +0200 Subject: [PATCH 25/31] refactor: renamed generic parameter --- src/Cogworks.AzureSearch/Indexes/Index.cs | 14 +++++----- .../Initializers/Initializer.cs | 8 +++--- .../Interfaces/Indexes/IIndex.cs | 10 +++---- .../Interfaces/Initializers/IInitializer.cs | 2 +- .../Operations/IDocumentOperation.cs | 10 +++---- .../Interfaces/Operations/IIndexOperation.cs | 2 +- .../Interfaces/Repositories/IRepository.cs | 10 +++---- .../Interfaces/Searches/ISearcher.cs | 6 ++-- .../Wrappers/IDocumentOperationWrapper.cs | 8 +++--- .../Wrappers/IIndexOperationWrapper.cs | 4 +-- .../Mappers/SearchResultMapper.cs | 10 +++---- .../Models/IndexDefinition.cs | 2 +- .../Operations/DocumentOperation.cs | 20 ++++++------- .../Operations/IndexOperation.cs | 12 ++++---- .../Repositories/Repository.cs | 28 +++++++++---------- .../Searchers/BaseDomainSearch.cs | 12 ++++---- .../Searchers/Searcher.cs | 12 ++++---- .../Wrappers/DocumentOperationWrapper.cs | 16 +++++------ .../Wrappers/IndexOperationWrapper.cs | 8 +++--- 19 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/Cogworks.AzureSearch/Indexes/Index.cs b/src/Cogworks.AzureSearch/Indexes/Index.cs index 76cbc03..7f7e1b7 100644 --- a/src/Cogworks.AzureSearch/Indexes/Index.cs +++ b/src/Cogworks.AzureSearch/Indexes/Index.cs @@ -7,23 +7,23 @@ namespace Cogworks.AzureSearch.Indexes { - internal class Index : IIndex where TAzureModel : class, IModel, new() + internal class Index : IIndex where TModel : class, IModel, new() { - private readonly IDocumentOperation _documentOperation; + private readonly IDocumentOperation _documentOperation; - public Index(IDocumentOperation documentOperation) + public Index(IDocumentOperation documentOperation) => _documentOperation = documentOperation; - public async Task AddOrUpdateDocumentAsync(TAzureModel model) + public async Task AddOrUpdateDocumentAsync(TModel model) => await _documentOperation.AddOrUpdateDocumentAsync(model); - public async Task TryRemoveDocumentAsync(TAzureModel model) + public async Task TryRemoveDocumentAsync(TModel model) => await _documentOperation.TryRemoveDocumentAsync(model); - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) => await _documentOperation.AddOrUpdateDocumentsAsync(models); - public async Task TryRemoveDocumentsAsync(IEnumerable models) + public async Task TryRemoveDocumentsAsync(IEnumerable models) => await _documentOperation.TryRemoveDocumentsAsync(models); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Initializers/Initializer.cs b/src/Cogworks.AzureSearch/Initializers/Initializer.cs index 7edd4a9..9f0daa3 100644 --- a/src/Cogworks.AzureSearch/Initializers/Initializer.cs +++ b/src/Cogworks.AzureSearch/Initializers/Initializer.cs @@ -8,13 +8,13 @@ namespace Cogworks.AzureSearch.Initializers { - internal class Initializer : IInitializer - where TAzureModel : class, IModel, new() + internal class Initializer : IInitializer + where TModel : class, IModel, new() { private readonly IndexOption _indexOption; - private readonly IIndexOperation _indexOperation; + private readonly IIndexOperation _indexOperation; - public Initializer(IndexOption indexOption, IIndexOperation indexOperation) + public Initializer(IndexOption indexOption, IIndexOperation indexOperation) { _indexOption = indexOption; _indexOperation = indexOperation; diff --git a/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs b/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs index e8699e6..44f3934 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Indexes/IIndex.cs @@ -6,14 +6,14 @@ namespace Cogworks.AzureSearch.Interfaces.Indexes { - public interface IIndex where TAzureModel : class, IModel, new() + public interface IIndex where TModel : class, IModel, new() { - Task AddOrUpdateDocumentAsync(TAzureModel model); + Task AddOrUpdateDocumentAsync(TModel model); - Task AddOrUpdateDocumentsAsync(IEnumerable models); + Task AddOrUpdateDocumentsAsync(IEnumerable models); - Task TryRemoveDocumentAsync(TAzureModel model); + Task TryRemoveDocumentAsync(TModel model); - Task TryRemoveDocumentsAsync(IEnumerable models); + Task TryRemoveDocumentsAsync(IEnumerable models); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs b/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs index 185543b..e1d0f9e 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Initializers/IInitializer.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.Interfaces.Initializers { - public interface IInitializer where TAzureModel : class, IModel, new() + public interface IInitializer where TModel : class, IModel, new() { Task InitializeAsync(); } diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs index 64570b0..a619035 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IDocumentOperation.cs @@ -5,14 +5,14 @@ namespace Cogworks.AzureSearch.Interfaces.Operations { - public interface IDocumentOperation where TAzureModel : class, IModel, new() + public interface IDocumentOperation where TModel : class, IModel, new() { - Task AddOrUpdateDocumentAsync(TAzureModel model); + Task AddOrUpdateDocumentAsync(TModel model); - Task AddOrUpdateDocumentsAsync(IEnumerable models); + Task AddOrUpdateDocumentsAsync(IEnumerable models); - Task TryRemoveDocumentAsync(TAzureModel model); + Task TryRemoveDocumentAsync(TModel model); - Task TryRemoveDocumentsAsync(IEnumerable models); + Task TryRemoveDocumentsAsync(IEnumerable models); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs b/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs index 4cd15c3..0b7115d 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Operations/IIndexOperation.cs @@ -3,7 +3,7 @@ namespace Cogworks.AzureSearch.Interfaces.Operations { - public interface IIndexOperation where TAzureModel : class, IModel, new() + public interface IIndexOperation where TModel : class, IModel, new() { Task IndexExistsAsync(); diff --git a/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs index 4fd1927..5dcabfa 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Repositories/IRepository.cs @@ -4,11 +4,11 @@ namespace Cogworks.AzureSearch.Interfaces.Repositories { - public interface IRepository : - IDocumentOperation, - IIndexOperation, - ISearcher - where TAzureModel : class, IModel, new() + public interface IRepository : + IDocumentOperation, + IIndexOperation, + ISearcher + where TModel : class, IModel, new() { } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Searches/ISearcher.cs b/src/Cogworks.AzureSearch/Interfaces/Searches/ISearcher.cs index 0b087fb..9fa663e 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Searches/ISearcher.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Searches/ISearcher.cs @@ -4,10 +4,10 @@ namespace Cogworks.AzureSearch.Interfaces.Searches { - public interface ISearcher where TAzureModel : class, IModel, new() + public interface ISearcher where TModel : class, IModel, new() { - SearchResult Search(string keyword, SearchParameters searchParameters); + SearchResult Search(string keyword, SearchParameters searchParameters); - Task> SearchAsync(string keyword, SearchParameters searchParameters); + Task> SearchAsync(string keyword, SearchParameters searchParameters); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs index 90b5b60..bc09f32 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IDocumentOperationWrapper.cs @@ -6,12 +6,12 @@ namespace Cogworks.AzureSearch.Interfaces.Wrappers { - public interface IDocumentOperationWrapper where TAzureModel : class, IModel, new() + public interface IDocumentOperationWrapper where TModel : class, IModel, new() { - SearchResults Search(string searchText, SearchOptions parameters = null); + SearchResults Search(string searchText, SearchOptions parameters = null); - Task> SearchAsync(string searchText, SearchOptions parameters = null); + Task> SearchAsync(string searchText, SearchOptions parameters = null); - Task> IndexAsync(IndexDocumentsBatch indexBatch); + Task> IndexAsync(IndexDocumentsBatch indexBatch); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs index 4c1ed7d..6210d44 100644 --- a/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Interfaces/Wrappers/IIndexOperationWrapper.cs @@ -10,8 +10,8 @@ public interface IIndexOperationWrapper Task DeleteAsync(string indexName); - Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IModel, new(); + Task CreateOrUpdateAsync(string indexName) where TModel : class, IModel, new(); - Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IModel, new(); + Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TModel : class, IModel, new(); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs b/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs index a07ad9f..f0c26d9 100644 --- a/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs +++ b/src/Cogworks.AzureSearch/Mappers/SearchResultMapper.cs @@ -6,22 +6,22 @@ namespace Cogworks.AzureSearch.Mappers { public static class SearchResultMapper { - public static SearchResult Map( - Azure.Search.Documents.Models.SearchResults results, + public static SearchResult Map( + Azure.Search.Documents.Models.SearchResults results, int skip, - int take) where TAzureModel : class, IModel, new() + int take) where TModel : class, IModel, new() { var resultsCount = results.TotalCount ?? 0; var searchedDocuments = results.GetResults() - .Select(resultDocument => new SearchResultItem( + .Select(resultDocument => new SearchResultItem( resultDocument.Document, resultDocument.Highlights, resultDocument.Score ?? default )) .ToArray(); - return new SearchResult() + return new SearchResult() { HasMoreItems = skip + take < resultsCount, TotalCount = resultsCount, diff --git a/src/Cogworks.AzureSearch/Models/IndexDefinition.cs b/src/Cogworks.AzureSearch/Models/IndexDefinition.cs index 0978f31..7c0458b 100644 --- a/src/Cogworks.AzureSearch/Models/IndexDefinition.cs +++ b/src/Cogworks.AzureSearch/Models/IndexDefinition.cs @@ -2,7 +2,7 @@ namespace Cogworks.AzureSearch.Models { - public class IndexDefinition where TAzureModel : class, IModel, new() + public class IndexDefinition where TModel : class, IModel, new() { public string IndexName { get; } diff --git a/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs b/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs index 570c3e3..72e69c4 100644 --- a/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/DocumentOperation.cs @@ -12,17 +12,17 @@ namespace Cogworks.AzureSearch.Operations { - public class DocumentOperation : IDocumentOperation - where TAzureModel : class, IModel, new() + public class DocumentOperation : IDocumentOperation + where TModel : class, IModel, new() { - private readonly IDocumentOperationWrapper _documentOperationWrapper; + private readonly IDocumentOperationWrapper _documentOperationWrapper; private const int BatchOperationSize = 500; - public DocumentOperation(IDocumentOperationWrapper documentOperationWrapper) + public DocumentOperation(IDocumentOperationWrapper documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; - public async Task AddOrUpdateDocumentAsync(TAzureModel model) + public async Task AddOrUpdateDocumentAsync(TModel model) { var azureBatchDocumentsOperationResult = await AddOrUpdateDocumentsAsync(new[] { model }); @@ -31,7 +31,7 @@ public async Task AddOrUpdateDocumentAsync(TAzureModel : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); } - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) { if (!models.HasAny()) { @@ -51,7 +51,7 @@ public async Task AddOrUpdateDocumentsAsync(IEnum foreach (var batchActions in chunkedBatchActions) { - var batch = IndexDocumentsBatch.Create(batchActions.ToArray()); + var batch = IndexDocumentsBatch.Create(batchActions.ToArray()); try { @@ -67,7 +67,7 @@ public async Task AddOrUpdateDocumentsAsync(IEnum return GetBatchOperationStatus(indexResults, "adding or updating"); } - public async Task TryRemoveDocumentAsync(TAzureModel model) + public async Task TryRemoveDocumentAsync(TModel model) { var azureBatchDocumentsOperationResult = await TryRemoveDocumentsAsync(new[] { model }); @@ -76,7 +76,7 @@ public async Task TryRemoveDocumentAsync(TAzureModel mo : azureBatchDocumentsOperationResult.FailedDocuments.FirstOrDefault(); } - public async Task TryRemoveDocumentsAsync(IEnumerable models) + public async Task TryRemoveDocumentsAsync(IEnumerable models) { if (!models.HasAny()) { @@ -96,7 +96,7 @@ public async Task TryRemoveDocumentsAsync(IEnumer foreach (var batchActions in chunkedBatchActions) { - var batch = IndexDocumentsBatch.Create(batchActions.ToArray()); + var batch = IndexDocumentsBatch.Create(batchActions.ToArray()); try { diff --git a/src/Cogworks.AzureSearch/Operations/IndexOperation.cs b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs index 730bae6..f08d3a8 100644 --- a/src/Cogworks.AzureSearch/Operations/IndexOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs @@ -7,14 +7,14 @@ namespace Cogworks.AzureSearch.Operations { - public class IndexOperation : IIndexOperation - where TAzureModel : class, IModel, new() + public class IndexOperation : IIndexOperation + where TModel : class, IModel, new() { - private readonly IndexDefinition _indexDefinition; + private readonly IndexDefinition _indexDefinition; private readonly IIndexOperationWrapper _indexOperationWrapper; public IndexOperation( - IndexDefinition indexDefinition, + IndexDefinition indexDefinition, IIndexOperationWrapper indexOperationWrapper) { _indexDefinition = indexDefinition; @@ -51,8 +51,8 @@ public async Task IndexCreateOrUpdateAsync() { _ = _indexDefinition.CustomIndexDefinition != null - ? await _indexOperationWrapper.CreateOrUpdateAsync(_indexDefinition.CustomIndexDefinition, true) - : await _indexOperationWrapper.CreateOrUpdateAsync(_indexDefinition.IndexName); + ? await _indexOperationWrapper.CreateOrUpdateAsync(_indexDefinition.CustomIndexDefinition, true) + : await _indexOperationWrapper.CreateOrUpdateAsync(_indexDefinition.IndexName); } catch (Exception exception) diff --git a/src/Cogworks.AzureSearch/Repositories/Repository.cs b/src/Cogworks.AzureSearch/Repositories/Repository.cs index ec6a101..587b1b5 100644 --- a/src/Cogworks.AzureSearch/Repositories/Repository.cs +++ b/src/Cogworks.AzureSearch/Repositories/Repository.cs @@ -8,33 +8,33 @@ namespace Cogworks.AzureSearch.Repositories { - internal class Repository : IRepository - where TAzureModel : class, IModel, new() + internal class Repository : IRepository + where TModel : class, IModel, new() { - private readonly IIndexOperation _indexOperation; - private readonly IDocumentOperation _documentOperation; - private readonly ISearcher _search; + private readonly IIndexOperation _indexOperation; + private readonly IDocumentOperation _documentOperation; + private readonly ISearcher _search; public Repository( - IIndexOperation indexOperation, - IDocumentOperation documentOperation, - ISearcher search) + IIndexOperation indexOperation, + IDocumentOperation documentOperation, + ISearcher search) { _indexOperation = indexOperation; _documentOperation = documentOperation; _search = search; } - public async Task AddOrUpdateDocumentAsync(TAzureModel model) + public async Task AddOrUpdateDocumentAsync(TModel model) => await _documentOperation.AddOrUpdateDocumentAsync(model); - public async Task AddOrUpdateDocumentsAsync(IEnumerable models) + public async Task AddOrUpdateDocumentsAsync(IEnumerable models) => await _documentOperation.AddOrUpdateDocumentsAsync(models); - public async Task TryRemoveDocumentAsync(TAzureModel model) + public async Task TryRemoveDocumentAsync(TModel model) => await _documentOperation.TryRemoveDocumentAsync(model); - public async Task TryRemoveDocumentsAsync(IEnumerable models) + public async Task TryRemoveDocumentsAsync(IEnumerable models) => await _documentOperation.TryRemoveDocumentsAsync(models); public async Task IndexExistsAsync() @@ -49,10 +49,10 @@ public async Task IndexCreateOrUpdateAsync() public async Task IndexClearAsync() => await _indexOperation.IndexClearAsync(); - public SearchResult Search(string keyword, SearchParameters searchParameters) + public SearchResult Search(string keyword, SearchParameters searchParameters) => _search.Search(keyword, searchParameters); - public async Task> SearchAsync(string keyword, + public async Task> SearchAsync(string keyword, SearchParameters searchParameters) => await _search.SearchAsync(keyword, searchParameters); } diff --git a/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs index b4f0d02..3767fd4 100644 --- a/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs +++ b/src/Cogworks.AzureSearch/Searchers/BaseDomainSearch.cs @@ -5,18 +5,18 @@ namespace Cogworks.AzureSearch.Searchers { - public abstract class BaseDomainSearch - where TAzureModel : class, IModel, new() + public abstract class BaseDomainSearch + where TModel : class, IModel, new() { - protected ISearcher Searcher { get; } + protected ISearcher Searcher { get; } - protected BaseDomainSearch(ISearcher search) + protected BaseDomainSearch(ISearcher search) => Searcher = search; - public virtual SearchResult Search(string keyword, SearchParameters searchParameters) + public virtual SearchResult Search(string keyword, SearchParameters searchParameters) => Searcher.Search(keyword, searchParameters); - public async Task> SearchAsync(string keyword, SearchParameters searchParameters) + public async Task> SearchAsync(string keyword, SearchParameters searchParameters) => await Searcher.SearchAsync(keyword, searchParameters); } } diff --git a/src/Cogworks.AzureSearch/Searchers/Searcher.cs b/src/Cogworks.AzureSearch/Searchers/Searcher.cs index cdb7c3e..5774cc6 100644 --- a/src/Cogworks.AzureSearch/Searchers/Searcher.cs +++ b/src/Cogworks.AzureSearch/Searchers/Searcher.cs @@ -8,15 +8,15 @@ namespace Cogworks.AzureSearch.Searchers { - internal class Searcher : ISearcher - where TAzureModel : class, IModel, new() + internal class Searcher : ISearcher + where TModel : class, IModel, new() { - private readonly IDocumentOperationWrapper _documentOperationWrapper; + private readonly IDocumentOperationWrapper _documentOperationWrapper; - public Searcher(IDocumentOperationWrapper documentOperationWrapper) + public Searcher(IDocumentOperationWrapper documentOperationWrapper) => _documentOperationWrapper = documentOperationWrapper; - public SearchResult Search(string keyword, SearchParameters searchParameters) + public SearchResult Search(string keyword, SearchParameters searchParameters) { var searchText = GetSearchText(keyword); var parameters = ParametersMapper.Map(searchParameters); @@ -28,7 +28,7 @@ public SearchResult Search(string keyword, SearchParameters searchP searchParameters.Take); } - public async Task> SearchAsync(string keyword, SearchParameters searchParameters) + public async Task> SearchAsync(string keyword, SearchParameters searchParameters) { var searchText = GetSearchText(keyword); var parameters = ParametersMapper.Map(searchParameters); diff --git a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs index 3935424..7b4a3c1 100644 --- a/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/DocumentOperationWrapper.cs @@ -10,13 +10,13 @@ namespace Cogworks.AzureSearch.Wrappers { - internal class DocumentOperationWrapper : IDocumentOperationWrapper - where TAzureModel : class, IModel, new() + internal class DocumentOperationWrapper : IDocumentOperationWrapper + where TModel : class, IModel, new() { private readonly SearchClient _searchClient; public DocumentOperationWrapper( - IndexDefinition indexDefinition, + IndexDefinition indexDefinition, ClientOption clientOption) { var azureKeyCredential = new AzureKeyCredential(clientOption.Credentials); @@ -30,13 +30,13 @@ public DocumentOperationWrapper( ); } - public SearchResults Search(string searchText, SearchOptions parameters = null) - => _searchClient.Search(searchText, parameters); + public SearchResults Search(string searchText, SearchOptions parameters = null) + => _searchClient.Search(searchText, parameters); - public async Task> SearchAsync(string searchText, SearchOptions parameters = null) - => await _searchClient.SearchAsync(searchText, parameters); + public async Task> SearchAsync(string searchText, SearchOptions parameters = null) + => await _searchClient.SearchAsync(searchText, parameters); - public async Task> IndexAsync(IndexDocumentsBatch indexBatch) + public async Task> IndexAsync(IndexDocumentsBatch indexBatch) => await _searchClient.IndexDocumentsAsync(indexBatch); } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs index 8d16f6a..d974320 100644 --- a/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs +++ b/src/Cogworks.AzureSearch/Wrappers/IndexOperationWrapper.cs @@ -28,10 +28,10 @@ public async Task ExistsAsync(string indexName) public async Task DeleteAsync(string indexName) => await _searchIndexClient.DeleteIndexAsync(indexName); - public async Task CreateOrUpdateAsync(string indexName) where TAzureModel : class, IModel, new() + public async Task CreateOrUpdateAsync(string indexName) where TModel : class, IModel, new() { var fieldBuilder = new FieldBuilder(); - var searchFields = fieldBuilder.Build(typeof(TAzureModel)); + var searchFields = fieldBuilder.Build(typeof(TModel)); var definition = new SearchIndex( indexName, @@ -40,12 +40,12 @@ public async Task DeleteAsync(string indexName) return await _searchIndexClient.CreateOrUpdateIndexAsync(definition); } - public async Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TAzureModel : class, IModel, new() + public async Task CreateOrUpdateAsync(SearchIndex customIndexDefinition, bool overrideFields) where TModel : class, IModel, new() { if (overrideFields) { var fieldBuilder = new FieldBuilder(); - var searchFields = fieldBuilder.Build(typeof(TAzureModel)); + var searchFields = fieldBuilder.Build(typeof(TModel)); customIndexDefinition.Fields = searchFields; } From 636030b9c1e58d1e40669eab8023d4ee0b153e24 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:42:36 +0200 Subject: [PATCH 26/31] refactor: renamed container builders --- ...reSearchBuilder.cs => ContainerBuilder.cs} | 34 ++++++++++--------- .../Extensions/AutofacExtensions.cs | 6 ++-- ...reSearchBuilder.cs => ContainerBuilder.cs} | 30 ++++++++-------- .../Extensions/RegisterExtensions.cs | 4 +-- ...reSearchBuilder.cs => ContainerBuilder.cs} | 30 ++++++++-------- .../Extensions/BuilderExtensions.cs | 4 +-- ...reSearchBuilder.cs => ContainerBuilder.cs} | 30 ++++++++-------- ...ks.AzureSearch.Umbraco.IocExtension.csproj | 2 +- .../Extensions/RegisterExtensions.cs | 8 ++--- .../Builder/IAzureSearchBuilder.cs | 29 ---------------- .../Interfaces/Builder/IContainerBuilder.cs | 29 ++++++++++++++++ .../AutofacIocExtensionTests.cs | 27 ++++++++------- .../LightInjectIocExtensionTests.cs | 12 +++---- .../MicrosoftIocExtensionTests.cs | 12 +++---- .../UmbracoIocExtensionTests.cs | 11 +++--- 15 files changed, 136 insertions(+), 132 deletions(-) rename src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/{AzureSearchBuilder.cs => ContainerBuilder.cs} (75%) rename src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/{AzureSearchBuilder.cs => ContainerBuilder.cs} (76%) rename src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/{AzureSearchBuilder.cs => ContainerBuilder.cs} (74%) rename src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/{AzureSearchBuilder.cs => ContainerBuilder.cs} (76%) delete mode 100644 src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs create mode 100644 src/Cogworks.AzureSearch/Interfaces/Builder/IContainerBuilder.cs diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/ContainerBuilder.cs similarity index 75% rename from src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs rename to src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/ContainerBuilder.cs index 1a7ee87..0f79410 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Builders/ContainerBuilder.cs @@ -1,8 +1,9 @@ using Autofac; +using AutofacContainerBuilder = Autofac.ContainerBuilder; using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; +using Cogworks.AzureSearch.Interfaces.Builder; using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; @@ -18,14 +19,15 @@ namespace Cogworks.AzureSearch.Autofac.Builders { - public class AzureSearchBuilder : IAzureSearchBuilder + + public class ContainerBuilder : IContainerBuilder { - private readonly ContainerBuilder _builder; + private readonly AutofacContainerBuilder _builder; - public AzureSearchBuilder(ContainerBuilder builder) + public ContainerBuilder(AutofacContainerBuilder builder) => _builder = builder; - internal AzureSearchBuilder RegisterInitializers() + internal ContainerBuilder RegisterInitializers() { _builder.RegisterGeneric(typeof(Initializer<>)) .As(typeof(IInitializer<>)) @@ -34,7 +36,7 @@ internal AzureSearchBuilder RegisterInitializers() return this; } - public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) + public IContainerBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { _ = _builder.Register(_ => new IndexOption(recreate, recreateOnUpdateFailure)) .AsSelf() @@ -43,7 +45,7 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) + public IContainerBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _ = _builder.Register(_ => new ClientOption( serviceName, @@ -55,7 +57,7 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) + public IContainerBuilder RegisterIndexDefinitions(string indexName) where TDocument : class, IModel, new() { _ = _builder.Register(_ => new IndexDefinition(indexName)) @@ -65,7 +67,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) + public IContainerBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IModel, new() { _ = _builder.Register(_ => new IndexDefinition(customIndex)) @@ -75,7 +77,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo return this; } - internal AzureSearchBuilder RegisterIndexes() + internal ContainerBuilder RegisterIndexes() { _ = _builder.RegisterGeneric(typeof(Index<>)) .As(typeof(IIndex<>)) @@ -84,7 +86,7 @@ internal AzureSearchBuilder RegisterIndexes() return this; } - internal AzureSearchBuilder RegisterWrappers() + internal ContainerBuilder RegisterWrappers() { _ = _builder.RegisterGeneric(typeof(DocumentOperationWrapper<>)) .As(typeof(IDocumentOperationWrapper<>)) @@ -97,7 +99,7 @@ internal AzureSearchBuilder RegisterWrappers() return this; } - internal AzureSearchBuilder RegisterRepositories() + internal ContainerBuilder RegisterRepositories() { _ = _builder.RegisterGeneric(typeof(Repository<>)) .As(typeof(IRepository<>)) @@ -106,7 +108,7 @@ internal AzureSearchBuilder RegisterRepositories() return this; } - internal AzureSearchBuilder RegisterSearchers() + internal ContainerBuilder RegisterSearchers() { _ = _builder.RegisterGeneric(typeof(Searcher<>)) .As(typeof(ISearcher<>)) @@ -115,7 +117,7 @@ internal AzureSearchBuilder RegisterSearchers() return this; } - internal AzureSearchBuilder RegisterOperations() + internal ContainerBuilder RegisterOperations() { _ = _builder.RegisterGeneric(typeof(DocumentOperation<>)) .As(typeof(IDocumentOperation<>)) @@ -128,7 +130,7 @@ internal AzureSearchBuilder RegisterOperations() return this; } - public IAzureSearchBuilder RegisterDomainSearcher() + public IContainerBuilder RegisterDomainSearcher() where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class @@ -141,7 +143,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) + public IContainerBuilder RegisterDomainSearcher(TSearcherType instance) where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class diff --git a/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs b/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs index f1765fc..222e1c4 100644 --- a/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs +++ b/src/Cogworks.AzureSearch.Autofac.IocExtension/Extensions/AutofacExtensions.cs @@ -1,12 +1,12 @@ -using Autofac; +using AutofacContainerBuilder = Autofac.ContainerBuilder; using Cogworks.AzureSearch.Autofac.Builders; namespace Cogworks.AzureSearch.Autofac.Extensions { public static class AutofacExtensions { - public static AzureSearchBuilder RegisterAzureSearch(this ContainerBuilder builder) - => new AzureSearchBuilder(builder) + public static ContainerBuilder RegisterAzureSearch(this AutofacContainerBuilder builder) + => new ContainerBuilder(builder) .RegisterRepositories() .RegisterIndexes() .RegisterSearchers() diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/ContainerBuilder.cs similarity index 76% rename from src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs rename to src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/ContainerBuilder.cs index 87323a4..75815b4 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Builders/ContainerBuilder.cs @@ -1,7 +1,7 @@ using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; +using Cogworks.AzureSearch.Interfaces.Builder; using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; @@ -18,14 +18,14 @@ namespace Cogworks.AzureSearch.LightInject.IocExtension.Builders { - public class AzureSearchBuilder : IAzureSearchBuilder + public class ContainerBuilder : IContainerBuilder { private readonly IServiceContainer _container; - public AzureSearchBuilder(IServiceContainer serviceContainer) + public ContainerBuilder(IServiceContainer serviceContainer) => _container = serviceContainer; - internal AzureSearchBuilder RegisterInitializers() + internal ContainerBuilder RegisterInitializers() { _ = _container.Register( typeof(IInitializer<>), @@ -34,7 +34,7 @@ internal AzureSearchBuilder RegisterInitializers() return this; } - public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) + public IContainerBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { _ = _container.Register( _ => new IndexOption(recreate, recreateOnUpdateFailure), @@ -43,7 +43,7 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) + public IContainerBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _ = _container.Register( _ => new ClientOption( @@ -55,7 +55,7 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) + public IContainerBuilder RegisterIndexDefinitions(string indexName) where TDocument : class, IModel, new() { _ = _container.Register( @@ -65,7 +65,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) + public IContainerBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IModel, new() { _ = _container.Register( @@ -75,7 +75,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo return this; } - internal AzureSearchBuilder RegisterIndexes() + internal ContainerBuilder RegisterIndexes() { _ = _container.Register( typeof(IIndex<>), @@ -84,7 +84,7 @@ internal AzureSearchBuilder RegisterIndexes() return this; } - internal AzureSearchBuilder RegisterWrappers() + internal ContainerBuilder RegisterWrappers() { _ = _container.Register( typeof(IDocumentOperationWrapper<>), @@ -95,7 +95,7 @@ internal AzureSearchBuilder RegisterWrappers() return this; } - internal AzureSearchBuilder RegisterRepositories() + internal ContainerBuilder RegisterRepositories() { _ = _container.Register( typeof(IRepository<>), @@ -104,7 +104,7 @@ internal AzureSearchBuilder RegisterRepositories() return this; } - internal AzureSearchBuilder RegisterSearchers() + internal ContainerBuilder RegisterSearchers() { _ = _container.Register( typeof(ISearcher<>), @@ -112,7 +112,7 @@ internal AzureSearchBuilder RegisterSearchers() return this; } - internal AzureSearchBuilder RegisterOperations() + internal ContainerBuilder RegisterOperations() { _ = _container.Register( typeof(IDocumentOperation<>), @@ -127,7 +127,7 @@ internal AzureSearchBuilder RegisterOperations() return this; } - public IAzureSearchBuilder RegisterDomainSearcher() + public IContainerBuilder RegisterDomainSearcher() where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class @@ -137,7 +137,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) + public IContainerBuilder RegisterDomainSearcher(TSearcherType instance) where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class diff --git a/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs b/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs index c537474..c447a5c 100644 --- a/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs +++ b/src/Cogworks.AzureSearch.LightInject.IocExtension/Extensions/RegisterExtensions.cs @@ -5,8 +5,8 @@ namespace Cogworks.AzureSearch.LightInject.IocExtension.Extensions { public static class RegisterExtensions { - public static AzureSearchBuilder RegisterAzureSearch(this IServiceContainer serviceContainer) - => new AzureSearchBuilder(serviceContainer) + public static ContainerBuilder RegisterAzureSearch(this IServiceContainer serviceContainer) + => new ContainerBuilder(serviceContainer) .RegisterRepositories() .RegisterIndexes() .RegisterSearchers() diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/ContainerBuilder.cs similarity index 74% rename from src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs rename to src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/ContainerBuilder.cs index bba21ef..af00b58 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Builders/ContainerBuilder.cs @@ -1,7 +1,7 @@ using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; +using Cogworks.AzureSearch.Interfaces.Builder; using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; @@ -19,28 +19,28 @@ namespace Cogworks.AzureSearch.Microsoft.IocExtension.Builders { - public class AzureSearchBuilder : IAzureSearchBuilder + public class ContainerBuilder : IContainerBuilder { private readonly IServiceCollection _serviceCollection; - public AzureSearchBuilder(IServiceCollection serviceCollection) + public ContainerBuilder(IServiceCollection serviceCollection) => _serviceCollection = serviceCollection; - internal AzureSearchBuilder RegisterInitializers() + internal ContainerBuilder RegisterInitializers() { _serviceCollection.TryAddScoped(typeof(IInitializer<>), typeof(Initializer<>)); return this; } - public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) + public IContainerBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { _serviceCollection.TryAddSingleton(_ => new IndexOption(recreate, recreateOnUpdateFailure)); return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) + public IContainerBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _serviceCollection.TryAddSingleton(_ => new ClientOption( serviceName, @@ -50,7 +50,7 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) + public IContainerBuilder RegisterIndexDefinitions(string indexName) where TDocument : class, IModel, new() { _serviceCollection.TryAddSingleton(_ => new IndexDefinition(indexName)); @@ -58,7 +58,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) + public IContainerBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IModel, new() { _serviceCollection.TryAddSingleton(_ => new IndexDefinition(customIndex)); @@ -66,14 +66,14 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo return this; } - internal AzureSearchBuilder RegisterIndexes() + internal ContainerBuilder RegisterIndexes() { _serviceCollection.TryAddScoped(typeof(IIndex<>), typeof(Index<>)); return this; } - internal AzureSearchBuilder RegisterWrappers() + internal ContainerBuilder RegisterWrappers() { _serviceCollection.TryAddScoped(typeof(IDocumentOperationWrapper<>), typeof(DocumentOperationWrapper<>)); @@ -82,7 +82,7 @@ internal AzureSearchBuilder RegisterWrappers() return this; } - internal AzureSearchBuilder RegisterRepositories() + internal ContainerBuilder RegisterRepositories() { _serviceCollection.TryAddScoped( typeof(IRepository<>), @@ -91,14 +91,14 @@ internal AzureSearchBuilder RegisterRepositories() return this; } - internal AzureSearchBuilder RegisterSearchers() + internal ContainerBuilder RegisterSearchers() { _serviceCollection.TryAddScoped(typeof(ISearcher<>), typeof(Searcher<>)); return this; } - internal AzureSearchBuilder RegisterOperations() + internal ContainerBuilder RegisterOperations() { _serviceCollection.TryAddScoped(typeof(IDocumentOperation<>), typeof(DocumentOperation<>)); @@ -107,7 +107,7 @@ internal AzureSearchBuilder RegisterOperations() return this; } - public IAzureSearchBuilder RegisterDomainSearcher() + public IContainerBuilder RegisterDomainSearcher() where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class @@ -117,7 +117,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) + public IContainerBuilder RegisterDomainSearcher(TSearcherType instance) where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class diff --git a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs index 86ef4aa..99b98f8 100644 --- a/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs +++ b/src/Cogworks.AzureSearch.Microsoft.IocExtension/Extensions/BuilderExtensions.cs @@ -5,8 +5,8 @@ namespace Cogworks.AzureSearch.Microsoft.IocExtension.Extensions { public static class BuilderExtensions { - public static AzureSearchBuilder RegisterAzureSearch(this IServiceCollection serviceCollection) - => new AzureSearchBuilder(serviceCollection) + public static ContainerBuilder RegisterAzureSearch(this IServiceCollection serviceCollection) + => new ContainerBuilder(serviceCollection) .RegisterRepositories() .RegisterIndexes() .RegisterSearchers() diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/ContainerBuilder.cs similarity index 76% rename from src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs rename to src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/ContainerBuilder.cs index 6afa0dc..65b39b1 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/AzureSearchBuilder.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Builders/ContainerBuilder.cs @@ -1,7 +1,7 @@ using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Indexes; using Cogworks.AzureSearch.Initializers; +using Cogworks.AzureSearch.Interfaces.Builder; using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; @@ -19,14 +19,14 @@ namespace Cogworks.AzureSearch.Umbraco.IocExtension.Builders { - public class AzureSearchBuilder : IAzureSearchBuilder + public class ContainerBuilder : IContainerBuilder { private readonly IRegister _composingRegister; - public AzureSearchBuilder(IRegister composingRegister) + public ContainerBuilder(IRegister composingRegister) => _composingRegister = composingRegister; - internal AzureSearchBuilder RegisterInitializers() + internal ContainerBuilder RegisterInitializers() { _composingRegister.Register( typeof(IInitializer<>), @@ -35,7 +35,7 @@ internal AzureSearchBuilder RegisterInitializers() return this; } - public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) + public IContainerBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false) { _composingRegister.Register( _ => new IndexOption(recreate, recreateOnUpdateFailure), @@ -44,7 +44,7 @@ public IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUp return this; } - public IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) + public IContainerBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl) { _composingRegister.Register( _ => new ClientOption( @@ -56,7 +56,7 @@ public IAzureSearchBuilder RegisterClientOptions(string serviceName, string cred return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) + public IContainerBuilder RegisterIndexDefinitions(string indexName) where TDocument : class, IModel, new() { _composingRegister.Register( @@ -66,7 +66,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(string indexName) return this; } - public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) + public IContainerBuilder RegisterIndexDefinitions(SearchIndex customIndex) where TDocument : class, IModel, new() { _composingRegister.Register( @@ -76,7 +76,7 @@ public IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex custo return this; } - internal AzureSearchBuilder RegisterIndexes() + internal ContainerBuilder RegisterIndexes() { _composingRegister.Register( typeof(IIndex<>), @@ -85,7 +85,7 @@ internal AzureSearchBuilder RegisterIndexes() return this; } - internal AzureSearchBuilder RegisterWrappers() + internal ContainerBuilder RegisterWrappers() { _composingRegister.Register( typeof(IDocumentOperationWrapper<>), @@ -96,7 +96,7 @@ internal AzureSearchBuilder RegisterWrappers() return this; } - internal AzureSearchBuilder RegisterRepositories() + internal ContainerBuilder RegisterRepositories() { _composingRegister.Register( typeof(IRepository<>), @@ -105,7 +105,7 @@ internal AzureSearchBuilder RegisterRepositories() return this; } - internal AzureSearchBuilder RegisterSearchers() + internal ContainerBuilder RegisterSearchers() { _composingRegister.Register( typeof(ISearcher<>), @@ -114,7 +114,7 @@ internal AzureSearchBuilder RegisterSearchers() return this; } - internal AzureSearchBuilder RegisterOperations() + internal ContainerBuilder RegisterOperations() { _composingRegister.Register( typeof(IDocumentOperation<>), @@ -127,7 +127,7 @@ internal AzureSearchBuilder RegisterOperations() return this; } - public IAzureSearchBuilder RegisterDomainSearcher() + public IContainerBuilder RegisterDomainSearcher() where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class @@ -137,7 +137,7 @@ public IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) + public IContainerBuilder RegisterDomainSearcher(TSearcherType instance) where TDocument : class, IModel, new() where TSearcher : BaseDomainSearch, TSearcherType where TSearcherType : class diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj index 4e585b5..ebb4bbd 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj @@ -179,7 +179,7 @@ - + diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs index 05c7642..4761066 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Extensions/RegisterExtensions.cs @@ -1,4 +1,4 @@ -using Cogworks.AzureSearch.Builder; +using Cogworks.AzureSearch.Interfaces.Builder; using Cogworks.AzureSearch.LightInject.IocExtension.Extensions; using Cogworks.AzureSearch.Umbraco.IocExtension.Builders; using LightInject; @@ -8,10 +8,10 @@ namespace Cogworks.AzureSearch.Umbraco.IocExtension.Extensions { public static class RegisterExtensions { - public static IAzureSearchBuilder RegisterAzureSearch(this IRegister composingRegister, bool useConcreteContainer = false) + public static IContainerBuilder RegisterAzureSearch(this IRegister composingRegister, bool useConcreteContainer = false) => useConcreteContainer - ? (composingRegister.Concrete as IServiceContainer).RegisterAzureSearch() as IAzureSearchBuilder - : new AzureSearchBuilder(composingRegister) + ? (composingRegister.Concrete as IServiceContainer).RegisterAzureSearch() as IContainerBuilder + : new ContainerBuilder(composingRegister) .RegisterRepositories() .RegisterIndexes() .RegisterSearchers() diff --git a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs b/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs deleted file mode 100644 index d77c3aa..0000000 --- a/src/Cogworks.AzureSearch/Builder/IAzureSearchBuilder.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Azure.Search.Documents.Indexes.Models; -using Cogworks.AzureSearch.Models; -using Cogworks.AzureSearch.Searchers; - -namespace Cogworks.AzureSearch.Builder -{ - public interface IAzureSearchBuilder - { - IAzureSearchBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false); - - IAzureSearchBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl); - - IAzureSearchBuilder RegisterIndexDefinitions(string indexName) - where TDocument : class, IModel, new(); - - IAzureSearchBuilder RegisterIndexDefinitions(SearchIndex customIndex) - where TDocument : class, IModel, new(); - - IAzureSearchBuilder RegisterDomainSearcher() - where TDocument : class, IModel, new() - where TSearcher : BaseDomainSearch, TSearcherType - where TSearcherType : class; - - IAzureSearchBuilder RegisterDomainSearcher(TSearcherType instance) - where TDocument : class, IModel, new() - where TSearcher : BaseDomainSearch, TSearcherType - where TSearcherType : class; - } -} \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Interfaces/Builder/IContainerBuilder.cs b/src/Cogworks.AzureSearch/Interfaces/Builder/IContainerBuilder.cs new file mode 100644 index 0000000..4383b2a --- /dev/null +++ b/src/Cogworks.AzureSearch/Interfaces/Builder/IContainerBuilder.cs @@ -0,0 +1,29 @@ +using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Models; +using Cogworks.AzureSearch.Searchers; + +namespace Cogworks.AzureSearch.Interfaces.Builder +{ + public interface IContainerBuilder + { + IContainerBuilder RegisterIndexOptions(bool recreate, bool recreateOnUpdateFailure = false); + + IContainerBuilder RegisterClientOptions(string serviceName, string credentials, string serviceEndpointUrl); + + IContainerBuilder RegisterIndexDefinitions(string indexName) + where TDocument : class, IModel, new(); + + IContainerBuilder RegisterIndexDefinitions(SearchIndex customIndex) + where TDocument : class, IModel, new(); + + IContainerBuilder RegisterDomainSearcher() + where TDocument : class, IModel, new() + where TSearcher : BaseDomainSearch, TSearcherType + where TSearcherType : class; + + IContainerBuilder RegisterDomainSearcher(TSearcherType instance) + where TDocument : class, IModel, new() + where TSearcher : BaseDomainSearch, TSearcherType + where TSearcherType : class; + } +} \ No newline at end of file diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index 7741b05..dd3bc7f 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -1,6 +1,5 @@ -using Autofac; +using AutofacContainerBuilder = Autofac.ContainerBuilder; using Cogworks.AzureSearch.Autofac.Extensions; -using Cogworks.AzureSearch.Builder; using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; @@ -9,18 +8,20 @@ using Cogworks.AzureSearch.Models; using NSubstitute; using System; +using Autofac; using Cogworks.AzureSearch.AutofacIoc.UnitTests.Models; using Cogworks.AzureSearch.AutofacIoc.UnitTests.Searchers; using Xunit; using Azure.Search.Documents.Indexes.Models; using Azure.Search.Documents.Models; +using Cogworks.AzureSearch.Interfaces.Builder; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests { public class AutofacIocExtensionTests { - private readonly IAzureSearchBuilder _azureSearchBuilder; - private readonly ContainerBuilder _containerBuilder; + private readonly IContainerBuilder _containerBuilder; + private readonly AutofacContainerBuilder _autofacContainerBuilder; private const string FirstDocumentIndexName = "first-test-document"; private const string SecondDocumentIndexName = "second-test-document"; @@ -28,9 +29,9 @@ public class AutofacIocExtensionTests public AutofacIocExtensionTests() { - _containerBuilder = new ContainerBuilder(); + _autofacContainerBuilder = new AutofacContainerBuilder(); - _azureSearchBuilder = _containerBuilder.RegisterAzureSearch() + _containerBuilder = _autofacContainerBuilder.RegisterAzureSearch() .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) @@ -62,7 +63,7 @@ public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) // Arrange // ReSharper disable once PossibleNullReferenceException - using (var scope = _containerBuilder.Build().BeginLifetimeScope().BeginLifetimeScope()) + using (var scope = _autofacContainerBuilder.Build().BeginLifetimeScope().BeginLifetimeScope()) { // Act var instance = scope.Resolve(desiredObjectType); @@ -120,7 +121,7 @@ public void Should_ThrowException_When_IndexNotRegistered(Type desiredObjectType var exceptionRecord = Record.Exception(() => { // ReSharper disable once PossibleNullReferenceException - using (var scope = _containerBuilder.Build().BeginLifetimeScope()) + using (var scope = _autofacContainerBuilder.Build().BeginLifetimeScope()) { // Act _ = scope.Resolve(desiredObjectType); @@ -146,10 +147,10 @@ public void Should_Not_ThrowException_When_GettingCustomSearchService() public void Should_ReturnCustomSearchService() { // Arrange - _azureSearchBuilder.RegisterDomainSearcher(); + _containerBuilder.RegisterDomainSearcher(); // ReSharper disable once PossibleNullReferenceException - using (var scope = _containerBuilder.Build().BeginLifetimeScope()) + using (var scope = _autofacContainerBuilder.Build().BeginLifetimeScope()) { var customTestSearch = scope.Resolve(); @@ -167,10 +168,10 @@ public void Should_InvokeCustomSearchServiceDomainMethod() // Arrange var mockedCustomTestSearch = Substitute.For(); - _azureSearchBuilder.RegisterDomainSearcher(mockedCustomTestSearch); + _containerBuilder.RegisterDomainSearcher(mockedCustomTestSearch); // ReSharper disable once PossibleNullReferenceException - using (var scope = _containerBuilder.Build().BeginLifetimeScope()) + using (var scope = _autofacContainerBuilder.Build().BeginLifetimeScope()) { var customTestSearch = scope.Resolve(); @@ -205,7 +206,7 @@ public void Should_GetDedicatedIndexWithProperName() // Act // ReSharper disable once PossibleNullReferenceException - using (var scope = _containerBuilder.Build().BeginLifetimeScope()) + using (var scope = _autofacContainerBuilder.Build().BeginLifetimeScope()) { var firstTestDocumentIndexDefinition = scope.Resolve>(); var secondTestDocumentIndexDefinition = scope.Resolve>(); diff --git a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs index 2e34e6c..99bfc92 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.LightInject.UnitTests/LightInjectIocExtensionTests.cs @@ -1,5 +1,4 @@ -using Cogworks.AzureSearch.Builder; -using Cogworks.AzureSearch.Interfaces.Indexes; +using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Interfaces.Repositories; @@ -12,13 +11,14 @@ using NSubstitute; using System; using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Interfaces.Builder; using Xunit; namespace Cogworks.AzureSearch.LightInject.UnitTests { public class LightInjectIocExtensionTests { - private readonly IAzureSearchBuilder _azureSearchBuilder; + private readonly IContainerBuilder _containerBuilder; private readonly IServiceContainer _container; private const string FirstDocumentIndexName = "first-test-document"; @@ -29,7 +29,7 @@ public LightInjectIocExtensionTests() { _container = new ServiceContainer(); - _azureSearchBuilder = _container.RegisterAzureSearch() + _containerBuilder = _container.RegisterAzureSearch() .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) @@ -143,7 +143,7 @@ public void Should_Not_ThrowException_When_GettingCustomSearchService() public void Should_ReturnCustomSearchService() { // Arrange - _azureSearchBuilder.RegisterDomainSearcher(); + _containerBuilder.RegisterDomainSearcher(); // ReSharper disable once PossibleNullReferenceException using (var scope = _container.BeginScope()) @@ -161,7 +161,7 @@ public void Should_InvokeCustomSearchServiceDomainMethod() // Arrange var mockedCustomTestSearch = Substitute.For(); - _azureSearchBuilder.RegisterDomainSearcher(mockedCustomTestSearch); + _containerBuilder.RegisterDomainSearcher(mockedCustomTestSearch); // ReSharper disable once PossibleNullReferenceException using (var scope = _container.BeginScope()) diff --git a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs index d44b27a..52289aa 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.MicrosoftIoc.UnitTests/MicrosoftIocExtensionTests.cs @@ -1,5 +1,4 @@ -using Cogworks.AzureSearch.Builder; -using Cogworks.AzureSearch.Interfaces.Indexes; +using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; using Cogworks.AzureSearch.Interfaces.Repositories; @@ -10,6 +9,7 @@ using NSubstitute; using System; using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Interfaces.Builder; using Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Models; using Cogworks.AzureSearch.MicrosoftIoc.UnitTests.Searchers; using Xunit; @@ -18,7 +18,7 @@ namespace Cogworks.AzureSearch.MicrosoftIoc.UnitTests { public class MicrosoftIocExtensionTests { - private readonly IAzureSearchBuilder _azureSearchBuilder; + private readonly IContainerBuilder _containerBuilder; private readonly IServiceCollection _serviceContainer; private const string FirstDocumentIndexName = "first-test-document"; @@ -29,7 +29,7 @@ public MicrosoftIocExtensionTests() { _serviceContainer = new ServiceCollection(); - _azureSearchBuilder = _serviceContainer.RegisterAzureSearch() + _containerBuilder = _serviceContainer.RegisterAzureSearch() .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) @@ -145,7 +145,7 @@ public void Should_Not_ThrowException_When_GettingCustomSearchService() public void Should_ReturnCustomSearchService() { // Arrange - _azureSearchBuilder.RegisterDomainSearcher(); + _containerBuilder.RegisterDomainSearcher(); // ReSharper disable once PossibleNullReferenceException using (var serviceProvider = _serviceContainer.BuildServiceProvider()) @@ -163,7 +163,7 @@ public void Should_InvokeCustomSearchServiceDomainMethod() // Arrange var mockedCustomTestSearch = Substitute.For(); - _azureSearchBuilder.RegisterDomainSearcher(mockedCustomTestSearch); + _containerBuilder.RegisterDomainSearcher(mockedCustomTestSearch); // ReSharper disable once PossibleNullReferenceException using (var serviceProvider = _serviceContainer.BuildServiceProvider()) diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs index a7f0f50..6f87448 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/UmbracoIocExtensionTests.cs @@ -1,5 +1,5 @@ // ReSharper disable PossibleNullReferenceException -using Cogworks.AzureSearch.Builder; + using Cogworks.AzureSearch.Interfaces.Indexes; using Cogworks.AzureSearch.Interfaces.Initializers; using Cogworks.AzureSearch.Interfaces.Operations; @@ -13,6 +13,7 @@ using NSubstitute; using System; using Azure.Search.Documents.Indexes.Models; +using Cogworks.AzureSearch.Interfaces.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Composing.LightInject; using Xunit; @@ -21,7 +22,7 @@ namespace Cogworks.AzureSearch.UmbracoIoc.UnitTests { public class UmbracoIocExtensionTests { - private readonly IAzureSearchBuilder _azureSearchBuilder; + private readonly IContainerBuilder _containerBuilder; private readonly Composition _composing; private const string FirstDocumentIndexName = "first-test-document"; @@ -34,7 +35,7 @@ public UmbracoIocExtensionTests() _composing = new Composition(lightInjectContainer, null, null, null, null); - _azureSearchBuilder = _composing.RegisterAzureSearch() + _containerBuilder = _composing.RegisterAzureSearch() .RegisterClientOptions("test", "test", "https://localhost") .RegisterIndexOptions(false, false) .RegisterIndexDefinitions(FirstDocumentIndexName) @@ -151,7 +152,7 @@ public void Should_Not_ThrowException_When_GettingCustomSearchService() public void Should_ReturnCustomSearchService() { // Arrange - _azureSearchBuilder.RegisterDomainSearcher(); + _containerBuilder.RegisterDomainSearcher(); var container = _composing.Concrete as ServiceContainer as IServiceContainer; @@ -170,7 +171,7 @@ public void Should_InvokeCustomSearchServiceDomainMethod() // Arrange var mockedCustomTestSearch = Substitute.For(); - _azureSearchBuilder.RegisterDomainSearcher(mockedCustomTestSearch); + _containerBuilder.RegisterDomainSearcher(mockedCustomTestSearch); var container = _composing.Concrete as ServiceContainer as IServiceContainer; From 75871933d2426348906b56ea0f5aef10410041e7 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 13:44:18 +0200 Subject: [PATCH 27/31] refactor: changed field name --- .../Operations/DocumentOperationTests.cs | 4 ++-- .../Operations/IndexOperationTests.cs | 8 ++++---- .../UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs index eaacd75..b096563 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/DocumentOperationTests.cs @@ -19,8 +19,8 @@ public class DocumentOperationTests : TestBase public DocumentOperationTests() => _documentOperation = new Repository( - IndexOperationService, - DocumentOperationService, + IndexOperation, + DocumentOperation, Search); [Theory] diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs index 18d201d..902e23b 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/Operations/IndexOperationTests.cs @@ -20,8 +20,8 @@ public class IndexOperationTests : TestBase public IndexOperationTests() => _indexOperation = new Repository( - IndexOperationService, - DocumentOperationService, + IndexOperation, + DocumentOperation, Search); #region Exists Tests @@ -165,7 +165,7 @@ public async Task Should_CreateOrUpdateCustomIndex() var azureIndexOperation = new Repository( customIndexOperationService, - DocumentOperationService, + DocumentOperation, Search); // Act @@ -207,7 +207,7 @@ public async Task Should_ThrowException_When_IssueOnCreatingOrUpdatingCustomInde var azureIndexOperation = new Repository( customIndexOperationService, - DocumentOperationService, + DocumentOperation, Search); _ = IndexOperationWrapper.CreateOrUpdateAsync(Arg.Any(), Arg.Any()) diff --git a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs index bcee22b..68ff4fd 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.UnitTests/TestBase.cs @@ -22,8 +22,8 @@ public abstract class TestBase protected readonly IndexDefinition TestDocumentModelDefinition; protected readonly ISearcher Search; - protected readonly IDocumentOperation DocumentOperationService; - protected readonly IIndexOperation IndexOperationService; + protected readonly IDocumentOperation DocumentOperation; + protected readonly IIndexOperation IndexOperation; protected TestBase() { @@ -34,10 +34,10 @@ protected TestBase() Search = Substitute.For>(); - DocumentOperationService = new DocumentOperation( + DocumentOperation = new DocumentOperation( DocumentOperationWrapper); - IndexOperationService = new IndexOperation( + IndexOperation = new IndexOperation( TestDocumentModelDefinition, IndexOperationWrapper); } From 220d58e5891e418c906047b48bc3daaae4d8f8f3 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Wed, 12 May 2021 14:52:44 +0200 Subject: [PATCH 28/31] refactor: added all cs files as compile for net framework projects --- .../Cogworks.AzureSearch.Umbraco.IocExtension.csproj | 4 +--- .../Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj | 8 +------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj index ebb4bbd..897f01b 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.csproj @@ -179,9 +179,7 @@ - - - + diff --git a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj index 729f31a..bafac6e 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj +++ b/tests/UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests/Cogworks.AzureSearch.UmbracoIoc.UnitTests.csproj @@ -252,13 +252,7 @@ - - - - - - - + From 83009ee8b02037a67700bdb921293bb73c27e508 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Thu, 13 May 2021 11:49:47 +0200 Subject: [PATCH 29/31] chore: removed new lines --- .../Exceptions/IndexExceptions/IndexClearException.cs | 1 - .../Exceptions/IndexExceptions/IndexExistsException.cs | 1 - src/Cogworks.AzureSearch/Operations/IndexOperation.cs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexClearException.cs b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexClearException.cs index 6da901d..4dfc082 100644 --- a/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexClearException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexClearException.cs @@ -13,6 +13,5 @@ public IndexClearException(string message) : base(message) public IndexClearException(string message, Exception innerException) : base(message, innerException) { } - } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexExistsException.cs b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexExistsException.cs index cdad8db..7a669d2 100644 --- a/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexExistsException.cs +++ b/src/Cogworks.AzureSearch/Exceptions/IndexExceptions/IndexExistsException.cs @@ -13,6 +13,5 @@ public IndexExistsException(string message) : base(message) public IndexExistsException(string message, Exception innerException) : base(message, innerException) { } - } } \ No newline at end of file diff --git a/src/Cogworks.AzureSearch/Operations/IndexOperation.cs b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs index f08d3a8..e4a7acb 100644 --- a/src/Cogworks.AzureSearch/Operations/IndexOperation.cs +++ b/src/Cogworks.AzureSearch/Operations/IndexOperation.cs @@ -72,7 +72,6 @@ public async Task IndexClearAsync() } await IndexCreateOrUpdateAsync(); - } catch (Exception exception) { From 8f4775f8fffad6671281e658e5f6c6a057a88248 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Thu, 13 May 2021 11:50:21 +0200 Subject: [PATCH 30/31] chore: removed unused using --- .../AutofacIocExtensionTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs index dd3bc7f..e0e52fd 100644 --- a/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs +++ b/tests/UnitTests/Cogworks.AzureSearch.AutofacIoc.UnitTests/AutofacIocExtensionTests.cs @@ -13,7 +13,6 @@ using Cogworks.AzureSearch.AutofacIoc.UnitTests.Searchers; using Xunit; using Azure.Search.Documents.Indexes.Models; -using Azure.Search.Documents.Models; using Cogworks.AzureSearch.Interfaces.Builder; namespace Cogworks.AzureSearch.AutofacIoc.UnitTests From 04dfebb7701fec13a9fd5e536422426ef40c7052 Mon Sep 17 00:00:00 2001 From: Adrian Ochmann Date: Thu, 13 May 2021 13:10:05 +0200 Subject: [PATCH 31/31] chore: changed tabs to spaces --- ...ks.AzureSearch.Umbraco.IocExtension.nuspec | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec index 3702b15..0d24c29 100644 --- a/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec +++ b/src/Cogworks.AzureSearch.Umbraco.IocExtension/Cogworks.AzureSearch.Umbraco.IocExtension.nuspec @@ -1,30 +1,30 @@  - - Cogworks.AzureSearch.Umbraco.IocExtension - $version$ - Cogworks.AzureSearch.Umbraco.IocExtension - Cogworks - Cogworks - https://github.com/thecogworks/Cogworks.AzureSearch - - Apache-2.0 - false - A wrapper to Azure Search allowing to easily setup Azure Search indexes, searchers and using it with DI/IoC approach (currently with support for Umbraco, LightInject and Autofac). - The Cogworks Limited 2020 - Azure Search, Umbraco - - - - - - - - - - - - - - + + Cogworks.AzureSearch.Umbraco.IocExtension + $version$ + Cogworks.AzureSearch.Umbraco.IocExtension + Cogworks + Cogworks + https://github.com/thecogworks/Cogworks.AzureSearch + + Apache-2.0 + false + A wrapper to Azure Search allowing to easily setup Azure Search indexes, searchers and using it with DI/IoC approach (currently with support for Umbraco, LightInject and Autofac). + The Cogworks Limited 2020 + Azure Search, Umbraco + + + + + + + + + + + + + + \ No newline at end of file