public async Task Should_create_new_user_and_add_event()
        {
            using (var dbContext = new AtlesDbContext(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);
            }
        }
Beispiel #2
0
        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 AtlesDbContext(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 AtlesDbContext(options))
            {
                var sut    = new PermissionSetRules(dbContext);
                var actual = await sut.IsNameUniqueAsync(siteId, "Permission Set 1", permissionSetId);

                Assert.IsFalse(actual);
            }
        }
Beispiel #3
0
        public async Task Should_create_new_category_and_add_event()
        {
            using (var dbContext = new AtlesDbContext(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 AtlesDbContext(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 AtlesDbContext(options))
            {
                var sut    = new ForumRules(dbContext);
                var actual = await sut.IsNameUniqueAsync(siteId, categoryId, "Forum 1", forumId);

                Assert.IsFalse(actual);
            }
        }
Beispiel #5
0
 public UserService(AtlesDbContext dbContext,
                    IValidator <CreateUser> createValidator,
                    IValidator <UpdateUser> updateValidator)
 {
     _dbContext       = dbContext;
     _createValidator = createValidator;
     _updateValidator = updateValidator;
 }
 public IntegrityService(IContextService contextService,
                         IUserService userService,
                         AtlesDbContext dbContext)
 {
     _contextService = contextService;
     _userService    = userService;
     _dbContext      = dbContext;
 }
 public InstallationService(AtlesDbContext dbContext,
                            IConfiguration configuration,
                            IServiceProvider serviceProvider)
 {
     _dbContext       = dbContext;
     _configuration   = configuration;
     _serviceProvider = serviceProvider;
 }
Beispiel #8
0
 public ForumModelBuilder(AtlesDbContext dbContext,
                          ICacheManager cacheManager,
                          IGravatarService gravatarService)
 {
     _dbContext       = dbContext;
     _cacheManager    = cacheManager;
     _gravatarService = gravatarService;
 }
 public PermissionModelBuilder(AtlesDbContext dbContext,
                               ICacheManager cacheManager,
                               RoleManager <IdentityRole> roleManager)
 {
     _dbContext    = dbContext;
     _cacheManager = cacheManager;
     _roleManager  = roleManager;
 }
Beispiel #10
0
 public UserModelBuilder(AtlesDbContext dbContext,
                         RoleManager <IdentityRole> roleManager,
                         UserManager <IdentityUser> userManager)
 {
     _dbContext   = dbContext;
     _roleManager = roleManager;
     _userManager = userManager;
 }
Beispiel #11
0
 public SiteService(AtlesDbContext dbContext,
                    ICacheManager cacheManager,
                    IValidator <UpdateSite> updateValidator)
 {
     _dbContext       = dbContext;
     _cacheManager    = cacheManager;
     _updateValidator = updateValidator;
 }
        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", PostStatusType.Published);
            var reply    = Post.CreateReply(Guid.NewGuid(), topicId, forumId, Guid.NewGuid(), "Content", PostStatusType.Published);

            using (var dbContext = new AtlesDbContext(options))
            {
                dbContext.Categories.Add(category);
                dbContext.Forums.Add(forum);
                dbContext.Posts.Add(topic);
                dbContext.Posts.Add(reply);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(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);
            }
        }
Beispiel #13
0
 public ForumService(AtlesDbContext dbContext,
                     ICacheManager cacheManager,
                     IValidator <CreateForum> createValidator,
                     IValidator <UpdateForum> updateValidator)
 {
     _dbContext       = dbContext;
     _cacheManager    = cacheManager;
     _createValidator = createValidator;
     _updateValidator = updateValidator;
 }
 public UserModelBuilder(AtlesDbContext dbContext,
                         ICacheManager cacheManager,
                         IGravatarService gravatarService,
                         ISearchModelBuilder searchModelBuilder)
 {
     _dbContext          = dbContext;
     _cacheManager       = cacheManager;
     _gravatarService    = gravatarService;
     _searchModelBuilder = searchModelBuilder;
 }
        public async Task Should_return_true_when_name_is_unique_for_existing_category()
        {
            using (var dbContext = new AtlesDbContext(Shared.CreateContextOptions()))
            {
                var sut    = new CategoryRules(dbContext);
                var actual = await sut.IsNameUniqueAsync(Guid.NewGuid(), "My Category", Guid.NewGuid());

                Assert.IsTrue(actual);
            }
        }
Beispiel #16
0
        public async Task Should_return_false_when_topic_is_not_valid()
        {
            using (var dbContext = new AtlesDbContext(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 AtlesDbContext(Shared.CreateContextOptions()))
            {
                var sut    = new UserRules(dbContext);
                var actual = await sut.IsDisplayNameUniqueAsync("Display Name", Guid.NewGuid());

                Assert.IsTrue(actual);
            }
        }
 public CategoryService(AtlesDbContext dbContext,
                        ICacheManager cacheManager,
                        IValidator <CreateCategory> createValidator,
                        IValidator <UpdateCategory> updateValidator)
 {
     _dbContext       = dbContext;
     _cacheManager    = cacheManager;
     _createValidator = createValidator;
     _updateValidator = updateValidator;
 }
 public PermissionSetService(AtlesDbContext dbContext,
                             ICacheManager cacheManager,
                             IValidator <CreatePermissionSet> createValidator,
                             IValidator <UpdatePermissionSet> updateValidator)
 {
     _dbContext       = dbContext;
     _cacheManager    = cacheManager;
     _createValidator = createValidator;
     _updateValidator = updateValidator;
 }
Beispiel #20
0
        public async Task Should_return_true_when_name_is_unique()
        {
            using (var dbContext = new AtlesDbContext(Shared.CreateContextOptions()))
            {
                var sut    = new PermissionSetRules(dbContext);
                var actual = await sut.IsNameUniqueAsync(Guid.NewGuid(), "My Permission Set");

                Assert.IsTrue(actual);
            }
        }
Beispiel #21
0
 public ContextService(IHttpContextAccessor httpContextAccessor,
                       ICacheManager cacheManager,
                       AtlesDbContext dbContext,
                       IGravatarService gravatarService)
 {
     _httpContextAccessor = httpContextAccessor;
     _cacheManager        = cacheManager;
     _dbContext           = dbContext;
     _gravatarService     = gravatarService;
 }
Beispiel #22
0
        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 AtlesDbContext(options))
            {
                dbContext.Categories.Add(category);
                dbContext.Forums.Add(forum1);
                dbContext.Forums.Add(forum2);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(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 AtlesDbContext(options))
            {
                dbContext.PermissionSets.Add(permissionSet);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(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);
            }
        }
Beispiel #24
0
        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 AtlesDbContext(options))
            {
                dbContext.Categories.Add(category);
                dbContext.Forums.Add(forum);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(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 RepliesController(IContextService contextService,
                          IReplyService replyService,
                          ISecurityService securityService,
                          AtlesDbContext dbContext,
                          IPermissionModelBuilder permissionModelBuilder,
                          ILogger <RepliesController> logger)
 {
     _contextService         = contextService;
     _replyService           = replyService;
     _securityService        = securityService;
     _dbContext              = dbContext;
     _permissionModelBuilder = permissionModelBuilder;
     _logger = logger;
 }
Beispiel #26
0
        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 AtlesDbContext(options))
            {
                dbContext.Categories.Add(category1);
                dbContext.Categories.Add(category2);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(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);
            }
        }
