コード例 #1
0
        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");
            }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 public UnitOfWork(SkiRentalContext context)
 {
     this.SkiRentalContext = context;
     EquipmentRepository = new EquipmentRepository(context);
     RentalRepository = new RentalRepository(context);
     PlansRepository = new PlansRepository(context);
     TypesRepository = new TypesRepository(context);
     EquipmentStatesRepository = new EquipmentStatesRepository(context);
 }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        public void GetAllRentalsShouldNotBeEmpty()
        {
            using (var context = new SkiRentalContext())
            {
                var uow = new UnitOfWork(context);
                var eqList = CreateEquipmentList();

                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.EquipmentId = eqList[0].Id;
                rental.RentalPlanId = rp1.Id;

                Rental rental2 = new Rental();
                rental2.CustomerName = "Anna Nilsson";
                rental2.CustomerPhoneNumber = "0738887766";
                rental2.StartTime = DateTime.Now;
                rental2.EquipmentId = eqList[1].Id;
                rental2.RentalPlanId = rp1.Id;

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

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

                var rentals = uow.RentalRepository.GetAllRentals();

                rentals.Should().NotBeEmpty();
            }
        }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
 public TypesRepository(SkiRentalContext context)
 {
     this.context = context;
 }
コード例 #9
0
 public EquipmentRepository(SkiRentalContext context)
 {
     this.context = context;
 }
コード例 #10
0
        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();
            }
        }