Пример #1
0
        public void CheckDatabaseSchemaAgainstEntityFrameworkExpectedSchema()
        {
            using (var container = new Container(c =>
            {
                c.AddRegistry <ConfigurationRegistry>();
            }))
            {
                var configuration = container.GetInstance <ProviderRelationshipsConfiguration>();

                using (var connection = new SqlConnection(configuration.DatabaseConnectionString))
                {
                    var optionsBuilder = new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseSqlServer(connection);

                    using (var context = new ProviderRelationshipsDbContext(optionsBuilder.Options))
                    {
                        var config = new CompareEfSqlConfig
                        {
                            TablesToIgnoreCommaDelimited = "ClientOutboxData,OutboxData"
                        };

                        config.IgnoreTheseErrors("EXTRA IN DATABASE: SFA.DAS.ProviderRelationships.Database->Column 'Users', column name. Found = Id");

                        var comparer  = new CompareEfSql(config);
                        var hasErrors = comparer.CompareEfWithDb(context);

                        hasErrors.Should().BeFalse(comparer.GetAllErrors);
                    }
                }
            }
        }
Пример #2
0
 public CreateOrUpdateUserCommandHandlerTestsFixture()
 {
     Db = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     CreateOrUpdateUserCommand = new CreateOrUpdateUserCommand(Guid.NewGuid(), "*****@*****.**", "Foo", "Bar");
     Handler = new CreateOrUpdateUserCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
     Now     = DateTime.UtcNow;
 }
 public GetProviderToAddQueryHandlerTestsFixture()
 {
     Query = new GetProviderToAddQuery(12345678);
     Db    = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     ConfigurationProvider = new MapperConfiguration(c => c.AddProfiles(typeof(ProviderMappings)));
     Handler = new GetProviderToAddQueryHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db), ConfigurationProvider);
 }
Пример #4
0
 public GetUpdatedAccountProviderLegalEntityQueryHandlerTestsFixture()
 {
     Db = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
     ConfigurationProvider = new MapperConfiguration(c => c.AddProfiles(typeof(AccountProviderLegalEntityMappings)));
     Query   = new GetUpdatedAccountProviderLegalEntityQuery(1, 3, 4);
     Handler = new GetUpdatedAccountProviderLegalEntityQueryHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db), ConfigurationProvider);
 }
Пример #5
0
        public GetAccountProviderLegalEntitiesWithPermissionQueryHandlerTestsFixture()
        {
            Query = new GetAccountProviderLegalEntitiesWithPermissionQuery(88888888, Operation.CreateCohort);

            Db = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
            ConfigurationProvider = new MapperConfiguration(c => c.AddProfile <AccountProviderLegalEntityMappings>());
            Handler = new GetAccountProviderLegalEntitiesWithPermissionQueryHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db), ConfigurationProvider);
        }
Пример #6
0
 public GetAccountProvidersQueryHandlerTestsFixture()
 {
     Query = new GetAccountProvidersQuery(1);
     Db    = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     ConfigurationProvider = new MapperConfiguration(c => c.AddProfiles(typeof(AccountProviderMappings)));
     AuthorizationService  = new Mock <IAuthorizationService>();
     Handler = new GetAccountProvidersQueryHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db), ConfigurationProvider, AuthorizationService.Object);
 }
Пример #7
0
 public GetAccountProviderLegalEntityQueryHandlerFixture()
 {
     Query = new GetAccountProviderLegalEntityQuery(1, 2, 3);
     Db    = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
     ConfigurationProvider = new MapperConfiguration(c => c.AddProfiles(typeof(AccountProviderLegalEntityMappings)));
     MockRecruitService    = new Mock <IDasRecruitService>();
     SetDasRecruitBlockedProvider();
     Handler = new GetAccountProviderLegalEntityQueryHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db), MockRecruitService.Object, ConfigurationProvider);
 }
 public UpdatedPermissionsEventAuditCommandHandlerTestsFixture()
 {
     Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     Command = new UpdatedPermissionsEventAuditCommand(112, 114, 116, 118, 256894321, Guid.NewGuid(),
                                                       new HashSet <Operation> {
         Operation.CreateCohort
     }, DateTime.Parse("2018-11-11"));
     Handler = new UpdatedPermissionsEventAuditCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
 }