Beispiel #27
0
        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", PostStatusType.Published);

            using (var dbContext = new AtlesDbContext(options))
            {
                dbContext.Categories.Add(category);
                dbContext.Forums.Add(forum);
                dbContext.Posts.Add(topic);

                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(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);
            }
        }
Beispiel #28
0
        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 AtlesDbContext(options))
            {
                dbContext.PermissionSets.Add(permissionSet);
                dbContext.Categories.Add(category);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(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);
            }
        }
Beispiel #29
0
 public TopicsController(IContextService contextService,
                         ITopicModelBuilder topicModelBuilder,
                         IPostModelBuilder postModelBuilder,
                         ITopicService topicService,
                         ISecurityService securityService,
                         AtlesDbContext dbContext,
                         IPermissionModelBuilder permissionModelBuilder,
                         ILogger <TopicsController> logger)
 {
     _contextService         = contextService;
     _topicModelBuilder      = topicModelBuilder;
     _postModelBuilder       = postModelBuilder;
     _topicService           = topicService;
     _securityService        = securityService;
     _dbContext              = dbContext;
     _permissionModelBuilder = permissionModelBuilder;
     _logger = logger;
 }
        public async Task Should_return_false_when_display_name_is_not_unique()
        {
            var options     = Shared.CreateContextOptions();
            var displayName = "Display Name";

            using (var dbContext = new AtlesDbContext(options))
            {
                var user = new User(Guid.NewGuid().ToString(), "*****@*****.**", displayName);
                dbContext.Users.Add(user);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new AtlesDbContext(options))
            {
                var sut    = new UserRules(dbContext);
                var actual = await sut.IsDisplayNameUniqueAsync(displayName);

                Assert.IsFalse(actual);
            }
        }