Exemplo n.º 1
0
        public GetCarListQueryTests()
        {
            _carList = new List <Car>()
            {
                new Car()
                {
                    Make = "Test Make", Model = "Test Model"
                },
                new Car()
                {
                    Make = "Test Make", Model = "Test Model"
                }
            };

            _uow = new Mock <IUnitOfWork>();
            _uow.Setup(c => c.Cars.GetAll()).Returns(_carList.AsQueryable());

            _subject = new GetCarListQuery(_uow.Object);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <CarDetail> > Handle(GetCarListQuery request, CancellationToken cancellationToken)
        {
            var resource = await CarRepository.GetAllAsync();

            if (resource == null)
            {
                throw new KeyNotFoundException("Record not found.");
            }

            return(resource.Select(x => new CarDetail()
            {
                Id = x.Id,
                Make = x.Make,
                Model = x.Model,
                Price = x.Price,
                Engine = x.Engine,
                Doors = x.Doors,
                Wheels = x.Wheels,
                BodyType = x.BodyType.BodyTypeName,
                VehicleType = x.VehicleType.VehicleTypeName
            }));
        }