public async Task <IActionResult> CreateProcedure([FromBody] CreateProcedureCommand command)
        {
            try
            {
                Procedure procedure = await this._mediator.Send(command);

                return(Ok(procedure));
            }
            catch (Exception ex)
            {
                this._logger.LogError(0, ex, ex.Message);
                return(BadRequest());
            }
        }
Beispiel #2
0
        public void CreateProcedure_ValidCommand_SendsCommandToMediator()
        {
            string    procedureName        = "Test Name";
            Procedure procedure            = new Procedure(procedureName);
            CreateProcedureCommand command = new CreateProcedureCommand {
                Name = procedureName
            };
            ProcedureController controller = new ProcedureController(
                this._mediatorMock.Object,
                this._loggerMock.Object,
                this._procedureQueriesMock.Object);

            this._mediatorMock.Setup(m => m.Send(command, default(CancellationToken))).Returns(Task.FromResult(procedure));

            controller.CreateProcedure(command).Wait();

            this._mediatorMock.Verify(m => m.Send(command, default(CancellationToken)), Times.Once());
        }
Beispiel #3
0
        public void CreateProcedure_ValidCommand_ReturnsOkWithCorrectProcedure()
        {
            string    procedureName        = "Test Name";
            Procedure procedure            = new Procedure(procedureName);
            CreateProcedureCommand command = new CreateProcedureCommand {
                Name = procedureName
            };
            ProcedureController controller = new ProcedureController(
                this._mediatorMock.Object,
                this._loggerMock.Object,
                this._procedureQueriesMock.Object);

            this._mediatorMock.Setup(m => m.Send(command, default(CancellationToken))).Returns(Task.FromResult(procedure));

            IActionResult result = controller.CreateProcedure(command).Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(procedure, ((OkObjectResult)result).Value);
        }