예제 #1
0
        public async Task ExecuteAsync()
        {
            WriteLine();
            WriteLine("Insira os dados do novo Caminhão...");

            var chassis = ReadChassis();
            var color   = await SelectColor(getColorOptions);

            var model           = ReadModel();
            var modelYear       = ReadModelYear();
            var manufactureYear = ReadManufactureYear();

            var Truck = new Infra.Database.Entities.Truck {
                Chassis         = chassis,
                ModelYear       = (int)modelYear,
                ManufactureYear = (int)manufactureYear,
                Model           = model,
                ColorId         = color.Id,
            };

            var command = new InsertTruck(Truck);
            var result  = await insertTruck.ExecuteAsync(command);

            if (!result.IsSuccess)
            {
                WriteLine($"Não foi possível criar o registro: {result.Message}");
                return;
            }

            WriteLine("Seu Caminhão foi criado com sucesso!");
        }
예제 #2
0
        public async Task Command_DuplicateKey_ShouldFail()
        {
            var context = GetInMemoryEmptyContext();
            var Truck   = new Truck.Infra.Database.Entities.Truck {
                Chassis = "TEST1",
                ColorId = 1,
                Model   = TruckModel.FM,
            };
            var command = new InsertTruck(Truck);
            var insert  = new InsertTruckCommand(context);

            await insert.ExecuteAsync(command);

            var commandResult = await insert.ExecuteAsync(command);

            Assert.IsFalse(commandResult.IsSuccess);
        }
예제 #3
0
        public async Task Command_Execute_ShouldInsert()
        {
            var context = GetInMemoryEmptyContext();
            var Truck   = new Truck.Infra.Database.Entities.Truck {
                Chassis = "TESTE2",
                ColorId = 1,
                Model   = TruckModel.FM
            };
            var command       = new InsertTruck(Truck);
            var insert        = new InsertTruckCommand(context);
            var commandResult = await insert.ExecuteAsync(command);

            Assert.IsTrue(commandResult.IsSuccess);
            var insertedTruck = context.Truck.Last();

            Assert.AreEqual(Truck.Chassis, insertedTruck.Chassis);
        }