コード例 #1
0
        public async void CreateOrder()
        {
            var suite = new OrderServiceTestSuite();

            var time       = DateTime.MinValue;
            var customerId = 2;
            var cargoId    = 3;
            var routeId    = 4;
            var billId     = 5;

            suite.CustomerServiceMock
            .Setup(m => m.IsExist(customerId))
            .ReturnsAsync(true);
            suite.CargoServiceMock
            .Setup(m => m.IsExist(cargoId))
            .ReturnsAsync(true);
            suite.RouteServiceMock
            .Setup(m => m.IsExist(routeId))
            .ReturnsAsync(true);
            suite.BillServiceMock
            .Setup(m => m.IsExist(billId))
            .ReturnsAsync(true);

            var newOrder = await suite.OrderService.Create(time, customerId, cargoId, routeId, billId);

            suite.OrderRepositoryMock
            .Verify(m => m.Add(It.Is <Order>(
                                   o => o.Time.Equals(time) &&
                                   o.CustomerId.Equals(customerId) &&
                                   o.CargoId.Equals(cargoId) &&
                                   o.RouteId.Equals(routeId) &&
                                   o.BillId.Equals(billId))));
        }
コード例 #2
0
        public async void AssignDriverrWhenOrderDoesNotExist()
        {
            var suite    = new OrderServiceTestSuite();
            var driverId = 1;

            suite.OrderRepositoryMock
            .Setup(m => m.Get(It.IsAny <int>()))
            .Returns(Task.FromResult <Order>(null));
            suite.DriverServiceMock
            .Setup(m => m.IsExist(driverId))
            .ReturnsAsync(true);

            await Assert.ThrowsAsync <EntityNotFoundException>("Order", () => suite.OrderService.AssignDriver(2, driverId));
        }
コード例 #3
0
        public async void AssignDriverWhenDriverDoesNotExist()
        {
            var suite = new OrderServiceTestSuite();
            var order = new Order {
                Id = 1
            };

            suite.OrderRepositoryMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.DriverServiceMock
            .Setup(m => m.IsExist(It.IsAny <int>()))
            .ReturnsAsync(false);

            await Assert.ThrowsAsync <EntityNotFoundException>("Driver", () => suite.OrderService.AssignDriver(order.Id, 2));
        }
コード例 #4
0
        public async void AssignDriver()
        {
            var suite = new OrderServiceTestSuite();

            var commonId = 1;
            var order    = new Order {
                Id = commonId++
            };
            var driverId = commonId++;

            suite.OrderRepositoryMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.DriverServiceMock
            .Setup(m => m.IsExist(driverId))
            .ReturnsAsync(true);

            await suite.OrderService.AssignDriver(order.Id, driverId);

            Assert.Equal(driverId, order.DriverId);
        }