コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        public static async Task GivenAnEventAsync(
            this GivenAnyContext context,
            EventEntity ev)
        {
            var dbContext = context.GetCoreDbContext();

            await dbContext.Events.AddAsync(ev);

            await dbContext.SaveChangesAsync();
        }
コード例 #4
0
        private static async Task GivenIHaveARoleInARegion(
            this GivenAnyContext context,
            string email,
            string regionId,
            string regionRoleId)
        {
            await context.GivenARegionMembershipAsync(email, regionId, regionRoleId);

            context.GivenIHaveAnEmail(email);
        }
コード例 #5
0
 public static async Task <RegionEntity> GetAGivenRegionById(this GivenAnyContext context, string id)
 {
     return(await context.GetCoreDbContext().Regions.FindAsync(id));
 }
コード例 #6
0
 public static void GivenTheCurrentUtcDateTime(
     this GivenAnyContext context,
     DateTime utcNow)
 {
     context.DateTimeAccessor.Setup(x => x.UtcNow).Returns(utcNow);
 }
コード例 #7
0
 public static Task <RegionMembershipEntity> GivenASuperAdministratorAsync(
     this GivenAnyContext context, string userId, string regionId)
 => context.GivenARegionMembershipAsync(userId, regionId, Core.Data.Constants.RegionRoles.SuperAdministrator);
コード例 #8
0
 public static void GivenIHaveAnEmail(this GivenAnyContext context, string email)
 => context.UserEmail.Setup(x => x.Value).Returns(email);
コード例 #9
0
 public static Task GivenIAmARegionSuperAdministratorAsync(this GivenAnyContext context, string email, string regionId)
 => context.GivenIHaveARoleInARegion(email, regionId, Core.Data.Constants.RegionRoles.SuperAdministrator);
コード例 #10
0
 public static void GivenIAmARootSuperAdministrator(this GivenAnyContext context)
 => context.GivenIHaveAnEmail("*****@*****.**");
コード例 #11
0
 public static TService GetRequiredService <TService>(this GivenAnyContext context)
 => context.Services.GetRequiredService <TService>();
コード例 #12
0
 public static CoreDbContext GetCoreDbContext(this GivenAnyContext context)
 => context.GetRequiredService <CoreDbContext>();