Пример #1
0
        public void UpdateCategory()
        {
            var inputParameter = new Domain.Category("name", 1, "description");
            var command        = new UpdateCategoryCommand {
                Id = "1", Name = inputParameter.Name, SortOrder = inputParameter.SortOrder, Description = inputParameter.Description
            };
            var dto = Substitute.For <ICategoryDto>();

            var datastore = Substitute.For <ICategoryDatastore>();

            datastore.Create(inputParameter).Returns <ICategoryDto>(dto);
            var taskDatastore = Substitute.For <ITaskDatastore>();

            UpdateCategoryCommandHandler handler = new UpdateCategoryCommandHandler(datastore, taskDatastore);
            GenericValidationCommandHandlerDecorator <UpdateCategoryCommand> val =
                new GenericValidationCommandHandlerDecorator <UpdateCategoryCommand>(
                    handler,
                    new List <IValidator <UpdateCategoryCommand> > {
                new UpdateCategoryValidator(TestUtils.GetInt32IdValidator())
            }
                    );

            val.Execute(command);

            datastore.ReceivedWithAnyArgs(1).Update(inputParameter);
        }
Пример #2
0
        public void CreateCategory()
        {
            var inputParameter = new Domain.Category("name", 1, "description");
            var command        = new CreateCategoryCommand {
                Name = inputParameter.Name, SortOrder = inputParameter.SortOrder, Description = inputParameter.Description
            };
            var dto = Substitute.For <ICategoryDto>();

            var datastore = Substitute.For <ICategoryDatastore>();

            datastore.Create(inputParameter).Returns <ICategoryDto>(dto);
            var taskDatastore = Substitute.For <ITaskDatastore>();

            CreateCategoryCommandHandler handler = new CreateCategoryCommandHandler(datastore, taskDatastore);
            GenericValidationCommandHandlerDecorator <CreateCategoryCommand> val =
                new GenericValidationCommandHandlerDecorator <CreateCategoryCommand>(
                    handler,
                    new List <IValidator <NForum.CQS.Commands.Categories.CreateCategoryCommand> > {
                new NForum.CQS.Validators.Categories.CreateCategoryValidator()
            }
                    );

            val.Execute(command);

            datastore.ReceivedWithAnyArgs(1).Create(inputParameter);
        }
Пример #3
0
        public void CreateTopic()
        {
            var parentCategory = Substitute.For <Domain.Category>("category", 1, "desc");

            parentCategory.Id.Returns("1");

            var parentForum = Substitute.For <Domain.Forum>(parentCategory, "forum", 1, "desc");

            parentForum.Id.Returns("1");

            var inputParameter = new Domain.Topic(parentForum, "topic subject", "bla bla bla ", Domain.TopicType.Regular);
            var command        = new CreateTopicCommand {
                ForumId = parentForum.Id, Content = inputParameter.Content, State = inputParameter.State, Subject = inputParameter.Subject, Type = inputParameter.Type
            };
            var dto = Substitute.For <ITopicDto>();

            var categoryDatastore = Substitute.For <ICategoryDatastore>();
            var datalayerCategory = Substitute.For <ICategoryDto>();

            datalayerCategory.Id.Returns("1");
            var forumDatastore = Substitute.For <IForumDatastore>();
            var datalayerForum = Substitute.For <IForumDto>();

            datalayerForum.Id.Returns("1");
            categoryDatastore.ReadById(parentCategory.Id).Returns(datalayerCategory);
            forumDatastore.ReadById(parentForum.Id).Returns(datalayerForum);

            var datastore = Substitute.For <ITopicDatastore>();

            datastore.Create(inputParameter).Returns <ITopicDto>(dto);

            var taskDatastore = Substitute.For <ITaskDatastore>();
            var user          = Substitute.For <IPrincipal>();

            CreateTopicCommandHandler handler = new CreateTopicCommandHandler(forumDatastore, datastore, taskDatastore, user);
            GenericValidationCommandHandlerDecorator <CreateTopicCommand> val =
                new GenericValidationCommandHandlerDecorator <CreateTopicCommand>(
                    handler,
                    new List <IValidator <NForum.CQS.Commands.Topics.CreateTopicCommand> > {
                new NForum.CQS.Validators.Topics.CreateTopicValidator(TestUtils.GetInt32IdValidator())
            }
                    );

            val.Execute(command);

            // Let's make sure the Create method on the datastore is actually called once. Nevermind the input argument.
            datastore.ReceivedWithAnyArgs(1).Create(inputParameter);
        }
