private EmployerAccountsDbContext GetAcccountsDbContext(IContext context)
        {
            var db = new EmployerAccountsDbContext(context.GetInstance <EmployerApprenticeshipsServiceConfiguration>().DatabaseConnectionString);

            db.Database.BeginTransaction();
            return(db);
        }
示例#2
0
 public EmployerAccountsDbBuilder(
     DbBuilderDependentRepositories dependentRepositories,
     IHashingService hashingService,
     IPublicHashingService publicHashingService,
     EmployerAccountsDbContext dbContext)
 {
     DependentRepositories = dependentRepositories;
     _hashingService       = hashingService;
     _publicHashingService = publicHashingService;
     _dbContext            = dbContext;
 }
示例#3
0
        private Account CreateAccount(EmployerAccountsDbContext db)
        {
            var hashedId = GetNextHashedIdForTests(db);
            var account  = db.Accounts.Create();

            account.CreatedDate = DateTime.Now;
            account.HashedId    = hashedId;
            account.Name        = $"Account created for unit test {hashedId}";
            db.Accounts.Add(account);

            return(account);
        }
示例#4
0
        public async Task CreateAccountStatistics()
        {
            var fixture = new Fixture();

            var accountDbContext = new EmployerAccountsDbContext(_configuration.DatabaseConnectionString);
            var lazyDb           = new Lazy <EmployerAccountsDbContext>(() => accountDbContext);
            var userRepo         = new UserRepository(_configuration, Mock.Of <ILog>(), lazyDb);
            var userToCreate     = fixture
                                   .Build <User>()
                                   .Without(user => user.Id)
                                   .Without(user => user.UserRef)
                                   .Create();
            var accountRepo = new AccountRepository(_configuration,
                                                    Mock.Of <ILog>(), lazyDb, Mock.Of <IAccountLegalEntityPublicHashingService>());

            accountDbContext.Database.BeginTransaction();

            try
            {
                await userRepo.Create(userToCreate);

                var createdUser = await userRepo.GetUserByRef(userToCreate.UserRef);

                await accountRepo.CreateAccount(new CreateAccountParams
                {
                    UserId = createdUser.Id,
                    EmployerDateOfIncorporation = DateTime.Today,
                    EmployerRef               = $"ref-{DateTime.Now.Ticks.ToString().Substring(4, 10)}",
                    Source                    = 2,
                    PublicSectorDataSource    = 1,
                    EmployerNumber            = fixture.Create <string>(),
                    EmployerName              = fixture.Create <string>(),
                    EmployerRegisteredAddress = fixture.Create <string>(),
                    AccessToken               = fixture.Create <string>(),
                    RefreshToken              = fixture.Create <string>(),
                    CompanyStatus             = fixture.Create <string>(),
                    EmployerRefName           = fixture.Create <string>(),
                    Sector                    = fixture.Create <string>(),
                    Aorn          = fixture.Create <string>(),
                    AgreementType = fixture.Create <AgreementType>()
                });

                accountDbContext.Database.CurrentTransaction.Commit();
            }
            catch (Exception e)
            {
                accountDbContext.Database.CurrentTransaction.Rollback();
                Console.WriteLine(e);
                throw;
            }
        }
示例#5
0
        private static void SetUpAccountIoC(ConfigurationExpression config)
        {
            config.AddRegistry <ConfigurationRegistry>();
            config.AddRegistry <HashingRegistry>();
            config.AddRegistry <RepositoriesRegistry>();

            var accountConfiguration = LazyAccountConfiguration.Value;
            var dbContext            = new EmployerAccountsDbContext(accountConfiguration.DatabaseConnectionString);

            config.For <DbConnection>().Use(context => new SqlConnection(accountConfiguration.DatabaseConnectionString));
            config.For <EmployerApprenticeshipsServiceConfiguration>().Use(accountConfiguration);
            config.For <EmployerAccountsDbContext>().Use(context => dbContext);
            config.For <Lazy <EmployerAccountsDbContext> >().Use(context => new Lazy <EmployerAccountsDbContext>(() => dbContext));
        }
示例#6
0
        public EmployerAccountsDbBuilder(
            IContainer container
            )
        {
            _container = container;

            _configuration = ConfigurationTestHelper.GetConfiguration <EmployerAccountsConfiguration>(ServiceName);

            _hashingService       = _container.GetInstance <IHashingService>();
            _publicHashingService = _container.GetInstance <IPublicHashingService>();

            _dbContext = new EmployerAccountsDbContext(_configuration.DatabaseConnectionString);

            _lazyAccountRepository = new  Lazy <IAccountRepository>(buildAccountRepository);
            _lazyUserRepository    = new Lazy <IUserRepository>(buildUserRepository);
        }
示例#7
0
        public async Task CreateAccountStatistics()
        {
            var fixture = new Fixture();

            var accountDbContext = new EmployerAccountsDbContext(_configuration.DatabaseConnectionString);
            var lazyDb           = new Lazy <EmployerAccountsDbContext>(() => accountDbContext);
            var userRepo         = new UserRepository(_configuration, Mock.Of <ILog>(), lazyDb);
            var userToCreate     = fixture
                                   .Build <User>()
                                   .Without(user => user.Id)
                                   .Without(user => user.UserRef)
                                   .Create();
            var accountRepo = new AccountRepository(_configuration,
                                                    Mock.Of <ILog>(), lazyDb, Mock.Of <IAccountLegalEntityPublicHashingService>());

            accountDbContext.Database.BeginTransaction();

            try
            {
                await userRepo.Create(userToCreate);

                var createdUser = await userRepo.GetUserByRef(userToCreate.UserRef);

                await accountRepo.CreateAccount(
                    createdUser.Id,
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    DateTime.Today,
                    $"ref-{DateTime.Now.Ticks.ToString().Substring(4, 10)}",
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    2,
                    1,
                    fixture.Create <string>());

                accountDbContext.Database.CurrentTransaction.Commit();
            }
            catch (Exception e)
            {
                accountDbContext.Database.CurrentTransaction.Rollback();
                Console.WriteLine(e);
                throw;
            }
        }
示例#8
0
        private string GetNextHashedIdForTests(EmployerAccountsDbContext dbContext)
        {
            var regex = new Regex("ZZ[0-9]{4}");

            var maxHashedId = dbContext.Accounts
                              .Where(ac => ac.HashedId.StartsWith("ZZ"))
                              .AsEnumerable()
                              .Where(ac => regex.IsMatch(ac.HashedId))
                              .Max(ac => ac.HashedId);

            if (string.IsNullOrWhiteSpace(maxHashedId))
            {
                return("ZZ0001");
            }
            else
            {
                var intPart = int.Parse(maxHashedId.Substring(2, 4)) + 1;
                return($"ZZ{intPart:D4}");
            }
        }