public static async Task <IDisposableEntity <OrganizationMember> > CreateOrganizationMemberAsync( this TestServiceScope scope, ApplicationUser user = null, Organization organization = null, int?organizationId = null, string[] roles = null, string role = null) { organizationId ??= (organization ?? (await scope.CreateOrganizationAsync()).Entity).OrganizationId; if (roles == null && role != null) { roles = new[] { role }; } var member = new OrganizationMember { OrganizationId = organizationId.Value, User = user, Roles = roles?.Select(r => new OrganizationMemberRole { Role = r }).ToList() }; await scope.Db.OrganizationMembers.AddAsync(member); await scope.Db.SaveChangesAsync(); return(new DisposableEntity <OrganizationMember>(member, scope.Db)); }
public static async Task <IDisposableEntity <EventCollection> > CreateEventCollectionAsync( this TestServiceScope scope, string name = TestingConstants.Placeholder, string slug = null, string description = null, bool featured = false, string featuredImageUrl = TestingConstants.Placeholder, string featuredImageCaption = TestingConstants.Placeholder, Organization organization = null, int?organizationId = null) { if (name == TestingConstants.Placeholder) { name = $"Test Collection {Guid.NewGuid()}"; } organizationId ??= (organization ?? (await scope.CreateOrganizationAsync()).Entity).OrganizationId; if (featuredImageUrl == TestingConstants.Placeholder) { featuredImageUrl = featured ? $"http://some.featured.image.url/{Guid.NewGuid()}" : null; } if (featuredImageCaption == TestingConstants.Placeholder) { featuredImageCaption = featured ? $"Some featured image caption {Guid.NewGuid()}" : null; } var collection = new EventCollection { Name = name, OrganizationId = organizationId.Value, Slug = slug, Description = description, Featured = featured, FeaturedImageUrl = featuredImageUrl, FeaturedImageCaption = featuredImageCaption }; await scope.Db.EventCollections.AddAsync(collection); await scope.Db.SaveChangesAsync(); return(new DisposableEntity <EventCollection>(collection, scope.Db)); }