public GetAccountProviderLegalEntitiesWithPermissionQueryHandlerTestsFixture SetAccountProviderLegalEntities() { Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, 4660117L); AccountProvider = EntityActivator.CreateInstance <AccountProvider>() .Set(ap => ap.Id, 49L) .Set(ap => ap.AccountId, Account.Id) .Set(ap => ap.ProviderUkprn, Query.Ukprn); AccountLegalEntity = EntityActivator.CreateInstance <AccountLegalEntity>() .Set(ale => ale.Id, 413L) .Set(ale => ale.Name, "Legal Entity Name") .Set(ale => ale.AccountId, Account.Id); AccountProviderLegalEntity = EntityActivator.CreateInstance <AccountProviderLegalEntity>() .Set(aple => aple.Id, 5) .Set(aple => aple.AccountProviderId, AccountProvider.Id) .Set(aple => aple.AccountLegalEntityId, AccountLegalEntity.Id); Permission = EntityActivator.CreateInstance <Permission>() .Set(p => p.Id, 3) .Set(p => p.AccountProviderLegalEntityId, AccountProviderLegalEntity.Id) .Set(p => p.Operation, Query.Operation); //todo: if these don't clone, we should Db.Accounts.Add(Account); Db.AccountProviders.Add(AccountProvider); Db.AccountLegalEntities.Add(AccountLegalEntity); Db.AccountProviderLegalEntities.Add(AccountProviderLegalEntity); Db.Permissions.Add(Permission); Db.SaveChanges(); return(this); }
public GetAccountProvidersQueryHandlerTestsFixture SetAccountProviders() { Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, Query.AccountId); Provider = EntityActivator.CreateInstance <Provider>().Set(p => p.Ukprn, 12345678).Set(p => p.Name, "Foo"); AccountProvider = EntityActivator.CreateInstance <AccountProvider>().Set(ap => ap.Id, 2).Set(ap => ap.AccountId, Account.Id).Set(ap => ap.ProviderUkprn, Provider.Ukprn); AccountLegalEntities = new List <AccountLegalEntity> { EntityActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, 3).Set(ale => ale.AccountId, Account.Id), EntityActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, 4).Set(ale => ale.AccountId, Account.Id), EntityActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, 5).Set(ale => ale.AccountId, 2) }; AccountProviderLegalEntity = EntityActivator.CreateInstance <AccountProviderLegalEntity>() .Set(aple => aple.Id, 8).Set(aple => aple.AccountLegalEntityId, 3) .Set(aple => aple.AccountProviderId, 2); Permission = EntityActivator.CreateInstance <Permission>().Set(p => p.Id, 4) .Set(p => p.Operation, Operation.CreateCohort).Set(p => p.AccountProviderLegalEntityId, 8); Db.Accounts.Add(Account); Db.Providers.Add(Provider); Db.AccountProviders.Add(AccountProvider); Db.AccountLegalEntities.AddRange(AccountLegalEntities); Db.AccountProviderLegalEntities.Add(AccountProviderLegalEntity); Db.Permissions.Add(Permission); Db.SaveChanges(); return(this); }
public HealthCheckTestsFixture() { User = EntityActivator.CreateInstance <User>().Set(u => u.Ref, Guid.NewGuid()); UnitOfWorkContext = new UnitOfWorkContext(); ApprenticeshipInfoServiceApiRequest = () => Task.CompletedTask; ProviderRelationshipsApiRequest = () => Task.CompletedTask; }
public AddAccountProviderCommandHandlerTestsFixture SetAccountProvider() { Db.AccountProviders.Add(EntityActivator.CreateInstance <AccountProvider>().Set(ap => ap.AccountId, Account.Id).Set(ap => ap.ProviderUkprn, Provider.Ukprn)); Db.SaveChanges(); return(this); }
public void CreateInstance_WithoutEvents_ExceptionThrown() { var events = Array.Empty <IEntityEvent>(); var eventStoreEntity = new { }; Action act = () => EntityActivator.CreateInstance <Person>(events, eventStoreEntity); act.Should().Throw <ArgumentException>(); }
public FindProviderToAddQueryHandlerTestsFixture SetProvider() { Provider = EntityActivator.CreateInstance <Provider>().Set(p => p.Ukprn, Query.Ukprn); Db.Providers.Add(Provider); Db.SaveChanges(); return(this); }
public FindProviderToAddQueryHandlerTestsFixture SetAccountProvider() { Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, Query.AccountId); AccountProvider = EntityActivator.CreateInstance <AccountProvider>().Set(ap => ap.Id, 1).Set(ap => ap.AccountId, Account.Id).Set(ap => ap.ProviderUkprn, Provider.Ukprn); Db.AccountProviders.Add(AccountProvider); Db.SaveChanges(); return(this); }
public void CreateInstance_WithSomeEvents_EntityCreated() { var events = new IEntityEvent[] { new Person.NameChangedEvent(), new Person.AgeChangedEvent() }; var eventStoreEntity = new { }; var entity = EntityActivator.CreateInstance <Person>(events, eventStoreEntity); entity.Should().NotBeNull(); entity.Should().BeOfType <Person>(); }
public void CreateInstance_WithoutEvents_EntityCreated() { var events = new IEntityEvent[0]; var eventStoreEntity = new { }; var entity = EntityActivator.CreateInstance <Person>(events, eventStoreEntity); entity.Should().NotBeNull(); entity.Should().BeOfType <Person>(); }
public GetAccountProviderLegalEntityQueryHandlerFixture SetAccountLegalEntities() { Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, Query.AccountId); AccountLegalEntity = EntityActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, Query.AccountLegalEntityId).Set(ale => ale.Name, "Bar").Set(ale => ale.AccountId, Account.Id); Db.Accounts.Add(Account); Db.AccountLegalEntities.Add(AccountLegalEntity); Db.SaveChanges(); return(this); }
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)); }
public void CreateInstance_WithEventStoreEntity_PropertiesValuesCopiedToNewEntity() { var events = new IEntityEvent[0]; var eventStoreEntity = new { PersonId = 1234, Ssn = "123-123 CA", EntityName = "Silverback" }; var entity = EntityActivator.CreateInstance <Person>(events, eventStoreEntity); entity.Should().NotBeNull(); entity.Id.Should().Be(1234); entity.Ssn.Should().Be("123-123 CA"); entity.Name.Should().Be("Silverback"); }
public UpdatePermissionsCommandHandlerTestsFixture SetAccountProviderLegalEntity() { AccountProviderLegalEntity = EntityActivator.CreateInstance <AccountProviderLegalEntity>() .Set(aple => aple.Id, 4) .Set(aple => aple.AccountProviderId, AccountProvider.Id) .Set(aple => aple.AccountLegalEntityId, AccountLegalEntity.Id); AccountProvider.Add(ap => ap.AccountProviderLegalEntities, AccountProviderLegalEntity); Db.SaveChanges(); return(this); }
public GetAddedAccountProviderQueryHandlerTestsFixture SetAccountProvider() { Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, Query.AccountId); Provider = EntityActivator.CreateInstance <Provider>().Set(p => p.Ukprn, 12345678); AccountProvider = EntityActivator.CreateInstance <AccountProvider>().Set(ap => ap.Id, Query.AccountProviderId).Set(ap => ap.AccountId, Account.Id).Set(ap => ap.ProviderUkprn, Provider.Ukprn); Db.Accounts.Add(Account); Db.Providers.Add(Provider); Db.AccountProviders.Add(AccountProvider); Db.SaveChanges(); return(this); }
public RemoveAccountLegalEntityCommandHandlerTestsFixture SetAccountProviderLegalEntities() { AccountProviderLegalEntities = new List <AccountProviderLegalEntity> { EntityActivator.CreateInstance <AccountProviderLegalEntity>().Set(aple => aple.Id, 4).Set(aple => aple.AccountProvider, AccountProvider), EntityActivator.CreateInstance <AccountProviderLegalEntity>().Set(aple => aple.Id, 5).Set(aple => aple.AccountProvider, AccountProvider), }; AccountLegalEntity.AddRange(ale => ale.AccountProviderLegalEntities, AccountProviderLegalEntities); Db.SaveChanges(); return(this); }
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(); }
public CreateOrUpdateUserCommandHandlerTestsFixture SetUser() { User = EntityActivator.CreateInstance <User>() .Set(u => u.Ref, CreateOrUpdateUserCommand.Ref) .Set(u => u.Email, CreateOrUpdateUserCommand.Email) .Set(u => u.FirstName, CreateOrUpdateUserCommand.FirstName) .Set(u => u.LastName, CreateOrUpdateUserCommand.LastName) .Set(u => u.Created, Now); Db.Users.Add(User); Db.SaveChanges(); return(this); }
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)); }
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); }
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)); }
/// <summary> /// Rebuilds the domain entity applying the stored events. /// </summary> /// <param name="eventStoreEntity"> /// The event store entity referencing the events to be applied. /// </param> /// <param name="snapshot"> /// The optional datetime of the snapshot to build. Specifying it will cause only the events up to this /// datetime to be applied. /// </param> /// <returns> /// The domain entity rebuilt from the stored events. /// </returns> protected virtual TDomainEntity GetDomainEntity( TEventStoreEntity eventStoreEntity, DateTime?snapshot = null) { Check.NotNull(eventStoreEntity, nameof(eventStoreEntity)); var events = snapshot != null ? eventStoreEntity.Events.Where(e => e.Timestamp <= snapshot) : eventStoreEntity.Events; return(EntityActivator.CreateInstance <TDomainEntity>( events .OrderBy(e => e.Timestamp).ThenBy(e => e.Sequence) .Select(MapEvent) .ToList(), eventStoreEntity)); }
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(); }
public void CreateInstance_WithSomeEvents_EventsApplied() { var events = new IEntityEvent[] { new Person.NameChangedEvent { NewName = "Silverback" }, new Person.AgeChangedEvent { NewAge = 13 } }; var eventStoreEntity = new { }; var entity = EntityActivator.CreateInstance <Person>(events, eventStoreEntity); entity.Name.Should().Be("Silverback"); entity.Age.Should().Be(13); }
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); }
public GetUpdatedAccountProviderLegalEntityQueryHandlerTestsFixture SetAccountProviderLegalEntity() { Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, Query.AccountId); Provider = EntityActivator.CreateInstance <Provider>() .Set(p => p.Ukprn, 12345678) .Set(p => p.Name, "Provider"); AccountProvider = EntityActivator.CreateInstance <AccountProvider>() .Set(ap => ap.Id, Query.AccountProviderId) .Set(ap => ap.AccountId, Account.Id) .Set(ap => ap.Provider, Provider); AccountLegalEntity = EntityActivator.CreateInstance <AccountLegalEntity>() .Set(ale => ale.Id, Query.AccountLegalEntityId) .Set(ale => ale.Name, "Account legal entity A") .Set(ale => ale.AccountId, Account.Id); AccountLegalEntities = new List <AccountLegalEntity> { AccountLegalEntity, EntityActivator.CreateInstance <AccountLegalEntity>() .Set(ale => ale.Id, 5) .Set(ale => ale.Name, "Account legal entity B") .Set(ale => ale.AccountId, Account.Id), EntityActivator.CreateInstance <AccountLegalEntity>() .Set(ale => ale.Id, 6) .Set(ale => ale.Name, "Account legal entity C") .Set(ale => ale.AccountId, 2) }; AccountProviderLegalEntity = EntityActivator.CreateInstance <AccountProviderLegalEntity>() .Set(aple => aple.Id, 7) .Set(aple => aple.AccountProvider, AccountProvider) .Set(aple => aple.AccountLegalEntity, AccountLegalEntity); Db.AccountLegalEntities.AddRange(AccountLegalEntities); Db.AccountProviderLegalEntities.Add(AccountProviderLegalEntity); Db.SaveChanges(); return(this); }
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)); }
private void CreateDefaultEntities() { Account = new Account( id: 1, hashedId: "HashedId", publicHashedId: "PublicHashedId", name: "Account", created: DateTime.UtcNow); Db.Add(Account); AccountLegalEntity = new AccountLegalEntity( account: Account, id: 12345, publicHashedId: "ALE1", name: "Account legal entity 1", created: DateTime.UtcNow); Db.Add(AccountLegalEntity); Provider = EntityActivator .CreateInstance <Provider>() .Set(x => x.Ukprn, 299792458); Db.Add(Provider); User = new User(Guid.NewGuid(), "*****@*****.**", "Bill", "Gates"); Db.Add(User); AccountProvider = new AccountProvider(Account, Provider, User, null); AccountProvider.Set(x => x.Id, 23); Db.Add(AccountProvider); AccountProviderLegalEntity = new AccountProviderLegalEntity( accountProvider: AccountProvider, accountLegalEntity: AccountLegalEntity, user: User, grantedOperations: new HashSet <Operation>(new[] { Operation.CreateCohort, Operation.Recruitment })); AccountProviderLegalEntity.Set(x => x.Id, 34); Db.Add(AccountProviderLegalEntity); Db.SaveChanges(); }
public HealthCheckTestsFixture SetHealthCheck() { HealthCheck = EntityActivator.CreateInstance <HealthCheck>().Set(h => h.Id, 1); return(this); }