예제 #1
0
        public async Task Should_return_BadRequest_given_invalid_vehicul_properties()
        {
            #region Arrange
            var request = HttpHelpers.CreateMockHttpRequest(new
            {
                vehiculId = Guid.NewGuid().ToString(),
                label     = "My Super Car",
                type      = "1"
            });

            _mediator.Setup(x => x.Send(It.IsAny <MediatR.IRequest <Unit> >(), CancellationToken.None))
            .Throws(new MicroserviceBarebone.Application.Exceptions.ValidationException(new System.Collections.Generic.List <FluentValidation.Results.ValidationFailure>()
            {
                new FluentValidation.Results.ValidationFailure("VehiculId", "Id must be a valid GUID"),
                new FluentValidation.Results.ValidationFailure("Label", "Label must be max 255")
            }));

            #endregion

            #region Act
            var res = await VehiculsFunctions.RunPost(request.Object, _logger.Object);

            #endregion

            #region Assert
            Assert.IsType <BadRequestObjectResult>(res);
            Assert.Equal("Id must be a valid GUID", ((Dictionary <string, string[]>)((BadRequestObjectResult)res).Value)["VehiculId"][0]);
            Assert.Equal("Label must be max 255", ((Dictionary <string, string[]>)((BadRequestObjectResult)res).Value)["Label"][0]);
            #endregion
        }
예제 #2
0
        public async Task Should_return_OkResult_given_valid_vehicul()
        {
            #region Arrange
            bool commandSended = false;

            var request = HttpHelpers.CreateMockHttpRequest(new
            {
                vehiculId = Guid.NewGuid().ToString(),
                label     = "My Super Car",
                type      = "1"
            });

            _mediator.Setup(x => x.Send(It.IsAny <MediatR.IRequest <Unit> >(), CancellationToken.None))
            .Callback <MediatR.IRequest <Unit>, CancellationToken>((x, y) =>
            {
                commandSended = true;
            })
            .Returns(Unit.Task);
            #endregion

            #region Act
            var res = await VehiculsFunctions.RunPost(request.Object, _logger.Object);

            #endregion

            #region Assert
            Assert.True(commandSended);
            Assert.IsType <OkObjectResult>(res);
            Assert.Equal("Vehicul created.", ((OkObjectResult)res).Value);
            #endregion
        }