Пример #1
0
        public async void AddTrip()
        {
            if (!String.IsNullOrEmpty(Destination))
            {
                await _tripRepository.Add(new Trip(Destination, DepartureDate, ReturnDate, 0));

                NavigateToListOverview();
            }
        }
        public async Task <IActionResult> CreateTrip(Trip trip)
        {
            trip.User = await _userManager.GetUserAsync(User);

            var created = await _tripRepository.Add(trip);

            return(created != null
                ? CreatedAtAction("GetById", new { id = created.Id }, created)
                : BadRequest());
        }
        public async void ShouldAddComplaint()
        {
            //Given
            var now = DateTime.Now;

            var calendar = await CalendarRepository.Add(Calendars[0].Date);

            await CompanyRepository.Add(Companies[0], true);

            await TripRepository.Add(Trips[0]);

            await VehicleRepository.Add(Vehicles[0], true);

            var status = await StatusRepository.Add(new Status { Name = "Open" }, true);

            var location = new Point(new Coordinate(-122.3456, 45.67890));

            var complaintDTO = new ComplaintDTO
            {
                SubmittedDate    = Calendars[0].Date + now.TimeOfDay,
                Location         = location.ToGeoJson <GeoJSON.Net.Geometry.Point>(),
                CompanyName      = Companies[0].Name,
                VehicleName      = Vehicles[0].Name,
                VehicleTypeKey   = 1,
                ComplaintTypeKey = 8,
                ComplaintDetails = "Vehicle component issue",
                Complaints       = new string[] { }
            };

            //When
            var result = await Controller.PostAsync(complaintDTO);

            var dbCollision = await ComplaintRepository.Find(1);

            //Then
            var viewResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsType <ComplaintDTO>(viewResult.Value);

            Assert.NotNull(model);
            Assert.Equal(complaintDTO.SubmittedDate, model.SubmittedDate);
            Assert.True(dbCollision.FirstSeen == dbCollision.LastSeen);
        }
        public async void ShouldAddCollision()
        {
            //Given
            var now = DateTime.Now;

            var calendar = await CalendarRepository.Add(Calendars[0].Date);

            await CompanyRepository.Add(Companies[0], true);

            await TripRepository.Add(Trips[0]);

            await VehicleRepository.Add(Vehicles[0], true);

            var status = await StatusRepository.Add(new Status { Name = "Open" }, true);

            var location = new Point(new Coordinate(-122.3456, 45.67890));

            var collisionDTO = new CollisionDTO
            {
                Date                = Calendars[0].Date + now.TimeOfDay,
                Location            = location.ToGeoJson <GeoJSON.Net.Geometry.Point>(),
                CompanyName         = Companies[0].Name,
                VehicleName         = Vehicles[0].Name,
                TripAlternateKey    = Trips[0].AlternateKey,
                VehicleTypeKey      = 4,
                OtherVehicleTypeKey = 1,
                ClaimStatusKey      = Convert.ToByte(status.Key)
            };

            //When
            var result = await Controller.PostAsync(collisionDTO);

            var dbCollision = await CollisionRepository.Find(1);

            //Then
            var viewResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsType <CollisionDTO>(viewResult.Value);

            Assert.NotNull(model);
            Assert.Equal(collisionDTO.Date, model.Date);
            Assert.True(dbCollision.FirstSeen == dbCollision.LastSeen);
        }
Пример #5
0
        public void AddTrip(TripDTO tripdto, string username)
        {
            var user = _repo.GetUserByUserName(username);

            var trip = new Trip
            {
                Car = new Car
                {
                    Model        = tripdto.Car.Model,
                    SeatCapacity = tripdto.Car.SeatCapacity
                },
                DatePosted   = System.DateTime.Now,
                StartAddress = tripdto.StartAddress,
                EndAddress   = tripdto.EndAddress,
                Cost         = tripdto.Cost
            };

            _repo.Add(trip);
            _repo.SaveChanges();
            _repo.AddUserTrip(new UserTrip {
                UserId = user.Id, TripId = trip.Id
            });
            _repo.SaveChanges();
        }
        public async void ShouldUpdateSameTrip()
        {
            //Given
            var now         = DateTime.Now;
            var companyName = "New One";

            var calendar = await CalendarRepository.Add(now);

            var company = await CompanyRepository.Add(new Company { Name = companyName }, true);

            var vehicle = await VehicleRepository.Add(new Vehicle { Name = "Vehicle" }, true);

            var vehicleType = await VehicleTypeRepository.Add(new VehicleType { Name = "VehicleType" }, true);

            var neighborhood = await NeighborhoodRepository.Add(new Neighborhood { Name = "Neighborhood" }, true);

            var patternArea = await PatternAreaRepository.Add(new PatternArea { Name = "Pattern Area" }, true);

            var paymentType = await PaymentTypeRepository.Add(new PaymentType { Name = "Payment" }, true);

            var dbTrip = new Trip
            {
                Key                  = 1,
                StartDateKey         = calendar.Key,
                StartTime            = now.TimeOfDay,
                EndDateKey           = calendar.Key,
                EndTime              = now.TimeOfDay.Add(TimeSpan.FromHours(1)),
                CompanyKey           = company.Key,
                VehicleKey           = vehicle.Key,
                VehicleTypeKey       = vehicleType.Key,
                NeighborhoodStartKey = neighborhood.Key,
                NeighborhoodEndKey   = neighborhood.Key,
                PatternAreaStartKey  = patternArea.Key,
                PatternAreaEndKey    = patternArea.Key,
                PaymentTypeKey       = paymentType.Key,
                PaymentAccessKey     = paymentType.Key
            };

            await TripRepository.Add(dbTrip);

            var count = await TripRepository.Count();

            var controller = new TripController(
                new Mock <ILogger <TripController> >().Object,
                TripRepository,
                CalendarRepository,
                CompanyRepository,
                VehicleRepository
                );

            var tripDTO = new TripDTO
            {
                StartTime            = now,
                EndTime              = now.AddHours(2),
                CompanyName          = companyName,
                VehicleName          = vehicle.Name,
                VehicleTypeKey       = Convert.ToByte(vehicleType.Key),
                NeighborhoodStartKey = neighborhood.Key,
                NeighborhoodEndKey   = neighborhood.Key,
                PatternAreaStartKey  = patternArea.Key,
                PatternAreaEndKey    = patternArea.Key,
                PaymentTypeKey       = Convert.ToByte(paymentType.Key),
                PaymentAccessKey     = Convert.ToByte(paymentType.Key)
            };
            //When
            var result = await controller.PostAsync(tripDTO);

            dbTrip = await TripRepository.Find(1);

            //Then
            var viewResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsType <TripDTO>(viewResult.Value);

            Assert.Equal(count, await TripRepository.Count());
            Assert.NotNull(model);
            Assert.Equal(dbTrip.Key, model.Key);
            Assert.Equal(tripDTO.EndTime.TimeOfDay, dbTrip.EndTime);
        }