public void GetEquipmentByIdReturnsAnEquipment()
        {
            int id = 0;

            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);
                Equipment e1 = new Equipment();
                e1.ProductName = "EQtest1";
                e1.EquipmentTypeId = 1;
                e1.EquipmentStateId = 1;
                e1.PurchaseDate = DateTime.Now;
                e1.PurchasePrice = 500;

                Equipment e2 = new Equipment();
                e2.ProductName = "EQtest2";
                e2.EquipmentTypeId = 2;
                e2.EquipmentStateId = 2;
                e2.PurchaseDate = DateTime.Now;
                e2.PurchasePrice = 600;

                context.Equipments.Add(e1);
                context.Equipments.Add(e2);
                uow.Save();
                id = e2.Id;
            }
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);
                uow.EquipmentRepository.GetEquipmentById(id).Should().NotBeNull();
                uow.EquipmentRepository.GetEquipmentById(id).ProductName.Should().Be("EQtest2");
                uow.EquipmentRepository.GetEquipmentById(0).Should().BeNull();
            }
        }
        public void GetEquipmentTypeByEquipmentIdReturnsRightEquipmentType()
        {
            int eqId;
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);

                Equipment e1 = new Equipment();
                e1.ProductName = "EQtest1";
                e1.EquipmentTypeId = 1;
                e1.EquipmentStateId = 1;
                e1.PurchaseDate = DateTime.Now;
                e1.PurchasePrice = 500;

                Equipment e2 = new Equipment();
                e2.ProductName = "EQtest2";
                e2.EquipmentTypeId = 2;
                e2.EquipmentStateId = 2;
                e2.PurchaseDate = DateTime.Now;
                e2.PurchasePrice = 600;

                context.Equipments.Add(e1);
                context.Equipments.Add(e2);
                uow.Save();

                eqId = e2.Id;
            }
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);
                var equipmentType = uow.TypesRepository.GetEquipmentTypeByEquipmentId(eqId);

                equipmentType.TypeName.Should().Be("Ski Boots");
            }
        }
        public RentalWindow(IRentalService rentalService, Equipment equipment)
        {
            RentalService = rentalService;

            InitializeComponent();

            ViewModel = DataContext as RentalWindowVM;
            ViewModel.Equipment = equipment;
        }
        public void CreateRentalShouldStoreRental()
        {
            int eqid;
            int rpid;

            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);

                Equipment e1 = new Equipment();
                e1.ProductName = "EQtest1";
                e1.EquipmentTypeId = 1;
                e1.EquipmentStateId = 1;
                e1.PurchaseDate = DateTime.Now;
                e1.PurchasePrice = 500;

                RentalPlan rp1 = new RentalPlan();
                rp1.Duration = 8;
                rp1.Discount = 0.25;

                context.Equipments.Add(e1);
                context.RentalPlans.Add(rp1);
                uow.Save();

                eqid = e1.Id;
                rpid = rp1.Id;

            }
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);

                Rental rental = new Rental();
                rental.CustomerName = "Johan Eriksson";
                rental.CustomerPhoneNumber = "0705556677";
                rental.StartTime = DateTime.Now;
                rental.EquipmentId = eqid;
                rental.RentalPlanId = rpid;

                uow.RentalRepository.CreateRental(rental);
                uow.Save();
            }

            using (var context = new SkiRentalContext())
            {
                context.Rentals.Should().NotBeNullOrEmpty();
                context.Rentals.Where(r => r.CustomerName == "Johan Eriksson").Should().HaveCount(1);
            }
        }
Esempio n. 5
0
        public List<Equipment> CreateEquipmentList()
        {
            Equipment e1 = new Equipment();
            e1.ProductName = "EqTest1";
            e1.PurchaseDate = DateTime.Now;
            e1.PurchasePrice = 50;
            e1.EquipmentType = new EquipmentType { TypeName = "SkiBoots", PricePerHour = 50 };
            e1.EquipmentState = new EquipmentState { Description = "Ugly" };

            Equipment e2 = new Equipment();
            e2.ProductName = "EqTest2";
            e2.PurchaseDate = DateTime.Now;
            e2.PurchasePrice = 500;
            e2.EquipmentType = new EquipmentType { TypeName = "Skis", PricePerHour = 500 };
            e2.EquipmentState = new EquipmentState { Description = "Damaged" };

            var testData = new List<Equipment>();
            testData.Add(e1);
            testData.Add(e2);

            return testData;
        }
        public void GetAllEquipmentsReturnsNotNull()
        {
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);

                Equipment e1 = new Equipment();
                e1.ProductName = "EQtest1";
                e1.EquipmentTypeId = 1;
                e1.EquipmentStateId = 1;
                e1.PurchaseDate = DateTime.Now;
                e1.PurchasePrice = 500;

                context.Equipments.Add(e1);
                uow.Save();

            }
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);
                uow.EquipmentRepository.GetAllEquipments().Should().NotBeNull();
            }
        }
Esempio n. 7
0
 public async Task<double> GetRentalPriceAsync(RentalPlan plan, Equipment equipment)
 {
     var price = await restService.GetAsync<double>("api/prices?planId=" + plan.Id + "&equipmentId=" + equipment.Id);
     return price;
 }
        public void GetEquipmentsByRentalStateReturnsEquipmentsWithCorrectRentalState()
        {
            int availableId;
            int rentedId;
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);
                Equipment e1 = new Equipment();
                e1.ProductName = "EQtest1";
                e1.EquipmentTypeId = 1;
                e1.EquipmentStateId = 1;
                e1.PurchaseDate = DateTime.Now;
                e1.PurchasePrice = 500;

                Equipment e2 = new Equipment();
                e2.ProductName = "EQtest2";
                e2.EquipmentTypeId = 2;
                e2.EquipmentStateId = 2;
                e2.PurchaseDate = DateTime.Now;
                e2.PurchasePrice = 600;

                context.Equipments.Add(e1);
                context.Equipments.Add(e2);

                RentalPlan rp1 = new RentalPlan();
                rp1.Duration = 8;
                rp1.Discount = 0.25;

                context.RentalPlans.Add(rp1);

                Rental rental = new Rental();
                rental.CustomerName = "Johan Eriksson";
                rental.CustomerPhoneNumber = "0705556677";
                rental.StartTime = DateTime.Now;
                rental.Equipment = e1;
                rental.RentalPlan = rp1;

                uow.RentalRepository.CreateRental(rental);
                uow.Save();

                availableId = e2.Id;
                rentedId = e1.Id;
            }
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);

                var availableEq = uow.EquipmentRepository.GetEquipmentsByRentalState(false);
                var rentedEq = uow.EquipmentRepository.GetEquipmentsByRentalState(true);

                availableEq.Should().HaveCount(1);
                rentedEq.Should().HaveCount(1);

                availableEq[0].Id.Should().Be(availableId);
                rentedEq[0].Id.Should().Be(rentedId);
            }
        }
        private static List<Equipment> CreateEquipmentList()
        {
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);

                Equipment e1 = new Equipment();
                e1.ProductName = "EqTest1";
                e1.PurchaseDate = DateTime.Now;
                e1.PurchasePrice = 50;
                e1.EquipmentTypeId = 1;
                e1.EquipmentStateId = 2;

                Equipment e2 = new Equipment();
                e2.ProductName = "EqTest2";
                e2.PurchaseDate = DateTime.Now;
                e2.PurchasePrice = 500;
                e2.EquipmentTypeId = 2;
                e2.EquipmentStateId = 1;

                context.Equipments.Add(e1);
                context.Equipments.Add(e2);
                uow.Save();

                return context.Equipments.ToList();
            }
        }