Ejemplo n.º 1
0
        /// <summary>
        /// Adds an entity to the given query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="entity">The entity.</param>
        /// <typeparam name="TEntity">The entity type.</typeparam>
        public static void Add <TEntity>(this InMemoryQuery query,
                                         TEntity entity)
            where TEntity : class, IEntity
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            query.Add(entity, entity.IdentityValue);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a collection of entities to the given query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="entities">The entities.</param>
        /// <typeparam name="TEntity">The entity type.</typeparam>
        public static void Add <TEntity>(this InMemoryQuery query,
                                         IEnumerable <TEntity> entities)
            where TEntity : class, IEntity
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            query.Add(entities, item => item.IdentityValue);
        }
Ejemplo n.º 3
0
        public void Add_adds_an_entity_with_its_identity([AlwaysMock] InMemoryQuery query,
                                                         Person entity)
        {
            // Arrange
            var identityValue = entity.Identity;

            // Act
            query.Add(entity);

            // Assert
            Mock.Get(query).Verify(x => x.Add(entity, identityValue), Times.Once());
        }
Ejemplo n.º 4
0
        public void Delete_deletes_an_entity_by_its_identity([AlwaysMock] InMemoryQuery query,
                                                             IIdentity <Person> identity,
                                                             object identityValue)
        {
            // Arrange
            Mock.Get(identity).SetupGet(x => x.Value).Returns(identityValue);

            // Act
            query.DeleteEntity(identity);

            // Assert
            Mock.Get(query).Verify(x => x.Delete <Person>(identityValue), Times.Once());
        }
Ejemplo n.º 5
0
        public void Add_adds_collection_of_entities_with_their_identities([AlwaysMock] InMemoryQuery query,
                                                                          Person entityOne,
                                                                          Person entityTwo)
        {
            // Arrange
            IEnumerable <IEntity> collection = new[] { entityOne, entityTwo };

            // Act
            query.Add(collection);

            // Assert
            Mock.Get(query).Verify(x => x.Add(collection, It.IsAny <Func <IEntity, object> >()), Times.Once());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deletes an entity from the given query using its identity.
        /// </summary>
        /// <param name="query">Query.</param>
        /// <param name="identity">Identity.</param>
        /// <typeparam name="TEntity">The entity type.</typeparam>
        public static void DeleteEntity <TEntity>(this InMemoryQuery query,
                                                  IIdentity <TEntity> identity)
            where TEntity : class, IEntity
        {
            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            query.Delete <TEntity>(identity.Value);
        }
Ejemplo n.º 7
0
 public Task <IReadOnlyCollection <TReadModel> > ExecuteQueryAsync(
     InMemoryQuery <TReadModel> query,
     CancellationToken cancellationToken)
 {
     return(_readModelStore.FindAsync(query.Query, cancellationToken));
 }