Пример #9
0
        private void CreateDb()
        {
            var optionsBuilder =
                new DbContextOptionsBuilder <ProviderRelationshipsDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .ConfigureWarnings(warnings =>
                                   warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)
                                   );

            Db = new ProviderRelationshipsDbContext(optionsBuilder.Options);
        }
Пример #10
0
        public AddAccountLegalEntityCommandHandlerTestsFixture()
        {
            Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
            Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, 1);

            Db.Accounts.Add(Account);
            Db.SaveChanges();

            Command = new AddAccountLegalEntityCommand(Account.Id, 2, "ALE123", "Foo", DateTime.UtcNow);
            Handler = new AddAccountLegalEntityCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
        }
Пример #11
0
        public UpdateAccountNameCommandHandlerTestsFixture()
        {
            OriginalAccountName = "Foo";
            Now     = DateTime.UtcNow;
            Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, 1).Set(a => a.Name, OriginalAccountName);
            Command = new UpdateAccountNameCommand(Account.Id, "Bar", Now.AddHours(-1));
            Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);

            Db.Accounts.Add(Account);
            Db.SaveChanges();

            Handler           = new UpdateAccountNameCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
            UnitOfWorkContext = new UnitOfWorkContext();
        }
Пример #12
0
        public SendDeletedPermissionsNotificationCommandHandlerTestsFixture()
        {
            Ukprn = 228876542;
            AccountLegalEntityId = 116;
            OrganisationName     = "TestOrg";

            Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            Command = new SendDeletedPermissionsNotificationCommand(Ukprn, AccountLegalEntityId);
            Client  = new Mock <IPasAccountApiClient>();

            Db.AccountLegalEntities.Add(EntityActivator.CreateInstance <AccountLegalEntity>().Set(a => a.Id, AccountLegalEntityId).Set(a => a.Name, OrganisationName));
            Db.SaveChanges();

            Handler = new SendDeletedPermissionsNotificationCommandHandler(Client.Object, new Lazy <ProviderRelationshipsDbContext>(() => Db));
        }
        public ReceiveProviderRelationshipsHealthCheckEventCommandHandlerTestsFixture()
        {
            HealthChecks = new List <HealthCheck>
            {
                EntityActivator.CreateInstance <HealthCheck>().Set(h => h.Id, 1),
                EntityActivator.CreateInstance <HealthCheck>().Set(h => h.Id, 2)
            };

            Command = new ReceiveProviderRelationshipsHealthCheckEventCommand(HealthChecks[1].Id);
            Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);

            Db.HealthChecks.AddRange(HealthChecks);
            Db.SaveChanges();

            Handler = new ReceiveProviderRelationshipsHealthCheckEventCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
        }
Пример #14
0
        public GetHealthCheckQueryHandlerTestsFixture()
        {
            GetHealthCheckQuery = new GetHealthCheckQuery();
            Db = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
            ConfigurationProvider = new MapperConfiguration(c => c.AddProfiles(typeof(HealthCheckMappings)));

            HealthChecks = new List <HealthCheck>
            {
                EntityActivator.CreateInstance <HealthCheck>().Set(h => h.Id, 1),
                EntityActivator.CreateInstance <HealthCheck>().Set(h => h.Id, 2)
            };

            Db.HealthChecks.AddRange(HealthChecks);
            Db.SaveChanges();

            Handler = new GetHealthCheckQueryHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db), ConfigurationProvider);
        }
Пример #15
0
        public RemoveAccountLegalEntityCommandHandlerTestsFixture()
        {
            Now                = DateTime.UtcNow;
            Account            = EntityActivator.CreateInstance <Account>().Set(a => a.Id, 1);
            AccountLegalEntity = EntityActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, 2).Set(ale => ale.AccountId, Account.Id);
            AccountProvider    = EntityActivator.CreateInstance <AccountProvider>().Set(ap => ap.Id, 3).Set(ap => ap.AccountId, Account.Id).Set(ap => ap.ProviderUkprn, 12345678);
            Command            = new RemoveAccountLegalEntityCommand(Account.Id, AccountLegalEntity.Id, Now.AddHours(-1));
            Db = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);

            Db.Accounts.Add(Account);
            Db.AccountLegalEntities.Add(AccountLegalEntity);
            Db.AccountProviders.Add(AccountProvider);
            Db.SaveChanges();

            Handler           = new RemoveAccountLegalEntityCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
            UnitOfWorkContext = new UnitOfWorkContext();
        }
