コード例 #1
0
ファイル: VehicleTest.cs プロジェクト: nikonik721/ProjectCars
        public async Task Vehicle_GetAll_Count_Check()
        {
            //setup
            var expectedCount = 2;

            _vehicleRepository.Setup(x => x.GetAll())
            .ReturnsAsync(_vehicle);

            //Act
            var result = await _controller.GetAll();

            //Assert
            var okObjectResult = result as OkObjectResult;

            Assert.NotNull(okObjectResult);

            var positions = okObjectResult.Value as IEnumerable <VehicleResponse>;

            Assert.NotNull(positions);
            Assert.Equal(expectedCount, positions.Count());
        }
コード例 #2
0
        public async void GetAll()
        {
            // Vehicles

            var vehicleServiceMock     = new Mock <IVehicleService>();
            var vehicleTypeServiceMock = new Mock <IVehicleTypeService>();

            string registration = "AA11AA";
            string vin          = "123456789AAAAAAAA";
            string entranceDate = "27/01/1978";
            string vehicleType  = "vehicleType1";


            var vehicle = new Vehicle(registration, vin, entranceDate, vehicleType);



            // DTO

            var vehicleDTO = new VehicleDTO(vehicle.Id.AsGuid(), registration, vin, entranceDate, vehicleType);

            var vehiclesDTO = new List <VehicleDTO>()
            {
                vehicleDTO
            };

            // Mocks

            vehicleServiceMock.Setup(_ => _.GetAll()).ReturnsAsync(vehiclesDTO);


            var controller = new VehicleController(vehicleServiceMock.Object, vehicleTypeServiceMock.Object);


            var actual = await controller.GetAll();

            Assert.Equal(vehiclesDTO, actual.Value);
        }