/// <summary> /// creates an article comment based on the given Create command. /// Creates a default user if parameter userName is empty. /// </summary> /// <param name="fixture"></param> /// <param name="command"></param> /// <param name="userName"></param> /// <returns></returns> public static async Task <Domain.Comment> CreateComment(SliceFixture fixture, Create.Command command, string userName) { if (string.IsNullOrWhiteSpace(userName)) { var user = await UserHelpers.CreateDefaultUser(fixture); userName = user.Username; } var dbContext = fixture.GetDbContext(); var currentAccessor = new StubCurrentUserAccessor(userName); var commentCreateHandler = new Create.Handler(dbContext, currentAccessor); var created = await commentCreateHandler.Handle(command, new System.Threading.CancellationToken()); var dbArticleWithComments = await fixture.ExecuteDbContextAsync( db => db.Articles .Include(a => a.Comments).Include(a => a.Author) .Where(a => a.Slug == command.Slug) .SingleOrDefaultAsync() ); var dbComment = dbArticleWithComments.Comments .Where(c => c.ArticleId == dbArticleWithComments.ArticleId && c.Author == dbArticleWithComments.Author) .FirstOrDefault(); return(dbComment); }
public static async Task <ArticleCategoriesEnvelope> ListCategories(SliceFixture fixture, Conduit.Features.ArticleCategories.List.Query command) { // first create the default user var user = await UserHelpers.CreateDefaultUser(fixture); var dbContext = fixture.GetDbContext(); var currentAccessor = new StubCurrentUserAccessor(user.Username); var createCategoryCommand = new Create.Command() { articleCategory = new ArticleCategory() { CategoryId = 1, ArticleId = 1 } }; var categoryCreateHandler = new Create.Handler(dbContext, currentAccessor); var createdCategory = await categoryCreateHandler.Handle(createCategoryCommand, new System.Threading.CancellationToken()); var categoryQueryHandler = new List.QueryHandler(dbContext, currentAccessor); var queriedCategories = await categoryQueryHandler.Handle(command, new System.Threading.CancellationToken()); return(queriedCategories); }
public static async Task <CategoriesEnvelope> ListCategories(SliceFixture fixture, List.Query command) { // first create the default user var user = await UserHelpers.CreateDefaultUser(fixture); var dbContext = fixture.GetDbContext(); var currentAccessor = new StubCurrentUserAccessor(user.Username); var createCategoryCommand = new Create.Command() { Category = new Create.CategoryData() { ParentCategory = 0, Name = "TestCategory", Description = "This is a test Category" } }; var categoryCreateHandler = new Create.Handler(dbContext, currentAccessor); var createdCategory = await categoryCreateHandler.Handle(createCategoryCommand, new System.Threading.CancellationToken()); var categoryQueryHandler = new List.QueryHandler(dbContext, currentAccessor); var queriedCategories = await categoryQueryHandler.Handle(command, new System.Threading.CancellationToken()); return(queriedCategories); }
public static async Task <Domain.Article> CreateArticle(SliceFixture fixture, Create.Command command) { var user = await UserHelpers.CreateDefaultUser(fixture); var dbContext = fixture.GetDbContext(); var currentUserAccessor = new StubCurrentUserAccessor(user.Username); var handler = new Create.Handler(dbContext, currentUserAccessor); var created = await handler.Handle(command, new CancellationToken()); var article = await fixture.ExecuteDbContextAsync(context => context.Articles.Where(a => a.ArticleId == created.Article.ArticleId).SingleOrDefaultAsync()); return(article); }
public static async Task <Domain.ArticleCategory> CreateArticleCategory(SliceFixture fixture, Create.Command command) { // first create the default user var user = await UserHelpers.CreateDefaultUser(fixture); var dbContext = fixture.GetDbContext(); var currentAccessor = new StubCurrentUserAccessor(user.Username); var categoryCreateHandler = new Create.Handler(dbContext, currentAccessor); var created = await categoryCreateHandler.Handle(command, new System.Threading.CancellationToken()); var dbCategory = await fixture.ExecuteDbContextAsync(db => db.ArticleCategories.Where(a => a.ArticleCategoryId == created.ArticleCategoryId) .SingleOrDefaultAsync()); return(dbCategory); }