/// <summary> /// Initializes a new instance of the IndexDocumentsAction class. /// </summary> /// <param name="type"> /// The operation to perform on the document. /// </param> /// <param name="doc">The document to index.</param> public IndexDocumentsAction(IndexActionType type, T doc) { Debug.Assert(Enum.IsDefined(typeof(IndexActionType), type)); ActionType = type; Document = doc; }
private static void AssertSearchBatch( string packageId, IndexBatch <KeyedDocument> batch, IndexActionType exDefault, IndexActionType exIncludePrerelease, IndexActionType exIncludeSemVer2, IndexActionType exIncludePrereleaseAndSemVer2) { Assert.Equal(4, batch.Actions.Count()); var defaultSearch = Assert.Single( batch.Actions, x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.Default) == x.Document.Key); Assert.Equal(exDefault, defaultSearch.ActionType); var includePrereleaseSearch = Assert.Single( batch.Actions, x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.IncludePrerelease) == x.Document.Key); Assert.Equal(exIncludePrerelease, includePrereleaseSearch.ActionType); var includeSemVer2Search = Assert.Single( batch.Actions, x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.IncludeSemVer2) == x.Document.Key); Assert.Equal(exIncludeSemVer2, includeSemVer2Search.ActionType); var includePrereleaseAndSemVer2Search = Assert.Single( batch.Actions, x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.IncludePrereleaseAndSemVer2) == x.Document.Key); Assert.Equal(exIncludePrereleaseAndSemVer2, includePrereleaseAndSemVer2Search.ActionType); }
/// <inheritdoc/> public async Task <bool> ChangeDocumentAsync <T>(IEnumerable <T> documents, IndexActionType indexActionType) where T : class { Argument.EnsureNotEmpty(nameof(documents), documents); return(await Connection.ChangeDocumentsInIndexAsync(documents.ToSortedDictionary( q => q, q => indexActionType ))); }
/// <inheritdoc/> public async Task <bool> ChangeDocumentAsync <T>(T document, IndexActionType indexActionType) where T : class { Argument.EnsureNotNull(nameof(document), document); return(await Connection.ChangeDocumentsInIndexAsync(new SortedDictionary <T, IndexActionType>() { { document, indexActionType } })); }
/// <summary> /// Initializes a new instance of the IndexDocumentsBatch class. /// </summary> /// <param name="type"> /// The operation to perform on a document in an indexing batch. /// </param> /// <param name="documents"> /// The collection of documents to index. /// </param> internal IndexDocumentsBatch(IndexActionType type, IEnumerable <T> documents) { Debug.Assert(Enum.IsDefined(typeof(IndexActionType), type)); Debug.Assert(documents != null); if (documents != null) { foreach (T doc in documents) { Actions.Add(new IndexDocumentsAction <T>(type, doc)); } } }
private async Task CrudTest(Func <Listing, Task <Listing> > crudAction, IndexActionType indexActionType) { var changingCrudActions = new[] { IndexActionType.Delete, IndexActionType.Upload }; var listing = await DataAssert.Data.SearchQuery <Listing>().FirstOrDefaultAsync(); var originalListing = new Listing(listing); var allListingsCount = await DataAssert.Data.SearchQuery <Listing>().CountAsync(); Listing crudActionResult = await crudAction(listing); if (changingCrudActions.Contains(indexActionType)) { var isDeleteAction = indexActionType == IndexActionType.Delete; var allListingsShouldCount = allListingsCount + (isDeleteAction ? -1 : +1); var changedListing = await GetListingAfterChange(q => q.Id == listing.Id, isDeleteAction); var newAllListingsCount = await DataAssert.Data.SearchQuery <Listing>().CountAsync(); if (isDeleteAction) { Assert.Null(changedListing); await DataAssert.Data.SearchContext().AddAsync(originalListing); } else { Assert.Equal(crudActionResult, changedListing); await DataAssert.Data.SearchContext().RemoveAsync(originalListing); } DataAssert.Data.WaitForSearchOperationCompletion(allListingsCount); Assert.Equal(allListingsShouldCount, newAllListingsCount); } else { var updatedListing = await GetListingAfterChange(q => q.Id == listing.Id); await DataAssert.Data.SearchContext().UpdateAsync(originalListing); Assert.Equal(listing, updatedListing); } }
internal static string ToSerializedValue(this IndexActionType value) { switch (value) { case IndexActionType.Upload: return("upload"); case IndexActionType.Merge: return("merge"); case IndexActionType.MergeOrUpload: return("mergeOrUpload"); case IndexActionType.Delete: return("delete"); } return(null); }
/// <summary> /// Convert an enum of type IndexActionType to a string. /// </summary> /// <param name='value'> /// The value to convert to a string. /// </param> /// <returns> /// The enum value as a string. /// </returns> internal static string IndexActionTypeToString(IndexActionType value) { if (value == IndexActionType.Upload) { return("upload"); } if (value == IndexActionType.Merge) { return("merge"); } if (value == IndexActionType.MergeOrUpload) { return("mergeOrUpload"); } if (value == IndexActionType.Delete) { return("delete"); } throw new ArgumentOutOfRangeException("value"); }
/// <summary> /// Initializes a new instance of the IndexAction class with the given action type. /// </summary> /// <param name="actionType">The type of action to perform on the document.</param> /// <param name="document">The document on which the action will be performed.</param> public IndexAction(IndexActionType actionType, T document) : base(actionType, document) { }
public static string ToSerialString(this IndexActionType value) => value switch {
/// <summary> /// Initializes a new instance of the IndexAction class with the given action type. /// </summary> /// <param name="actionType">The type of action to perform on the document.</param> /// <param name="document">The document on which the action will be performed.</param> public IndexAction(IndexActionType actionType, Document document) : base(actionType, document) { // Do nothing. }
/// <summary> /// Initializes a new instance of the IndexAction class with the given action type. /// </summary> /// <param name="actionType">The type of action to perform on the document.</param> public IndexAction(IndexActionType actionType) : this(actionType, null) { // Do nothing. }
/// <summary> /// Initializes a new instance of the IndexAction class with the given action type. /// </summary> /// <param name="actionType">The type of action to perform on the document.</param> /// <param name="document">The document on which the action will be performed.</param> public IndexAction(IndexActionType actionType, T document) : this(document) { ActionType = actionType; }
internal IndexAction(IndexActionType actionType, T document) : base(actionType, document) { }
/// <summary> /// Initializes a new instance of the IndexActionBase class with the given action type. /// </summary> /// <param name="actionType">The type of action to perform on the document.</param> /// <param name="document">The document on which the action will be performed.</param> protected IndexActionBase(IndexActionType actionType, T document) { Document = document; ActionType = actionType; }
/// <summary> /// Initializes a new instance of the IndexAction class with the given action type. /// </summary> /// <param name="actionType">The type of action to perform on the document.</param> public IndexAction(IndexActionType actionType) : base(actionType) { // Do nothing. }
/// <summary> /// Initializes a new instance of the IndexAction class. /// </summary> /// <param name="document">The document on which the action will be performed.</param> /// <param name="actionType">The operation to perform on a document in /// an indexing batch. Possible values include: 'upload', 'merge', /// 'mergeOrUpload', 'delete'</param> public IndexAction(T document = default(T), IndexActionType actionType = default(IndexActionType)) { Document = document; ActionType = actionType; CustomInit(); }
/// <summary> /// Creates a new instance of the IndexAction class. /// </summary> /// <typeparam name="T"> /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index. /// </typeparam> /// <param name="actionType">The type of action to perform on the document.</param> /// <param name="document">The document on which the action will be performed.</param> /// <returns>A new IndexAction.</returns> /// <remarks> /// You can use this method as a convenience if you don't want to explicitly specify your model class as a /// type parameter. /// </remarks> public static IndexAction <T> Create <T>(IndexActionType actionType, T document) where T : class { return(new IndexAction <T>(actionType, document)); }
/// <summary> /// Initializes a new instance of the IndexActionBase class with the given action type. /// </summary> /// <param name="actionType">The type of action to perform on the document.</param> /// <param name="document">The document on which the action will be performed.</param> protected IndexActionBase(IndexActionType actionType, T document) { this.Document = document; this.ActionType = actionType; }