示例#1
0
        public async void AddVehicle_NotFoundWhenLocationNotFound()
        {
            // arrange
            var location = context.Locations.First();
            var vehicle  = location.Vehicles.First();

            ICommandFactory <Location> commandFactory = new CommandFactory <Location>();
            var validationServiceMoq = new Mock <IValidationService>();

            var vehicleServiceMoq = new Mock <IVehicleService>();

            vehicleServiceMoq.Setup(x => x.GetByLocationId(It.IsAny <Guid>()))
            .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.NotFound));

            var sut = new LocationService(context, commandFactory, vehicleServiceMoq.Object, validationServiceMoq.Object);

            location.Vehicles.Remove(vehicle);
            await context.SaveChangesAsync();

            // act
            var result = await sut.AddVehicle(Guid.NewGuid(), vehicle);

            // assert
            Assert.Equal(ResultCode.NotFound, result.ResultCode);
        }
示例#2
0
        public async void AddVehicle_NewSucceeds()
        {
            // arrange
            var location = context.Locations.First();
            var vehicle  = context.Vehicles.FirstOrDefault(x => x.LocationId == location.Id);

            vehicle.LocationId = Guid.Empty;
            context.SaveChanges();
            var vehicles = context.Vehicles.Where(x => x.LocationId == location.Id && x.Id != vehicle.Id);

            ICommandFactory <Location> commandFactory = new CommandFactory <Location>();
            var validationServiceMoq = new Mock <IValidationService>();

            var vehicleServiceMoq = new Mock <IVehicleService>();

            vehicleServiceMoq.Setup(x => x.GetByLocationId(It.IsAny <Guid>()))
            .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.Success, vehicles));
            vehicleServiceMoq.Setup(x => x.Get(It.IsAny <Guid>()))
            .ReturnsAsync(() => new Result <Vehicle>(ResultCode.Success, vehicle));
            vehicleServiceMoq.Setup(x => x.Insert(It.IsAny <Vehicle>()))
            .ReturnsAsync(() => new Result <Guid>(ResultCode.Success, vehicle.Id));

            var sut = new LocationService(context, commandFactory, vehicleServiceMoq.Object, validationServiceMoq.Object);

            location.Vehicles.Remove(vehicle);
            await context.SaveChangesAsync();

            // act
            var result = await sut.AddVehicle(location.Id, vehicle);

            // assert
            Assert.Equal(ResultCode.Success, result.ResultCode);
        }
示例#3
0
        public async void AddVehicle_ConflictWhenDuplicate()
        {
            // arrange
            var location = context.Locations.First();
            var vehicle  = location.Vehicles.First();

            ICommandFactory <Location> commandFactory = new CommandFactory <Location>();
            var validationServiceMoq = new Mock <IValidationService>();

            var vehicleServiceMoq = new Mock <IVehicleService>();

            vehicleServiceMoq.Setup(x => x.GetByLocationId(It.IsAny <Guid>()))
            .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.Success, new[] { vehicle }));

            var sut = new LocationService(context, commandFactory, vehicleServiceMoq.Object, validationServiceMoq.Object);

            // act
            var result = await sut.AddVehicle(location.Id, vehicle);

            // assert
            Assert.Equal(ResultCode.Conflict, result.ResultCode);
        }