public async Task TruckHandler_Update_invalid_update_error()
        {
            var mockContextRepository = new Mock <IContextRepository>();
            var mockTruckRepository   = new Mock <ITruckRepository>();

            TruckUpdateCommand trunlUpdateCommand = new TruckUpdateCommand();

            trunlUpdateCommand.Id          = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9";
            trunlUpdateCommand.Color       = "Blue";
            trunlUpdateCommand.Image       = "img.jpg";
            trunlUpdateCommand.Description = "desciption";
            trunlUpdateCommand.Model       = 1;
            trunlUpdateCommand.ModelYear   = DateTime.Now.Year;

            Truck _truck = new Truck();

            _truck.Id          = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9";
            _truck.Color       = "Red";
            _truck.Image       = "img1.jpg";
            _truck.Description = "desciption";
            _truck.Model       = EnumModel.FH;
            _truck.ModelYear   = DateTime.Now.Year;

            mockTruckRepository.Setup(x => x.GetById(It.IsAny <string>())).ReturnsAsync(_truck);
            mockContextRepository.Setup(x => x.Update(It.IsAny <Truck>())).ReturnsAsync(false);

            TruckHandler _handler = new TruckHandler(mockContextRepository.Object, mockTruckRepository.Object);

            var _return = await _handler.Handle(trunlUpdateCommand);

            Assert.False(_return.Success);
            Assert.Equal(HttpStatusCode.BadRequest, _return.Code);
            Assert.False((bool)_return.Data);
        }
Esempio n. 2
0
        public async Task <ICommandResult> Handle(TruckUpdateCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, HttpStatusCode.BadRequest, command.Notifications));
            }

            var _verify = await _truckRepository.GetById(command.Id);

            if (_verify == null)
            {
                return(new GenericCommandResult(false, HttpStatusCode.NotFound, _verify));
            }

            Truck _entity = new Truck();

            _entity.Id          = command.Id;
            _entity.Description = command.Description;
            _entity.Color       = command.Color;
            _entity.Image       = command.Image;
            _entity.Model       = (EnumModel)command.Model;
            _entity.ModelYear   = command.ModelYear;

            var _result = await _contextRepository.Update(_entity);

            if (!_result)
            {
                return(new GenericCommandResult(false, HttpStatusCode.BadRequest, _result));
            }

            return(new GenericCommandResult(true, HttpStatusCode.OK, _result));
        }
Esempio n. 3
0
        public void TruckUpdateCommand_invalid_Description_null()
        {
            TruckUpdateCommand _command = new TruckUpdateCommand();

            _command.Id          = "5cae6e12-02a1-4e68-82ec-f34d3597c4cd";
            _command.Model       = 1;
            _command.Color       = "blue";
            _command.Image       = "img1.png";
            _command.ModelYear   = (DateTime.Now.Year);
            _command.Description = "";

            _command.Validate();
            var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications;

            Assert.False(_command.Valid);
            Assert.True(_command.Invalid);

            Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 1);
            Assert.Equal("Description not be null.", _notification[0].Message);
        }
Esempio n. 4
0
        public void TruckUpdateCommand_invalid_ModelYear_diferent_current_and_after_year_down()
        {
            TruckUpdateCommand _command = new TruckUpdateCommand();

            _command.Id          = "5cae6e12-02a1-4e68-82ec-f34d3597c4cd";
            _command.Model       = 1;
            _command.Color       = "blue";
            _command.Image       = "img1.png";
            _command.ModelYear   = (DateTime.Now.Year - 2);
            _command.Description = "description";

            _command.Validate();
            var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications;

            Assert.False(_command.Valid);
            Assert.True(_command.Invalid);

            Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 1);
            Assert.Equal("The model year must be the current year or the year after.", _notification[0].Message);
        }
Esempio n. 5
0
        public void TruckUpdateCommand_invalid_Model_diferent_FH_FM()
        {
            TruckUpdateCommand _command = new TruckUpdateCommand();

            _command.Id          = "5cae6e12-02a1-4e68-82ec-f34d3597c4cd";
            _command.Model       = 3;
            _command.ModelYear   = DateTime.Now.Year;
            _command.Description = "description";

            _command.Validate();
            var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications;

            Assert.False(_command.Valid);
            Assert.True(_command.Invalid);

            Assert.Null(_command.Color);
            Assert.Null(_command.Image);

            Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 1);
            Assert.Equal("Model not valid.", _notification[0].Message);
        }
Esempio n. 6
0
        public void TruckUpdateCommand_valid()
        {
            TruckUpdateCommand _command = new TruckUpdateCommand();

            _command.Id          = "5cae6e12-02a1-4e68-82ec-f34d3597c4cd";
            _command.Model       = 1;
            _command.Color       = "blue";
            _command.Image       = "img1.png";
            _command.ModelYear   = DateTime.Now.Year;
            _command.Description = "description";

            _command.Validate();
            var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications;

            Assert.True(_command.Valid);
            Assert.False(_command.Invalid);

            Assert.NotEmpty(_command.Color);
            Assert.NotEmpty(_command.Image);
            Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 0);
        }
Esempio n. 7
0
        public void TruckUpdateCommand_invalid_Id_Null_or_empty(string param)
        {
            TruckUpdateCommand _command = new TruckUpdateCommand();

            _command.Id          = param;
            _command.Model       = 1;
            _command.ModelYear   = DateTime.Now.Year;
            _command.Description = "description";

            _command.Validate();
            var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications;

            Assert.False(_command.Valid);
            Assert.True(_command.Invalid);

            Assert.Null(_command.Color);
            Assert.Null(_command.Image);
            Assert.NotNull(_command.ModelYear);
            Assert.NotNull(_command.Model);

            Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 2);
            Assert.Equal("Id not be null.", _notification[0].Message);
            Assert.Equal("This Id is not a valid guid.", _notification[1].Message);
        }
 public async Task <GenericCommandResult> PutTruck(
     [FromBody] TruckUpdateCommand command,
     [FromServices] IHandler <TruckUpdateCommand> handler)
 {
     return((GenericCommandResult)await handler.Handle(command));
 }