Exemplo n.º 1
0
        private async Task CreateOrUpdateAssociationAsync(AssociationEntity[] changedEntities)
        {
            using (var repository = _repositoryFactory())
            {
                foreach (var changedEntity in changedEntities)
                {
                    AssociationEntity existEntity = null;

                    if (!changedEntity.IsTransient())
                    {
                        existEntity = repository.Associations.FirstOrDefault(x => x.Id == changedEntity.Id);
                    }
                    else
                    {
                        existEntity = repository.Associations.FirstOrDefault(x => changedEntity.ItemId == x.ItemId && changedEntity.AssociatedItemId == x.AssociatedItemId && changedEntity.AssociationType == x.AssociationType && changedEntity.AssociatedCategoryId == x.AssociatedCategoryId);
                    }

                    if (existEntity == null)
                    {
                        repository.Add(changedEntity);
                    }
                    else
                    {
                        changedEntity.Patch(existEntity);
                    }
                }

                await repository.UnitOfWork.CommitAsync();

                //Reset cached associations

                ClearCache(changedEntities.Select(x => x.ItemId).ToArray());
            }
        }
Exemplo n.º 2
0
        public async Task SearchDynamicAssociationsAsync_IsActiveConditionNotValid_NoResults(AssociationEntity entity)
        {
            // Arrange
            var entities = new[]
            {
                entity
            };
            var searchServiceMock = CreateDynamicAssociationSearchServiceMock(entities);

            // Act
            var searchResult = await searchServiceMock.SearchAssociationsAsync(new AssociationSearchCriteria()
            {
                IsActive = true
            });

            // Assert
            Assert.Equal(0, searchResult.TotalCount);
        }