Пример #4
0
        public void CreateForumAsForumChild()
        {
            var parentCategory = Substitute.For <Domain.Category>("category", 1, "desc");

            parentCategory.Id.Returns("1");

            var parentForum = Substitute.For <Domain.Forum>(parentCategory, "category", 1, "desc");

            parentForum.Id.Returns("1");

            var inputParameter = new Domain.Forum(parentForum, "name", 1, "description");
            var command        = new CreateForumCommand {
                ParentForumId = parentForum.Id, Name = inputParameter.Name, SortOrder = inputParameter.SortOrder, Description = inputParameter.Description
            };
            var dto = Substitute.For <IForumDto>();

            var categoryDatastore = Substitute.For <ICategoryDatastore>();
            var datalayerCategory = Substitute.For <ICategoryDto>();

            datalayerCategory.Id.Returns("1");
            categoryDatastore.ReadById(parentCategory.Id).Returns(datalayerCategory);

            var datalayerForum = Substitute.For <IForumDto>();

            datalayerForum.Id.Returns("1");

            var datastore = Substitute.For <IForumDatastore>();

            datastore.CreateAsForumChild(inputParameter).Returns <IForumDto>(dto);
            var taskDatastore = Substitute.For <ITaskDatastore>();

            CreateForumCommandHandler handler = new CreateForumCommandHandler(categoryDatastore, datastore, taskDatastore);
            GenericValidationCommandHandlerDecorator <CreateForumCommand> val =
                new GenericValidationCommandHandlerDecorator <CreateForumCommand>(
                    handler,
                    new List <IValidator <NForum.CQS.Commands.Forums.CreateForumCommand> > {
                new NForum.CQS.Validators.Forums.CreateForumValidator(TestUtils.GetInt32IdValidator())
            }
                    );

            val.Execute(command);

            datastore.ReceivedWithAnyArgs(1).CreateAsForumChild(inputParameter);
        }
Пример #5
0
        public void UpdateTopic()
        {
            var parentCategory = Substitute.For <Domain.Category>("category", 1, "desc");

            parentCategory.Id.Returns("1");
            var parentForum = Substitute.For <Domain.Forum>(parentCategory, "forum", 1, "desc");

            parentForum.Id.Returns("1");

            Domain.Topic       oldTopic = new Domain.Topic(parentForum, "subject, topic2", "bla blalba", Domain.TopicType.Regular);
            UpdateTopicCommand command  = new UpdateTopicCommand {
                Id = "1", Subject = "a new subject", Content = "and new content"
            };
            ITopicDto dto = Substitute.For <ITopicDto>();

            var datastore = Substitute.For <ITopicDatastore>();

            datastore.Update(oldTopic).Returns <ITopicDto>(dto);

            var userProvider = Substitute.For <IUserProvider>();
            var user         = Substitute.For <IPrincipal>();
            var author       = Substitute.For <IAuthenticatedUser>();

            userProvider.Get(user).Returns <IAuthenticatedUser>(author);
            var taskDatastore = Substitute.For <ITaskDatastore>();

            UpdateTopicCommandHandler handler = new UpdateTopicCommandHandler(datastore, user, userProvider, taskDatastore);
            GenericValidationCommandHandlerDecorator <UpdateTopicCommand> val =
                new GenericValidationCommandHandlerDecorator <UpdateTopicCommand>(
                    handler,
                    new List <IValidator <UpdateTopicCommand> > {
                new UpdateTopicValidator(TestUtils.GetInt32IdValidator())
            }
                    );

            val.Execute(command);

            // Let's make sure the Update method on the datastore is actually called once. Nevermind the input argument.
            datastore.ReceivedWithAnyArgs(1).Update(oldTopic);
        }