public static async Task <RegionMembershipEntity> GivenARegionMembershipAsync( this GivenAnyContext context, string email, string regionId, string regionRoleId) { var coreDbContext = context.GetCoreDbContext(); var region = await coreDbContext.GetRegionByIdAsync(regionId); if (region == null) { throw new Exception("Region does not exist"); } var regionRole = await coreDbContext.RegionRoles.FindAsync(regionRoleId); if (regionRole == null) { throw new Exception("Region role does not exist"); } var result = await coreDbContext.RegionMemberships.AddAsync(new RegionMembershipEntity() { UserEmail = email, RegionId = region.Id, RegionRoleId = regionRoleId }); await coreDbContext.SaveChangesAsync(); return(result.Entity); }
public static async Task GivenARegionHierarchyAsync(this GivenAnyContext context) { var coreDbContext = context.GetCoreDbContext(); foreach (var region in _regions) { var id = string.Empty; if (region.ParentId != Constants.RootRegionId) { id += region.ParentId + "/"; } id += region.Name.ToLower().Replace(' ', '-'); await coreDbContext.Regions.AddAsync(new RegionEntity() { Id = id, ParentId = region.ParentId, DataJson = JsonConvert.SerializeObject(new { region.Name }), DataJsonVersion = 1 }); } await coreDbContext.SaveChangesAsync(); }
public static async Task GivenAnEventAsync( this GivenAnyContext context, EventEntity ev) { var dbContext = context.GetCoreDbContext(); await dbContext.Events.AddAsync(ev); await dbContext.SaveChangesAsync(); }
private static async Task GivenIHaveARoleInARegion( this GivenAnyContext context, string email, string regionId, string regionRoleId) { await context.GivenARegionMembershipAsync(email, regionId, regionRoleId); context.GivenIHaveAnEmail(email); }
public static async Task <RegionEntity> GetAGivenRegionById(this GivenAnyContext context, string id) { return(await context.GetCoreDbContext().Regions.FindAsync(id)); }
public static void GivenTheCurrentUtcDateTime( this GivenAnyContext context, DateTime utcNow) { context.DateTimeAccessor.Setup(x => x.UtcNow).Returns(utcNow); }
public static Task <RegionMembershipEntity> GivenASuperAdministratorAsync( this GivenAnyContext context, string userId, string regionId) => context.GivenARegionMembershipAsync(userId, regionId, Core.Data.Constants.RegionRoles.SuperAdministrator);
public static void GivenIHaveAnEmail(this GivenAnyContext context, string email) => context.UserEmail.Setup(x => x.Value).Returns(email);
public static Task GivenIAmARegionSuperAdministratorAsync(this GivenAnyContext context, string email, string regionId) => context.GivenIHaveARoleInARegion(email, regionId, Core.Data.Constants.RegionRoles.SuperAdministrator);
public static void GivenIAmARootSuperAdministrator(this GivenAnyContext context) => context.GivenIHaveAnEmail("*****@*****.**");
public static TService GetRequiredService <TService>(this GivenAnyContext context) => context.Services.GetRequiredService <TService>();
public static CoreDbContext GetCoreDbContext(this GivenAnyContext context) => context.GetRequiredService <CoreDbContext>();