Example #1
0
        public GetFeatureFlagByResourceIdRequestHandlerTests()
        {
            var dbOptions = new DbContextOptionsBuilder <SemaphoreContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString())
                            .Options;

            _context = new SemaphoreContext(dbOptions);

            var feature = new Feature
            {
                ResourceId = _resourceId,
                Name       = Name
            };

            for (var i = 0; i < SignalsCount; i++)
            {
                feature.Signals.Add(new Signal
                {
                    Value = (i % 2 == 0).ToString(),
                    Tags  = i.ToString()
                });
            }

            _context.Features.Add(feature);
            _context.SaveChanges();

            _sut = new GetFeatureFlagByResourceIdRequestHandler(_context);
        }
Example #2
0
        public PatchSignalRequestHandlerTests()
        {
            var dbOptions = new DbContextOptionsBuilder <SemaphoreContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString())
                            .Options;

            _context = new SemaphoreContext(dbOptions);
            _sut     = new PatchSignalRequestHandler(_context, _mediatorMock.Object);
        }
Example #3
0
        public CreateFeatureFlagRequestHandlerTests()
        {
            var dbOptions = new DbContextOptionsBuilder <SemaphoreContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString())
                            .Options;

            _context = new SemaphoreContext(dbOptions);

            _sut = new CreateFeatureFlagRequestHandler(_context);
        }
Example #4
0
        public GetSettingRequestHandlerTests()
        {
            var dbOptions = new DbContextOptionsBuilder <SemaphoreContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString())
                            .Options;

            _context = new SemaphoreContext(dbOptions);
            _context.Add(new Setting
            {
                Name  = Name,
                Value = Value
            });
            _context.SaveChanges();

            _sut = new GetSettingRequestHandler(_context);
        }
Example #5
0
        public GetSignalByNameRequestHandlerTests()
        {
            var dbOptions = new DbContextOptionsBuilder <SemaphoreContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString())
                            .Options;

            _context = new SemaphoreContext(dbOptions);

            _context.Signals.Add(new Signal
            {
                Id              = 1,
                ResourceId      = _resourceId,
                Name            = Name,
                Value           = Value,
                ValueType       = Value.GetSignalValueType(),
                IsBaseType      = Value.IsBaseType(),
                DateCreated     = DateTime.Now,
                DateLastUpdated = DateTime.Now
            });
            _context.SaveChanges();

            _sut = new GetSignalByNameRequestHandler(_context, _mediatorMock.Object);
        }
Example #6
0
        private static void Migrate(string connectionString)
        {
            var currentAssemblyName = typeof(ServiceCollectionExtensions).Assembly.GetName().Name;

            try
            {
                var migrationOptions = new DbContextOptionsBuilder <SemaphoreContext>().UseNpgsql(
                    connectionString,
                    db => { db.MigrationsAssembly(currentAssemblyName); })
                                       .Options;

                var migrationContext  = new SemaphoreContext(migrationOptions);
                var pendingMigrations = migrationContext.Database.GetPendingMigrations();
                if (pendingMigrations != null && pendingMigrations.Any())
                {
                    migrationContext.Database.Migrate();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("An error occurred migrating the database.", ex);
            }
        }
Example #7
0
        public GetFeatureFlagByNameAndTagRequestHandlerTests()
        {
            var dbOptions = new DbContextOptionsBuilder <SemaphoreContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString())
                            .Options;

            _context = new SemaphoreContext(dbOptions);
            _context.Features.Add(new Feature
            {
                ResourceId = _resourceId,
                Name       = Name,
                Signals    = new List <Signal>
                {
                    new Signal
                    {
                        Tags  = $"Tag1,Tag2,Tag3,{Tag}",
                        Value = Value.ToString()
                    }
                }
            });
            _context.SaveChanges();

            _sut = new GetFeatureFlagByNameAndTagRequestHandler(_context);
        }
Example #8
0
 public GetSignalByNameAndTagRequestHandler(SemaphoreContext context, IMediator mediator)
 {
     _context  = context;
     _mediator = mediator;
 }
Example #9
0
 public GetSettingRequestHandler(SemaphoreContext context)
 {
     _context = context;
 }
 public CreateSignalRequestHandler(SemaphoreContext context, IMediator mediator)
 {
     _context  = context;
     _mediator = mediator;
 }
 public PatchSignalRequestHandler(SemaphoreContext semaphoreContext, IMediator mediator)
 {
     _semaphoreContext = semaphoreContext;
     _mediator         = mediator;
 }
Example #12
0
 public GenerateKeysRequestHandler(SemaphoreContext context)
 {
     _context = context;
 }
 public CreateFeatureFlagRequestHandler(SemaphoreContext context)
 {
     _context = context;
 }
Example #14
0
 public GetFeatureFlagByResourceIdRequestHandler(SemaphoreContext context)
 {
     _context = context;
 }
Example #15
0
 public GetFeatureFlagByNameAndTagRequestHandler(SemaphoreContext context)
 {
     _context = context;
 }
Example #16
0
 public RollKeysRequestHandler(SemaphoreContext context, IMediator mediator)
 {
     _context  = context;
     _mediator = mediator;
 }