AbstractMockDbPersistence<T>

Abstract Mock DB Persistence (keep data in memory) with ability to test basic projections

Description

The AbstractMockDbPersistence class allows you to keep data in memory with the ability to test basic projections.

Important points The class that contains “Id” property (with no dependencies to IIdentifiable).

Constructors

Creates a new instance of the file persistence component.

public constructor(persister?: JsonFilePersister)

  • persister: JsonFilePersister - (optional) persister component that loads and saves data from/to a flat file.

Fields

MaxPageSize

Maximum page size

protected MaxPageSize: int = 100

_objects

Objects

protected _objects: Dictionary<string, T>

Instance methods

CreateAsync

creates and save objects into the _objects variable.

public virtual Task<T> CreateAsync(string correlationId, T @object)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • @object: T - object

ClearAsync

Clears the _objects variable.

public virtual Task ClearAsync()

DeleteAsync

Removes an object from the _objects variable.

public virtual Task/ DeleteAsync(string correlationId, string id)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • id: string - id

GetAsync

Gets an object from the _objects variable.

public virtual Task<DataPage<T>> GetAsync(string correlationId, FilterParams filter, PagingParams paging)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • filter: FilterParams - filter
  • paging: PagingParams - paging parameters
  • returns: Task<DataPage<T>> - Data page

GetAsync

Gets an object based on a given projection.

public virtual Task<DataPage<object>> GetAsync(string correlationId, FilterParams filter, PagingParams paging, ProjectionParams projection)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • filter: FilterParams - filter
  • paging: PagingParams - paging parameters
  • projection: ProjectionParams - projection parameters
  • returns: Task<DataPage<object>> - data page

GetByIdAsync

Gets an object from the _objects variable based on a given id.

public virtual Task<T> GetByIdAsync(string correlationId, string id)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • id: string - id

Gets an object based on a given id and projection.

public virtual Task<object> GetByIdAsync(string correlationId, string id, ProjectionParams projection)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • id: string - id
  • projection: ProjectionParams - projection parameters

UpdateAsync

Updates an object stored in _objects.

public virtual Task<T> UpdateAsync(string correlationId, T @object)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • @object: T - object to update

ModifyAsync

Modifies a value of the field of an object.

public virtual Task<T> ModifyAsync(string correlationId, string id, AnyValueMap updateMap)

  • correlationId: string - TODO: (optional) transaction id used to trace execution through the call chain.
  • id: string - id
  • updateMap: AnyValueMap - update map