Пример #16
0
        public AddAccountProviderCommandHandlerTestsFixture()
        {
            Db       = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
            Account  = EntityActivator.CreateInstance <Account>().Set(a => a.Id, 1);
            User     = EntityActivator.CreateInstance <User>().Set(u => u.Ref, Guid.NewGuid());
            Provider = EntityActivator.CreateInstance <Provider>().Set(p => p.Ukprn, 12345678);

            Db.Accounts.Add(Account);
            Db.Users.Add(User);
            Db.Providers.Add(Provider);
            Db.SaveChanges();

            Command           = new AddAccountProviderCommand(Account.Id, Provider.Ukprn, User.Ref);
            Now               = DateTime.UtcNow;
            UnitOfWorkContext = new UnitOfWorkContext();
            Handler           = new AddAccountProviderCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
        }
        public RunHealthCheckCommandHandlerTestsFixture()
        {
            Db   = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
            User = EntityActivator.CreateInstance <User>().Set(u => u.Ref, Guid.NewGuid());
            RunHealthCheckCommand          = new RunHealthCheckCommand(User.Ref);
            UnitOfWorkContext              = new UnitOfWorkContext();
            ProviderApiClient              = new Mock <IRoatpService>();
            ProviderRelationshipsApiClient = new Mock <IProviderRelationshipsApiClient>();
            CancellationToken              = new CancellationToken();

            Db.Users.Add(User);
            Db.SaveChanges();

            ProviderApiClient.Setup(c => c.Ping()).ReturnsAsync(true);
            ProviderRelationshipsApiClient.Setup(c => c.Ping(CancellationToken)).Returns(Task.CompletedTask);

            Handler = new RunHealthCheckCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db), ProviderApiClient.Object, ProviderRelationshipsApiClient.Object);
        }
Пример #18
0
        public UpdatePermissionsCommandHandlerTestsFixture()
        {
            Now = DateTime.UtcNow;;
            UnitOfWorkContext = new UnitOfWorkContext();
            Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            Command = new UpdatePermissionsCommand(1, 2, 3, Guid.NewGuid(), new HashSet <Operation> {
                Operation.CreateCohort
            });
            Account            = EntityActivator.CreateInstance <Account>().Set(a => a.Id, Command.AccountId);
            AccountProvider    = EntityActivator.CreateInstance <AccountProvider>().Set(ap => ap.Id, Command.AccountProviderId).Set(ap => ap.AccountId, Account.Id);
            AccountLegalEntity = EntityActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, Command.AccountLegalEntityId).Set(ale => ale.AccountId, Account.Id);
            User = EntityActivator.CreateInstance <User>().Set(u => u.Ref, Command.UserRef);

            Db.Accounts.Add(Account);
            Db.AccountProviders.Add(AccountProvider);
            Db.AccountLegalEntities.Add(AccountLegalEntity);
            Db.Users.Add(User);
            Db.SaveChanges();

            Handler = new UpdatePermissionsCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
        }
Пример #19
0
 public FindProviderToAddQueryHandlerTestsFixture()
 {
     Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     Handler = new FindProviderToAddQueryHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
     Query   = new FindProviderToAddQuery(1, 12345678);
 }
 public CreateAccountCommandHandlerTestFixture()
 {
     Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     Command = new CreateAccountCommand(1, "AAA111", "AAA222", "Foo", DateTime.UtcNow);
     Handler = new CreateAccountCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
 }
Пример #21
0
 public AddedAccountProviderEventAuditCommandHandlerTestsFixture()
 {
     Db      = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     Command = new AddedAccountProviderEventAuditCommand(112, 114, 118277339, Guid.NewGuid(), DateTime.Parse("2018-11-11"));
     Handler = new AddedAccountProviderEventAuditCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
 }