Beispiel #1
0
        public static async Task RejectDocument(this HttpClient httpClient, Uri documentUri,
                                                RejectDocumentCommand command)
        {
            var requestUri = CombineUri(documentUri, "reject");
            var content    = GetStringContent(command);

            var response = await httpClient.PutAsync(requestUri, content);

            response.EnsureSuccessStatusCode();
        }
Beispiel #2
0
        public async Task <IActionResult> RejectDocument(Guid id, [FromBody] RejectDocumentCommand command)
        {
            var outcome =
                from doc in GetDocumentFromEvents(id)
                from u in ValidateDocumentUser(doc.UserId.Value)
                from result in doc.Reject(command.Reason).AsTask()
                from _ in SaveAndPublishEventAsync(result.Event)
                select result.Document;

            return(await outcome.Map(val => val.ToActionResult(_ => NoContent())));
        }
Beispiel #3
0
        public async Task TestRejectDocumentReadEventsErrorBadRequestResult()
        {
            //Arrange
            var          command = new RejectDocumentCommand("Reject");
            const string error   = "testError";

            _documentsController = new DocumentsController(TestHelper.ReadEventsFuncWithError(error), TestHelper.SaveAndPublish,
                                                           DocumentExistsByNumber, TestHelper.GetDocumentById(), TestHelper.GetCurrentUserId());

            //Act
            var result = await _documentsController.RejectDocument(Guid.Empty, command);

            //Assert
            var badRequestResult = result as BadRequestObjectResult;

            Assert.NotNull(badRequestResult);
            Assert.NotNull(badRequestResult.Value);
        }
Beispiel #4
0
        public async Task TestRejectDocumentInvalidCommandBadRequestResult()
        {
            //Arrange
            var command            = new RejectDocumentCommand(string.Empty);
            var documentCreatedDto =
                new DocumentCreatedEventDto(Guid.Empty, DateTime.UtcNow, Guid.Empty, "1234", string.Empty);
            var readEventsFunc = TestHelper.ValidReadEventsFunc(documentCreatedDto.ToEvent());

            _documentsController = new DocumentsController(readEventsFunc, TestHelper.SaveAndPublish,
                                                           DocumentExistsByNumber, TestHelper.GetDocumentById(), TestHelper.GetCurrentUserId());

            //Act
            var result = await _documentsController.RejectDocument(Guid.Empty, command);

            //Assert
            var badRequestResult = result as BadRequestObjectResult;

            Assert.NotNull(badRequestResult);
            Assert.NotNull(badRequestResult.Value);
        }
Beispiel #5
0
        public async Task TestRejectDocumentNoContentResult()
        {
            //Arrange
            var documentCreatedDto =
                new DocumentCreatedEventDto(Guid.Empty, DateTime.UtcNow, Guid.Empty, "1234", string.Empty);
            var fileAddedDto = new FileAddedEventDto(Guid.Empty, DateTime.UtcNow, Guid.Empty, "test", string.Empty);
            var documentSentToApprovalDto = new DocumentSentForApprovalEventDto(Guid.Empty, DateTime.UtcNow);

            var readEventsFunc = TestHelper.ValidReadEventsFunc(documentCreatedDto.ToEvent(), fileAddedDto.ToEvent(), documentSentToApprovalDto.ToEvent());

            var command = new RejectDocumentCommand("Bad document");

            _documentsController = new DocumentsController(readEventsFunc, TestHelper.SaveAndPublish,
                                                           DocumentExistsByNumber, TestHelper.GetDocumentById(), TestHelper.GetCurrentUserId());

            //Act
            var result = await _documentsController.RejectDocument(Guid.Empty, command);

            //Assert
            var noContentResult = result as NoContentResult;

            Assert.NotNull(noContentResult);
        }
        public async Task RejectDocumentTest()
        {
            // Arrange
            var createDocumentCommand = new CreateDocumentCommand(DateTime.UtcNow.Ticks.ToString(), "Test document");
            var addFileCommand        = new AddFileCommand("Test", "Test file");
            var rejectDocumentCommand = new RejectDocumentCommand("Rejected");

            // Act
            var documentUri = await _client.CreateDocumentAsync(createDocumentCommand);

            await _client.AddFileAsync(documentUri, addFileCommand);

            await _client.SendDocumentForApprovalAsync(documentUri);

            await _client.RejectDocument(documentUri, rejectDocumentCommand);

            var document = await _client.GetAsync <Document>(documentUri);

            // Assert
            Assert.NotNull(document);
            Assert.Equal(DocumentStatus.Rejected.ToString(), document.Status);
            Assert.Equal(rejectDocumentCommand.Reason, document.RejectReason);
        }