public void WhenAddingFillup_ThenDelegatesToFillupRepository()
        {
            _vehicleRepo
                .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
                .Returns(_vehicle);

            var fillupForm = new FillupEntryFormModel();

            var handler = new AddFillupToVehicle(_vehicleRepo.Object, _fillupRepositoryMock.Object);
            handler.Execute(DefaultUserId, DefaultVehicleId, fillupForm);

            _fillupRepositoryMock
                .Verify(r => r.Create(DefaultUserId, DefaultVehicleId, It.IsAny<FillupEntry>()),
                Times.Once());
        }
Пример #2
0
        public void WhenAddingFillupAndFillupRepositoryThrows_ThenWrapsException()
        {
            _vehicleRepo
                .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
                .Returns(_vehicle);

            _fillupRepositoryMock
                .Setup(f => f.Create(DefaultUserId,DefaultVehicleId, It.IsAny<FillupEntry>()))
                .Throws<InvalidOperationException>();

            var handler = new AddFillupToVehicle(_vehicleRepo.Object, _fillupRepositoryMock.Object);
            var ex = Assert
                .Throws<BusinessServicesException>(() => handler.Execute(DefaultUserId, DefaultVehicleId, new FillupEntryFormModel()));
            Assert.IsType<InvalidOperationException>(ex.InnerException);
        }
        public void WhenAddingFillupOnSameDate_ThenCalculatesDistance()
        {
            _vehicleRepo
                .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
                .Returns(_vehicle);

            var fillups = new[]
                              {
                                  new FillupEntry{FillupEntryId = 1, Date = new DateTime(2011, 3, 25), Odometer = 500},
                                  new FillupEntry{FillupEntryId = 2, Date = new DateTime(2011, 3, 25), Odometer = 750}
                              };

            var fillupForm = new FillupEntryFormModel
            {
                FillupEntryId = 3,
                Date = new DateTime(2011, 3, 25),
                Odometer = 1000
            };

            _fillupRepositoryMock
                 .Setup(x => x.GetFillups(DefaultVehicleId))
                 .Returns(fillups);

            var handler = new AddFillupToVehicle(_vehicleRepo.Object, _fillupRepositoryMock.Object);
            handler.Execute(DefaultUserId, DefaultVehicleId, fillupForm);

            Assert.Equal(250, fillupForm.Distance);
        }
        public void WhenAddingFirstFillup_ThenDoesNotCalculatesDistance()
        {
            _vehicleRepo
                .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
                .Returns(_vehicle);

            var fillups = new FillupEntry[] {};

            var fillupForm = new FillupEntryFormModel { FillupEntryId = 3, Date = new DateTime(2011, 3, 25), Odometer = 1000 };

            _fillupRepositoryMock
                 .Setup(x => x.GetFillups(DefaultVehicleId))
                 .Returns(fillups);

            var handler = new AddFillupToVehicle(_vehicleRepo.Object, _fillupRepositoryMock.Object);
            handler.Execute(DefaultUserId, DefaultVehicleId, fillupForm);

            Assert.Null(fillupForm.Distance);
        }
        public void WhenAddingFillupAndVehicleRepositoryThrows_ThenWrapsException()
        {
            _vehicleRepo
                .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
                .Throws<InvalidOperationException>();

            var handler = new AddFillupToVehicle(_vehicleRepo.Object, _fillupRepositoryMock.Object);

            var ex = Assert
                .Throws<UnauthorizedException>(() => handler.Execute(DefaultUserId, DefaultVehicleId, new FillupEntryFormModel()));
            Assert.IsType<InvalidOperationException>(ex.InnerException);
        }
        public void WhenAddingFillup_UsesLocationIfVendorNull()
        {
            _vehicleRepo
                .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
                .Returns(_vehicle);

            var fillupForm = new FillupEntryFormModel
                                 {
                                     Vendor = null,
                                     Location = "testlocation",
                                     PricePerUnit = 0,
                                     TotalUnits = 0,
                                     TransactionFee = 0
                                 };

            var handler = new AddFillupToVehicle(_vehicleRepo.Object, _fillupRepositoryMock.Object);
            handler.Execute(DefaultUserId, DefaultVehicleId, fillupForm);

            _fillupRepositoryMock
                .Verify(r => r.Create(DefaultUserId, DefaultVehicleId, It.Is<FillupEntry>(f=>f.Vendor=="testlocation")));
        }