コード例 #1
0
        public async Task <ActionResult> Connect(int vehicleId)
        {
            var vehicleModel = await _vehicleService.GetAsync(vehicleId);

            if (vehicleModel == null)
            {
                return(NotFound(new ErrorDto($"Vehicle by id '{vehicleId}' not found.")));
            }

            await _vehicleService.ConnectedAsync(vehicleModel);

            return(Ok());
        }
        public async Task ConnectedAsync_ForOldConnection_ShouldUpdateConnectedDate()
        {
            var now = new DateTime(2019, 5, 6, 12, 34, 56);

            _dateTimeService.Setup(m => m.Now).Returns(now);

            var originalVehicle = new VehicleModel
            {
                Id                 = VEHICLE1_ID,
                VehicleId          = VEHICLE1_VEHICLEID,
                RegistrationNumber = VEHICLE1_REGNUMBER,
                Customer           = new CustomerModel
                {
                    Id       = CUSTOMER1_ID,
                    FullName = CUSTOMER1_FULLNAME,
                    Address  = CUSTOMER1_ADDRESS
                }
            };

            using (var context = new ApplicationDbContext(_options))
            {
                context.Vehicles.Add(originalVehicle);
                context.SaveChanges();
            }

            await _service.ConnectedAsync(originalVehicle);

            using (var context = new ApplicationDbContext(_options))
            {
                var vehicle = context.Vehicles.Find(VEHICLE1_ID);

                Assert.Equal(VEHICLE1_ID, vehicle.Id);
                Assert.Equal(VEHICLE1_VEHICLEID, vehicle.VehicleId);
                Assert.Equal(VEHICLE1_REGNUMBER, vehicle.RegistrationNumber);
                Assert.Equal(CUSTOMER1_ID, vehicle.CustomerId);
                Assert.Equal(now, vehicle.ConnectUpdated);
            }
        }