public IHttpActionResult PutTopic(int id, [FromBody] UpdateTopicCommand command)
        {
            command.intIdTopic = id;
            var resposta = _mediator.Send(command);

            return(Ok(resposta));
        }
Exemple #2
0
        public async Task Handle_GivenInvalidTopicData_ThrowsException()
        {
            // Arrange
            var topic = new TopicDTO
            {
                Id   = 99,
                Text = "Topic_new",
            };

            var command = new UpdateTopicCommand {
                Model = topic
            };

            // Act
            var handler = new UpdateTopicCommand.UpdateTopicCommandHandler(Context);

            // Assert
            await Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None));
        }
        protected void Reg_Top(object sender, EventArgs e)
        {
            section       = new Section();
            section.Id    = Int32.Parse(list_section.SelectedValue);
            section.Name  = list_section.DataTextField;
            topic         = new Topic();
            topic.Id      = Int32.Parse(Session["Id_top"].ToString());
            topic.Name    = name.Value;
            topic.Section = section;
            UpdateTopicCommand cmd = new UpdateTopicCommand(topic);

            cmd.Execute();
            if (topic.Code == 201)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme_succ()", true);
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true);
            }
        }
Exemple #4
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);
        }
Exemple #5
0
        public async Task Handler_GivenValidData_ShouldUpdateTopic()
        {
            // Arrange
            var topic = new TopicDTO
            {
                Id   = 1,
                Text = "Topic_new",
            };

            var command = new UpdateTopicCommand {
                Model = topic
            };

            // Act
            var handler = new UpdateTopicCommand.UpdateTopicCommandHandler(Context);
            await handler.Handle(command, CancellationToken.None);

            var entity = Context.Topics.Find(topic.Id);

            // Assert
            entity.ShouldNotBeNull();

            entity.Text.ShouldBe(command.Model.Text);
        }
Exemple #6
0
        public void Handle(UpdateTopicCommand message)
        {
            var currentTopic = _topicRepository.Get(message.Id);

            if (currentTopic.UserId != _user.GetUserId())
            {
                currentTopic.ValidationResult.Errors.Add(new ValidationFailure("UserId", "Acesso negado."));
                NotifyErrors(currentTopic.ValidationResult);
                return;
            }

            var topic = Topic.TopicFactory.FullTopic(message.Id, message.UserId, message.CategoryId, message.Title, message.Description, message.Created);

            if (!topic.IsValid())
            {
                NotifyErrors(topic.ValidationResult);
                return;
            }
            _topicRepository.Update(topic);
            if (Commit())
            {
                _bus.RaiseEvent(new UpdatedTopicEvent(topic.Id, topic.UserId, topic.CategoryId, topic.Title, topic.Description, topic.Created));
            }
        }