public static (bool, int[]) AddTestData <TEntity>(this NoTrackingContext context, int quantity) where TEntity : class
        {
            for (int i = 0; i < quantity; i++)
            {
                var entity     = Activator.CreateInstance <TEntity>();
                var properties = entity.GetType().GetProperties();

                foreach (var property in properties)
                {
                    if (property.Name == "Id")
                    {
                        continue;
                    }

                    if (property.PropertyType == typeof(string))
                    {
                        property.SetValue(entity, Random.GenerateString(10));
                    }
                }
                context.Set <TEntity>().Add(entity);
            }

            context.SaveChanges();

            return(true, context.Set <TEntity>().Select(x => (int)x.GetType().GetProperty("Id").GetValue(x)).ToArray());
        }
Example #2
0
        async Task <List <object> > FindResults(object[] keys)
        {
            var list = new List <object>();

            var inputKeyTypes = keys.Select(x => x.GetType()).ToList();

            var entitiesToQuery = EntityTypes
                                  .Where(entity =>
            {
                var primaryKey = entity.FindPrimaryKey();
                if (primaryKey == null)
                {
                    return(false);
                }

                var entityKeys = primaryKey.Properties.Select(x => x.ClrType);
                return(entityKeys.SequenceEqual(inputKeyTypes));
            });

            foreach (var entity in entitiesToQuery)
            {
                var result = await NoTrackingContext.FindAsync(entity.ClrType, keys);

                if (result != null)
                {
                    list.Add(result);
                }
            }

            return(list);
        }
Example #3
0
        public void Initialize()
        {
            var inMemoryDatabaseReference = Guid.NewGuid().ToString();

            var optionsNoTrackingContext = new DbContextOptionsBuilder <NoTrackingContext>().UseInMemoryDatabase(inMemoryDatabaseReference).Options;

            _noTrackingContext = new NoTrackingContext(optionsNoTrackingContext);

            var optionsTrackingContext = new DbContextOptionsBuilder <TrackingContext>().UseInMemoryDatabase(inMemoryDatabaseReference).Options;

            _trackingContext = new TrackingContext(optionsTrackingContext);

            Mapper.Initialize(x => x.AddProfile <Infrastructure.Profiles.TaskProfile>());
        }
Example #4
0
        public async ValueTask DisposeAsync()
        {
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (Context != null)
            {
                await Context.DisposeAsync();
            }

            if (NoTrackingContext != null)
            {
                await NoTrackingContext.DisposeAsync();
            }

            await Connection.DisposeAsync();
        }
Example #5
0
        public void Initialize()
        {
            var inMemoryDatabaseReference = Guid.NewGuid().ToString();

            var optionsNoTrackingContext = new DbContextOptionsBuilder <NoTrackingContext>().UseInMemoryDatabase(inMemoryDatabaseReference).Options;

            _noTrackingContext = new NoTrackingContext(optionsNoTrackingContext);

            var optionsTrackingContext = new DbContextOptionsBuilder <TrackingContext>().UseInMemoryDatabase(inMemoryDatabaseReference).Options;

            _trackingContext = new TrackingContext(optionsTrackingContext);

            Mapper.Initialize(x =>
            {
                x.AddProfile <Infrastructure.Profiles.MainAccountGroupProfile>();
                x.AddProfile <Infrastructure.Profiles.SubAccountGroupProfile>();
                x.AddProfile <Infrastructure.Profiles.AccountProfile>();
                x.AddProfile <Infrastructure.Profiles.AccountingEntryProfile>();
            });
        }
 public FindAllTransactionTemplatesRequestHandler(NoTrackingContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public FindTransactionByIdRequestHandler(NoTrackingContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #8
0
 public FindTaskListByIdRequestHandler(NoTrackingContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public GenerateTemplateRuleRequestHandler(NoTrackingContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #10
0
 public FindAllLedgersRequestHandler(NoTrackingContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public DistributeAmountRequestHandler(NoTrackingContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #12
0
 /// <summary>
 /// Returns <see cref="DbContext.Set{TEntity}()"/> from <see cref="NoTrackingContext"/>.
 /// </summary>
 public DbSet <T> Set <T>() where T : class
 {
     return(NoTrackingContext.Set <T>());
 }