コード例 #1
0
        public async Task ReturnAllParkingLots_When_GetIsCalled()
        {
            // Arrange
            var parkingLot  = new ParkingLot();
            var parkingLots = new List <ParkingLot> {
                parkingLot
            };

            _mock.Setup(r => r.GetAllAsync()).Returns(Task.FromResult(parkingLots));
            var controller = new ParkingLotController(_mock.Object);

            // Act
            var actionResult = await controller.Get();

            if (actionResult is OkObjectResult viewResult)
            {
                var actualParkingLots = viewResult.Value as ParkingLot;

                // Assert
                Assert.AreEqual(parkingLots, actualParkingLots);
            }
        }
コード例 #2
0
        public async Task ReturnParkingLot_When_GetIsCalledWithId()
        {
            // Arrange
            var parkingLot = new ParkingLot
            {
                ParkingLotId = 2
            };

            _mock.Setup(r => r.GetByIdAsync(parkingLot.ParkingLotId)).Returns(Task.FromResult(parkingLot));
            var controller = new ParkingLotController(_mock.Object);

            // Act
            var actionResult = await controller.Get(parkingLot.ParkingLotId);

            if (actionResult is OkObjectResult viewResult)
            {
                var actualParkingLot = viewResult.Value as ParkingLot;

                // Assert
                Assert.AreEqual(actualParkingLot, parkingLot);
            }
        }