public async Task Should_return_false_when_name_is_not_unique_for_existing_permission_set() { var options = Shared.CreateContextOptions(); var siteId = Guid.NewGuid(); var permissionSetId = Guid.NewGuid(); using (var dbContext = new AtlasDbContext(options)) { var site = new Site(siteId, "Name", "Title"); var permissionSet1 = new PermissionSet(siteId, "Permission Set 1", new List <PermissionCommand>()); var permissionSet2 = new PermissionSet(permissionSetId, siteId, "Permission Set 2", new List <PermissionCommand>()); dbContext.Sites.Add(site); dbContext.PermissionSets.Add(permissionSet1); dbContext.PermissionSets.Add(permissionSet2); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var sut = new PermissionSetRules(dbContext); var actual = await sut.IsNameUniqueAsync(siteId, "Permission Set 1", permissionSetId); Assert.IsFalse(actual); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AtlasDbContext atlasDbContext, ApplicationDbContext applicationDbContext, IInstallationService installationService, IDocumentationService documentationService) { if (env.IsDevelopment()) { app.UseExceptionHandler("/Error"); //app.UseDeveloperExceptionPage(); //app.UseDatabaseErrorPage(); app.UseWebAssemblyDebugging(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseBlazorFrameworkFiles(); app.UseStaticFiles(); //app.UseStaticFiles(new StaticFileOptions //{ // FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Uploads")), // RequestPath = new PathString("/Uploads") //}); app.UseRouting(); app.UseIdentityServer(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllers(); endpoints.MapFallbackToFile("index.html"); }); if (Configuration["MigrateDatabases"] == "true") { atlasDbContext.Database.Migrate(); applicationDbContext.Database.Migrate(); } if (Configuration["EnsureDefaultSiteInitialized"] == "true") { installationService.EnsureDefaultSiteInitializedAsync().Wait(); } if (Configuration["GenerateDocumentationOnStartup"] == "true") { documentationService.Generate(typeof(Site).Assembly); } }
public async Task Should_create_new_user_and_add_event() { using (var dbContext = new AtlasDbContext(Shared.CreateContextOptions())) { var command = Fixture.Create <CreateUser>(); var createValidator = new Mock <IValidator <CreateUser> >(); createValidator .Setup(x => x.ValidateAsync(command, new CancellationToken())) .ReturnsAsync(new ValidationResult()); var updateValidator = new Mock <IValidator <UpdateUser> >(); var sut = new UserService(dbContext, createValidator.Object, updateValidator.Object); await sut.CreateAsync(command); var user = await dbContext.Users.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); createValidator.Verify(x => x.ValidateAsync(command, new CancellationToken())); Assert.NotNull(user); Assert.NotNull(@event); } }
public async Task Should_create_new_category_and_add_event() { using (var dbContext = new AtlasDbContext(Shared.CreateContextOptions())) { var command = Fixture.Create <CreateCategory>(); var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateCategory> >(); createValidator .Setup(x => x.ValidateAsync(command, new CancellationToken())) .ReturnsAsync(new ValidationResult()); var updateValidator = new Mock <IValidator <UpdateCategory> >(); var sut = new CategoryService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.CreateAsync(command); var category = await dbContext.Categories.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); createValidator.Verify(x => x.ValidateAsync(command, new CancellationToken())); Assert.NotNull(category); Assert.AreEqual(1, category.SortOrder); Assert.NotNull(@event); } }
public async Task Should_return_false_when_name_is_not_unique_for_existing_forum() { var options = Shared.CreateContextOptions(); var siteId = Guid.NewGuid(); var categoryId = Guid.NewGuid(); var forumId = Guid.NewGuid(); using (var dbContext = new AtlasDbContext(options)) { var category = new Category(categoryId, siteId, "Category", 1, Guid.NewGuid()); var forum1 = new Forum(categoryId, "Forum 1", "My Forum", "my-forum", 1); var forum2 = new Forum(forumId, categoryId, "Forum 2", "my-forum-2", "My Forum", 2); dbContext.Categories.Add(category); dbContext.Forums.Add(forum1); dbContext.Forums.Add(forum2); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var sut = new ForumRules(dbContext); var actual = await sut.IsNameUniqueAsync(siteId, categoryId, "Forum 1", forumId); Assert.IsFalse(actual); } }
public InstallationService(AtlasDbContext dbContext, IConfiguration configuration, IServiceProvider serviceProvider) { _dbContext = dbContext; _configuration = configuration; _serviceProvider = serviceProvider; }
public UserService(AtlasDbContext dbContext, IValidator <CreateUser> createValidator, IValidator <UpdateUser> updateValidator) { _dbContext = dbContext; _createValidator = createValidator; _updateValidator = updateValidator; }
public UserModelBuilder(AtlasDbContext dbContext, RoleManager <IdentityRole> roleManager, UserManager <IdentityUser> userManager) { _dbContext = dbContext; _roleManager = roleManager; _userManager = userManager; }
public PermissionModelBuilder(AtlasDbContext dbContext, ICacheManager cacheManager, RoleManager <IdentityRole> roleManager) { _dbContext = dbContext; _cacheManager = cacheManager; _roleManager = roleManager; }
public TopicModelBuilder(AtlasDbContext dbContext, ICacheManager cacheManager, IGravatarService gravatarService) { _dbContext = dbContext; _cacheManager = cacheManager; _gravatarService = gravatarService; }
public SiteService(AtlasDbContext dbContext, ICacheManager cacheManager, IValidator <UpdateSite> updateValidator) { _dbContext = dbContext; _cacheManager = cacheManager; _updateValidator = updateValidator; }
public IntegrityService(IContextService contextService, IUserService userService, AtlasDbContext dbContext) { _contextService = contextService; _userService = userService; _dbContext = dbContext; }
public async Task Should_update_reply_and_add_event() { var options = Shared.CreateContextOptions(); var siteId = Guid.NewGuid(); var categoryId = Guid.NewGuid(); var forumId = Guid.NewGuid(); var topicId = Guid.NewGuid(); var category = new Category(categoryId, siteId, "Category", 1, Guid.NewGuid()); var forum = new Forum(forumId, categoryId, "Forum", "my-forum", "My Forum", 1); var topic = Post.CreateTopic(topicId, forumId, Guid.NewGuid(), "Title", "slug", "Content", StatusType.Published); var reply = Post.CreateReply(Guid.NewGuid(), topicId, forumId, Guid.NewGuid(), "Content", StatusType.Published); using (var dbContext = new AtlasDbContext(options)) { dbContext.Categories.Add(category); dbContext.Forums.Add(forum); dbContext.Posts.Add(topic); dbContext.Posts.Add(reply); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = Fixture.Build <UpdateReply>() .With(x => x.Id, reply.Id) .With(x => x.SiteId, siteId) .With(x => x.ForumId, forumId) .With(x => x.TopicId, topicId) .Create(); var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateReply> >(); var updateValidator = new Mock <IValidator <UpdateReply> >(); updateValidator .Setup(x => x.ValidateAsync(command, new CancellationToken())) .ReturnsAsync(new ValidationResult()); var sut = new ReplyService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.UpdateAsync(command); var updatedReply = await dbContext.Posts.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); updateValidator.Verify(x => x.ValidateAsync(command, new CancellationToken())); Assert.AreEqual(command.Content, updatedReply.Content); Assert.NotNull(@event); } }
public UserModelBuilder(AtlasDbContext dbContext, ICacheManager cacheManager, IGravatarService gravatarService, ISearchModelBuilder searchModelBuilder) { _dbContext = dbContext; _cacheManager = cacheManager; _gravatarService = gravatarService; _searchModelBuilder = searchModelBuilder; }
public ContextService(IHttpContextAccessor httpContextAccessor, ICacheManager cacheManager, AtlasDbContext dbContext, IGravatarService gravatarService) { _httpContextAccessor = httpContextAccessor; _cacheManager = cacheManager; _dbContext = dbContext; _gravatarService = gravatarService; }
public async Task Should_return_true_when_name_is_unique_for_existing_category() { using (var dbContext = new AtlasDbContext(Shared.CreateContextOptions())) { var sut = new CategoryRules(dbContext); var actual = await sut.IsNameUniqueAsync(Guid.NewGuid(), "My Category", Guid.NewGuid()); Assert.IsTrue(actual); } }
public TopicService(AtlasDbContext dbContext, ICacheManager cacheManager, IValidator <CreateTopic> createValidator, IValidator <UpdateTopic> updateValidator) { _dbContext = dbContext; _cacheManager = cacheManager; _createValidator = createValidator; _updateValidator = updateValidator; }
public async Task Should_return_false_when_topic_is_not_valid() { using (var dbContext = new AtlasDbContext(Shared.CreateContextOptions())) { var sut = new TopicRules(dbContext); var actual = await sut.IsValidAsync(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()); Assert.IsFalse(actual); } }
public async Task Should_return_true_when_display_name_is_unique_for_existing_member() { using (var dbContext = new AtlasDbContext(Shared.CreateContextOptions())) { var sut = new UserRules(dbContext); var actual = await sut.IsDisplayNameUniqueAsync("Display Name", Guid.NewGuid()); Assert.IsTrue(actual); } }
public PermissionSetService(AtlasDbContext dbContext, ICacheManager cacheManager, IValidator <CreatePermissionSet> createValidator, IValidator <UpdatePermissionSet> updateValidator) { _dbContext = dbContext; _cacheManager = cacheManager; _createValidator = createValidator; _updateValidator = updateValidator; }
public async Task Should_return_true_when_name_is_unique() { using (var dbContext = new AtlasDbContext(Shared.CreateContextOptions())) { var sut = new PermissionSetRules(dbContext); var actual = await sut.IsNameUniqueAsync(Guid.NewGuid(), "My Permission Set"); Assert.IsTrue(actual); } }
public CategoryService(AtlasDbContext dbContext, ICacheManager cacheManager, IValidator <CreateCategory> createValidator, IValidator <UpdateCategory> updateValidator) { _dbContext = dbContext; _cacheManager = cacheManager; _createValidator = createValidator; _updateValidator = updateValidator; }
public async Task Should_move_forum_down_and_add_events() { var options = Shared.CreateContextOptions(); var categoryId = Guid.NewGuid(); var siteId = Guid.NewGuid(); var category = new Category(categoryId, siteId, "Category", 1, Guid.NewGuid()); var forum1 = new Forum(categoryId, "Forum 1", "my-forum-1", "Forum 1", 1); var forum2 = new Forum(categoryId, "Forum 2", "my-forum-2", "Forum 2", 2); using (var dbContext = new AtlasDbContext(options)) { dbContext.Categories.Add(category); dbContext.Forums.Add(forum1); dbContext.Forums.Add(forum2); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = new MoveForum { Id = forum1.Id, Direction = Direction.Down, SiteId = siteId }; var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateForum> >(); var updateValidator = new Mock <IValidator <UpdateForum> >(); var sut = new ForumService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.MoveAsync(command); var updatedForum1 = await dbContext.Forums.FirstOrDefaultAsync(x => x.Id == forum1.Id); var updatedForum2 = await dbContext.Forums.FirstOrDefaultAsync(x => x.Id == forum2.Id); var event1 = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == forum1.Id); var event2 = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == forum2.Id); Assert.AreEqual(forum2.SortOrder, updatedForum1.SortOrder); Assert.AreEqual(forum1.SortOrder, updatedForum2.SortOrder); Assert.NotNull(event1); Assert.NotNull(event2); } }
public async Task Should_update_permission_set_and_add_event() { var options = Shared.CreateContextOptions(); var permissionSet = new PermissionSet(Guid.NewGuid(), Guid.NewGuid(), "Default", new List <PermissionCommand>()); using (var dbContext = new AtlasDbContext(options)) { dbContext.PermissionSets.Add(permissionSet); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = new UpdatePermissionSet { SiteId = permissionSet.SiteId, Id = permissionSet.Id, Name = "Permission Set", Permissions = new List <PermissionCommand> { new PermissionCommand { Type = PermissionType.Start, RoleId = Guid.NewGuid().ToString() } } }; var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreatePermissionSet> >(); var updateValidator = new Mock <IValidator <UpdatePermissionSet> >(); updateValidator .Setup(x => x.ValidateAsync(command, new CancellationToken())) .ReturnsAsync(new ValidationResult()); var sut = new PermissionSetService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.UpdateAsync(command); var updatedPermissionSet = await dbContext.PermissionSets.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); updateValidator.Verify(x => x.ValidateAsync(command, new CancellationToken())); Assert.AreEqual(command.Name, updatedPermissionSet.Name); Assert.NotNull(@event); } }
public async Task Should_update_forum_and_add_event() { var options = Shared.CreateContextOptions(); var categoryId = Guid.NewGuid(); var siteId = Guid.NewGuid(); var category = new Category(categoryId, siteId, "Category", 1, Guid.NewGuid()); var forum = new Forum(categoryId, "Forum 1", "my-forum", "Forum 1", 1); using (var dbContext = new AtlasDbContext(options)) { dbContext.Categories.Add(category); dbContext.Forums.Add(forum); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = Fixture.Build <UpdateForum>() .With(x => x.Id, forum.Id) .With(x => x.CategoryId, forum.CategoryId) .With(x => x.SiteId, siteId) .Create(); var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateForum> >(); var updateValidator = new Mock <IValidator <UpdateForum> >(); updateValidator .Setup(x => x.ValidateAsync(command, new CancellationToken())) .ReturnsAsync(new ValidationResult()); var sut = new ForumService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.UpdateAsync(command); var updatedForum = await dbContext.Forums.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); updateValidator.Verify(x => x.ValidateAsync(command, new CancellationToken())); Assert.AreEqual(command.Name, updatedForum.Name); Assert.NotNull(@event); } }
public async Task Should_move_category_up_and_add_events() { var options = Shared.CreateContextOptions(); var siteId = Guid.NewGuid(); var category1 = new Category(siteId, "Category 1", 1, Guid.NewGuid()); var category2 = new Category(siteId, "Category 2", 2, Guid.NewGuid()); using (var dbContext = new AtlasDbContext(options)) { dbContext.Categories.Add(category1); dbContext.Categories.Add(category2); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = new MoveCategory { Id = category2.Id, Direction = Direction.Up, SiteId = siteId }; var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateCategory> >(); var updateValidator = new Mock <IValidator <UpdateCategory> >(); var sut = new CategoryService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.MoveAsync(command); var updatedCategory1 = await dbContext.Categories.FirstOrDefaultAsync(x => x.Id == category1.Id); var updatedCategory2 = await dbContext.Categories.FirstOrDefaultAsync(x => x.Id == category2.Id); var event1 = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == category1.Id); var event2 = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == category2.Id); Assert.AreEqual(category2.SortOrder, updatedCategory1.SortOrder); Assert.AreEqual(category1.SortOrder, updatedCategory2.SortOrder); Assert.NotNull(event1); Assert.NotNull(event2); } }
public RepliesController(IContextService contextService, IReplyService replyService, ISecurityService securityService, AtlasDbContext dbContext, IPermissionModelBuilder permissionModelBuilder, ILogger <RepliesController> logger) { _contextService = contextService; _replyService = replyService; _securityService = securityService; _dbContext = dbContext; _permissionModelBuilder = permissionModelBuilder; _logger = logger; }
public async Task Should_lock_topic_and_add_event() { var options = Shared.CreateContextOptions(); var siteId = Guid.NewGuid(); var categoryId = Guid.NewGuid(); var forumId = Guid.NewGuid(); var category = new Category(categoryId, siteId, "Category", 1, Guid.NewGuid()); var forum = new Forum(forumId, category.Id, "Forum", "my-forum", "My Forum", 1); var topic = Post.CreateTopic(forumId, Guid.NewGuid(), "Title", "slug", "Content", StatusType.Published); using (var dbContext = new AtlasDbContext(options)) { dbContext.Categories.Add(category); dbContext.Forums.Add(forum); dbContext.Posts.Add(topic); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = Fixture.Build <LockTopic>() .With(x => x.Id, topic.Id) .With(x => x.ForumId, forumId) .With(x => x.SiteId, siteId) .Create(); var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateTopic> >(); var updateValidator = new Mock <IValidator <UpdateTopic> >(); var sut = new TopicService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.LockAsync(command); var lockedTopic = await dbContext.Posts.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); Assert.AreEqual(command.Locked, lockedTopic.Locked); Assert.NotNull(@event); } }
public async Task Should_update_category_and_add_event() { var options = Shared.CreateContextOptions(); var permissionSet = new PermissionSet(Guid.NewGuid(), Guid.NewGuid(), "Default", new List <PermissionCommand>()); var category = new Category(Guid.NewGuid(), permissionSet.SiteId, "Category", 1, permissionSet.Id); using (var dbContext = new AtlasDbContext(options)) { dbContext.PermissionSets.Add(permissionSet); dbContext.Categories.Add(category); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = Fixture.Build <UpdateCategory>() .With(x => x.Id, category.Id) .With(x => x.SiteId, category.SiteId) .Create(); var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateCategory> >(); var updateValidator = new Mock <IValidator <UpdateCategory> >(); updateValidator .Setup(x => x.ValidateAsync(command, new CancellationToken())) .ReturnsAsync(new ValidationResult()); var sut = new CategoryService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.UpdateAsync(command); var updatedCategory = await dbContext.Categories.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); updateValidator.Verify(x => x.ValidateAsync(command, new CancellationToken())); Assert.AreEqual(command.Name, updatedCategory.Name); Assert.NotNull(@event); } }
public TopicsController(IContextService contextService, ITopicModelBuilder topicModelBuilder, IPostModelBuilder postModelBuilder, ITopicService topicService, ISecurityService securityService, AtlasDbContext dbContext, IPermissionModelBuilder permissionModelBuilder, ILogger <TopicsController> logger) { _contextService = contextService; _topicModelBuilder = topicModelBuilder; _postModelBuilder = postModelBuilder; _topicService = topicService; _securityService = securityService; _dbContext = dbContext; _permissionModelBuilder = permissionModelBuilder; _logger = logger; }