Пример #1
0
        public void CreateRentalWillCreateRentalObject()
        {
            //Arrange
            var testHelper = new TestHelper();
            var testData = testHelper.CreateEquipmentList();

            IRentalRepository rentalRepository = Substitute.For<IRentalRepository>();

            IUnitOfWork uow = Substitute.For<IUnitOfWork>();
            uow.RentalRepository.Returns(rentalRepository);

            RentalService rs = new RentalService(uow);

            Rental rental = new Rental();
            rental.CustomerName = "Johan Eriksson";
            rental.CustomerPhoneNumber = "0705556677";
            rental.StartTime = DateTime.Now;
            rental.EquipmentId = testData[0].Id;

            RentalPlan rp = new RentalPlan();
            rp.Id = 1;
            rp.Duration = 8;
            rp.Discount = 0;

            rental.RentalPlanId = rp.Id;

            //Act
            rs.CreateRental(rental);

            //Assert
            rentalRepository.Received().CreateRental(rental);
        }
Пример #2
0
        public void GetAllRentalsShouldContainTwoRentals()
        {
            //Arrange

            var testHelper = new TestHelper();
            var testData   = testHelper.CreateEquipmentList();

            RentalPlan rp = new RentalPlan();

            rp.Id       = 1;
            rp.Duration = 8;
            rp.Discount = 0;

            Rental rental = new Rental();

            rental.CustomerName        = "Johan Eriksson";
            rental.CustomerPhoneNumber = "0705556677";
            rental.StartTime           = DateTime.Now;
            rental.EquipmentId         = testData[0].Id;
            rental.RentalPlanId        = rp.Id;

            Rental rental2 = new Rental();

            rental2.CustomerName        = "Johan Eriksson";
            rental2.CustomerPhoneNumber = "0705556677";
            rental2.StartTime           = DateTime.Now;
            rental2.EquipmentId         = testData[1].Id;
            rental2.RentalPlanId        = rp.Id;

            IRentalRepository rentalRepository = Substitute.For <IRentalRepository>();

            rentalRepository.GetAllRentals().Returns(new List <Rental> {
                rental, rental2
            });

            IUnitOfWork uow = Substitute.For <IUnitOfWork>();

            uow.RentalRepository.Returns(rentalRepository);

            RentalService rs = new RentalService(uow);

            //Act
            var rentals = rs.GetAllRentals();

            //Assert
            rentals.Should().HaveCount(2);
        }
        public void WillReturnEquipmentList()
        {
            //Arrange
            var testHelper = new TestHelper();
            var testData = testHelper.CreateEquipmentList();

            IEquipmentRepository eqRepository = Substitute.For<IEquipmentRepository>();
            eqRepository.GetAllEquipments().Returns(testData);

            IUnitOfWork uow = Substitute.For<IUnitOfWork>();
            uow.EquipmentRepository.Returns(eqRepository);

            EquipmentService eService = new EquipmentService(uow);

            //Act
            var equipments = eService.GetAllEquipments();
            //Assert
            equipments.Should().NotBeNull();
        }
        public void WillReturnSecondEquipment()
        {
            //Arrange
            var testHelper = new TestHelper();
            var testData = testHelper.CreateEquipmentList();
            int id = testData[1].Id;

            IEquipmentRepository eqRepository = Substitute.For<IEquipmentRepository>();
            eqRepository.GetEquipmentById(id).Returns(testData[1]);

            IUnitOfWork uow = Substitute.For<IUnitOfWork>();
            uow.EquipmentRepository.Returns(eqRepository);

            EquipmentService eService = new EquipmentService(uow);

            //Act
            var equipmentTaken = eService.GetEquipmentById(id);

            //Assert
            equipmentTaken.ProductName.Should().Be("EqTest2");
        }
Пример #5
0
        public void GetAllRentalsShouldContainTwoRentals()
        {
            //Arrange

            var testHelper = new TestHelper();
            var testData = testHelper.CreateEquipmentList();

            RentalPlan rp = new RentalPlan();
            rp.Id = 1;
            rp.Duration = 8;
            rp.Discount = 0;

            Rental rental = new Rental();
            rental.CustomerName = "Johan Eriksson";
            rental.CustomerPhoneNumber = "0705556677";
            rental.StartTime = DateTime.Now;
            rental.EquipmentId = testData[0].Id;
            rental.RentalPlanId = rp.Id;

            Rental rental2 = new Rental();
            rental2.CustomerName = "Johan Eriksson";
            rental2.CustomerPhoneNumber = "0705556677";
            rental2.StartTime = DateTime.Now;
            rental2.EquipmentId = testData[1].Id;
            rental2.RentalPlanId = rp.Id;

            IRentalRepository rentalRepository = Substitute.For<IRentalRepository>();
            rentalRepository.GetAllRentals().Returns(new List<Rental> { rental, rental2});

            IUnitOfWork uow = Substitute.For<IUnitOfWork>();
            uow.RentalRepository.Returns(rentalRepository);

            RentalService rs = new RentalService(uow);

            //Act
            var rentals = rs.GetAllRentals();

            //Assert
            rentals.Should().HaveCount(2);
        }
        public void WillReturnEquipmentList()
        {
            //Arrange
            var testHelper = new TestHelper();
            var testData   = testHelper.CreateEquipmentList();

            IEquipmentRepository eqRepository = Substitute.For <IEquipmentRepository>();

            eqRepository.GetAllEquipments().Returns(testData);

            IUnitOfWork uow = Substitute.For <IUnitOfWork>();

            uow.EquipmentRepository.Returns(eqRepository);

            EquipmentService eService = new EquipmentService(uow);

            //Act
            var equipments = eService.GetAllEquipments();

            //Assert
            equipments.Should().NotBeNull();
        }
        public void WillReturnSecondEquipment()
        {
            //Arrange
            var testHelper = new TestHelper();
            var testData   = testHelper.CreateEquipmentList();
            int id         = testData[1].Id;

            IEquipmentRepository eqRepository = Substitute.For <IEquipmentRepository>();

            eqRepository.GetEquipmentById(id).Returns(testData[1]);

            IUnitOfWork uow = Substitute.For <IUnitOfWork>();

            uow.EquipmentRepository.Returns(eqRepository);

            EquipmentService eService = new EquipmentService(uow);

            //Act
            var equipmentTaken = eService.GetEquipmentById(id);

            //Assert
            equipmentTaken.ProductName.Should().Be("EqTest2");
        }
Пример #8
0
        public void CreateRentalWillCreateRentalObject()
        {
            //Arrange
            var testHelper = new TestHelper();
            var testData   = testHelper.CreateEquipmentList();

            IRentalRepository rentalRepository = Substitute.For <IRentalRepository>();


            IUnitOfWork uow = Substitute.For <IUnitOfWork>();

            uow.RentalRepository.Returns(rentalRepository);

            RentalService rs = new RentalService(uow);

            Rental rental = new Rental();

            rental.CustomerName        = "Johan Eriksson";
            rental.CustomerPhoneNumber = "0705556677";
            rental.StartTime           = DateTime.Now;
            rental.EquipmentId         = testData[0].Id;

            RentalPlan rp = new RentalPlan();

            rp.Id       = 1;
            rp.Duration = 8;
            rp.Discount = 0;

            rental.RentalPlanId = rp.Id;

            //Act
            rs.CreateRental(rental);

            //Assert
            rentalRepository.Received().CreateRental(rental);
        }