Esempio n. 1
0
        public async Task<HttpResponseMessage> Update(IssueModel issueModel)
        {
            HttpResponseMessage response;
            if (issueModel == null)
            {
                response = this.CreateErrorResponse("The issueModel is not set.", HttpStatusCode.BadRequest);
                return response;
            }

            var updateIssueCommand = this.commandRepository.UpdateIssue(issueModel);
            var commandResult = await this.commandExecutor.ExecuteAsync(updateIssueCommand);

            response = this.CreateResponseFromCommandResult(commandResult);
            return response;
        }
        public async void Create_WithValidModel_ReturnsOk()
        {
            // arrange
            this.commandRepositoryMock
                .Setup(x => x.CreateNewIssue(It.IsNotNull<IssueModel>()))
                .Returns(this.CreateCommandMock(new CommandResult<IssueModel>(true, new IssueModel())));
            IssueModel issueModel = new IssueModel();

            // act
            var response = await this.controller.Create(issueModel);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            IssueModel createdIssue;
            Assert.IsTrue(response.TryGetContentValue(out createdIssue));
        }
        public async void Execute_WithNullContent_NotSuccessful()
        {
            // arrange
            var issueModel = new IssueModel
            {
                UserId = Guid.NewGuid(),
                Title = "title",
                Content = null
            };

            var command = this.commandRepository.CreateNewIssue(issueModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
Esempio n. 4
0
 public CommandBase UpdateIssue(IssueModel issueModel)
 {
     var command = this.commandFactory.CreateCommand<UpdateIssueCommand>();
     command.Initialize(issueModel);
     return command;
 }
Esempio n. 5
0
 public CommandBase<IssueModel> CreateNewIssue(IssueModel issueModel)
 {
     var command = this.commandFactory.CreateCommand<CreateNewIssueCommand, IssueModel>();
     command.Initialize(issueModel);
     return command;
 }
        public async void Execute_WithUnknownUser_NotSuccessful()
        {
            // arrange
            var issueModel = new IssueModel
            {
                UserId = Guid.NewGuid(),
                Title = "title",
                Content = "content"
            };
            this.userAccessMock
                .Setup(x => x.TryGetById(issueModel.UserId))
                .Returns(Maybe<User>.Empty);

            var command = this.commandRepository.CreateNewIssue(issueModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
        public async void Execute_WithCorrectModel_Successful()
        {
            // arrange
            var issueModel = new IssueModel
            {
                UserId = Guid.NewGuid(),
                Title = "title",
                Content = "content"
            };
            User existingUser = new User { Id = issueModel.UserId };
            this.userAccessMock
                .Setup(x => x.TryGetById(issueModel.UserId))
                .Returns(new Maybe<User>(existingUser));
            Issue newIssue = new Issue { Id = Guid.NewGuid() };
            this.issueAccessMock
                .Setup(x => x.Add(issueModel.UserId, issueModel.Title, issueModel.Content))
                .Returns(newIssue);

            var command = this.commandRepository.CreateNewIssue(issueModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsSuccessful(commandResult);
            Assert.AreEqual(newIssue.Id, commandResult.SuccessData.Id);
        }
Esempio n. 8
0
 public void Initialize(IssueModel issueModel)
 {
     this.issueModel = issueModel;
 }