コード例 #1
0
        /// <summary>
        /// Constructor For Setting RL, BL, Controller Instances.
        /// </summary>
        public Tests()
        {
            this.dbContext = new ParkingLotDBContext(dbContextOptions);
            var myConfiguration = new Dictionary <string, string>
            {
                { "Jwt:Key", "ThisismySecretKey" },
                { "Jwt:Issuer", "ParkingLot.com" },
                { "Jwt:Audiance", "ParkingLot.com" },
                { "Logging:LogLevel:Default", "Warning" },
                { "AllowedHosts", "*" },
                { "ConnectionStrings:ParkingLotConnectionString", "Server=localhost\\SQLEXPRESS;Database=ParkingLotDB;Trusted_Connection=True;" }
            };

            this.configuration = new ConfigurationBuilder().AddInMemoryCollection(myConfiguration).Build();

            distributedCache = new RedisCache(new RedisCacheOptions
            {
                Configuration = "parkinglot.redis.cache.windows.net:6380,password=RxLRe+cHYDzGro4UX8D4VtkfsifZ93ZM8CJlKI5Tobw=,ssl=True,abortConnect=False",
                InstanceName  = "master"
            });

            userRL         = new UserRL(dbContext);
            userBL         = new UserBL(userRL);
            userController = new UserController(userBL, configuration);

            parkingLotRL      = new ParkingLotRL(dbContext);
            parkingLotBL      = new ParkingLotBL(parkingLotRL);
            parkingController = new ParkingController(parkingLotBL, distributedCache);
        }
コード例 #2
0
        public async void GetParkingByStreetName_IfParkingExist_ExpectedCountry(string sName, string expected)
        {
            //Arrange
            var profile       = new MappedProfile();
            var configuration = new MapperConfiguration(x => x.AddProfile(profile));
            var mapper        = new Mapper(configuration);

            var mockContext = new Mock <DataContext>();

            mockContext.Setup(x => x.Parkings).ReturnsDbSet(GetParking());
            var logger = Mock.Of <ILogger <ParkingRepository> >();

            var parkingRepo = new ParkingRepository(mockContext.Object, logger);

            var actionDescriptor       = new List <ActionDescriptor>();
            var descriptorProviderMock = new Mock <ActionDescriptorCollectionProvider>();

            descriptorProviderMock.Setup(x => x.ActionDescriptors).Returns(new ActionDescriptorCollection(actionDescriptor, 0));

            var controller = new ParkingController(parkingRepo, mapper, descriptorProviderMock.Object);

            //Act
            var result = await controller.GetParkingByStreetName(sName, false);

            var contentResult = result as OkObjectResult;
            var dto           = contentResult.Value as ParkingDTO;

            //Assert
            Assert.Equal(expected, dto.Country);
        }
コード例 #3
0
        public void ParkingControllerTest()
        {
            var controller = new ParkingController(_mock.Object);

            Assert.IsNotNull(controller);
            Assert.IsInstanceOfType(controller, typeof(ParkingController));
        }
コード例 #4
0
        public async void GetParkings_IfExist_ExpectedCity()
        {
            //Arrange
            var profile       = new MappedProfile();
            var configuration = new MapperConfiguration(x => x.AddProfile(profile));
            var mapper        = new Mapper(configuration);

            var mockContext = new Mock <DataContext>();

            mockContext.Setup(x => x.Parkings).ReturnsDbSet(GetParking());

            var logger      = Mock.Of <ILogger <ParkingRepository> >();
            var parkingRepo = new ParkingRepository(mockContext.Object, logger);

            var actionDescriptor       = new List <ActionDescriptor>();
            var descriptorProviderMock = new Mock <ActionDescriptorCollectionProvider>();

            descriptorProviderMock.Setup(x => x.ActionDescriptors).Returns(new ActionDescriptorCollection(actionDescriptor, 0));

            var controller = new ParkingController(parkingRepo, mapper, descriptorProviderMock.Object);
            //Act
            var result = await controller.GetParkings(false, false, false);

            var    contentResut = result as OkObjectResult;
            var    dto          = contentResut.Value as ParkingDTO[];
            string city         = "Stockholm";

            //Assert
            Assert.Equal(city, dto[0].City);
        }
コード例 #5
0
        public async void DeleteParkingByID_IfIdFound_Expected204StatusCode()
        {
            //Arrange
            var profile       = new MappedProfile();
            var configuration = new MapperConfiguration(x => x.AddProfile(profile));
            var mapper        = new Mapper(configuration);

            var parkingRepo = new Mock <IParkingRepo>();

            parkingRepo.Setup(x => x.GetParkingById(It.IsAny <int>(), It.IsAny <Boolean>(), It.IsAny <Boolean>()))
            .Returns(Task.FromResult(new Parking()));
            parkingRepo.Setup(x => x.Save()).Returns(Task.FromResult(true));

            var actionDescriptor       = new List <ActionDescriptor>();
            var descriptorProviderMock = new Mock <ActionDescriptorCollectionProvider>();

            descriptorProviderMock.Setup(x => x.ActionDescriptors).Returns(new ActionDescriptorCollection(actionDescriptor, 0));

            var controller = new ParkingController(parkingRepo.Object, mapper, descriptorProviderMock.Object);
            int id         = 1;
            //Act
            var result = await controller.DeleteParkingByID(id);

            var contentResult = result as NoContentResult;

            //Assert
            Assert.Equal(204, contentResult.StatusCode);
        }
コード例 #6
0
        public void Parking_StatusShouldReturnNotFound()
        {
            //Setting Data.
            var           dbContext    = new ParkingLotDBContext(dbContextOptions);
            IParkingLotRL parkingLotRL = new ParkingLotRL(dbContext)
            {
                TotalLotLimit = 0
            };
            IParkingLotBL     parkingLotBL      = new ParkingLotBL(parkingLotRL);
            ParkingController parkingController = new ParkingController(parkingLotBL, distributedCache);

            //Act
            var response        = parkingController.CheckLotStatus() as NotFoundObjectResult;
            var jsonResponse    = JToken.Parse(JsonConvert.SerializeObject(response.Value));
            var responseSuccess = jsonResponse["Success"].ToObject <bool>();
            var responseMessage = jsonResponse["Message"].ToString();

            //Expected Values.
            string Message = "Lot Is Full";

            //Asserting Values.
            Assert.IsType <NotFoundObjectResult>(response);
            Assert.Equal(SuccessFalse, responseSuccess);
            Assert.Equal(Message, responseMessage);
        }
コード例 #7
0
        public void Parking_ValidVehicalNumberUnparkedShouldReturnNotFound()
        {
            //Setting Values.
            dbContext.ParkingDetails.Add(new ParkingDetails {
                ReceiptNumber = 9, VehicalOwnerName = "Pratik", VehicalNumber = "MH 07 PZ 1234", Brand = "Tata", Color = "White", DriverName = "Sanju", ParkingSlot = null, Status = "Unparked", TotalAmount = 40, TotalTime = 0.0015289095, IsHandicap = false
            });
            dbContext.SaveChanges();
            var parkingRL         = new ParkingLotRL(dbContext);
            var parkingBL         = new ParkingLotBL(parkingRL);
            var parkingController = new ParkingController(parkingBL, distributedCache);

            string VehicalNumber   = "MH 07 PZ 1234";
            var    response        = parkingController.GetVehicalByNumber(VehicalNumber) as NotFoundObjectResult;
            var    dataResponse    = JToken.Parse(JsonConvert.SerializeObject(response.Value));
            var    responseSuccess = dataResponse["Success"].ToObject <bool>();
            var    responseMessage = dataResponse["Message"].ToString();

            //Expected Values
            string Message = "Car Already Unparked";

            //Asserting Values.
            Assert.IsType <NotFoundObjectResult>(response);
            Assert.Equal(SuccessFalse, responseSuccess);
            Assert.Equal(Message, responseMessage);
        }
コード例 #8
0
 public void Setup()
 {
     // setup
     _lab08ParkingLotUnitOfWork = new Mock <ILab08ParkingLotUnitOfWork>();
     _vehicleRatesService       = new VehicleRatesService();
     _calculatorService         = new CalculatorService(_lab08ParkingLotUnitOfWork.Object, _vehicleRatesService);
     _registerService           = new RegisterService(_lab08ParkingLotUnitOfWork.Object, _calculatorService);
     _controller = new ParkingController(_registerService, _calculatorService);
 }
コード例 #9
0
ファイル: LimitTests.cs プロジェクト: jackinf/ParkingHouse
        public void TestReservedParkingSpaces()
        {
            var car  = GenerateCar(501, 2, 4, true);
            var cars = GenerateCars(4, 2, false, 450);

            var mock = new Mock <ICarsParkingRepository>();

            mock.Setup(m => m.Cars).Returns(cars.AsQueryable());
            var target = new ParkingController(mock.Object, Repository);

            target.AddParkingCar(car);
        }
コード例 #10
0
        public void GetALLParkingDetailsPasses_OkResult()
        {
            var controller = new ParkingController(_businessLayerparking, _configuration, dBContext);

            var okResult1 = controller.GetAllParkingData();
            var okResult2 = controller.GetAllParkVehicleData();
            var okResult3 = controller.GetAllUnParkVehicleData();

            Assert.IsType <OkObjectResult>(okResult1);
            Assert.IsType <OkObjectResult>(okResult2);
            Assert.IsType <OkObjectResult>(okResult3);
        }
コード例 #11
0
        public void Setup()
        {
            // setup
            _lab08ParkingLotUnitOfWork = new Mock <ILab08ParkingLotUnitOfWork>();
            _vehicleRatesService       = new Mock <IVehicleRatesService>();
            _calculatorService         = new CalculatorService(_lab08ParkingLotUnitOfWork.Object, _vehicleRatesService.Object);
            _registerService           = new RegisterService(_lab08ParkingLotUnitOfWork.Object, _calculatorService);
            _controller = new ParkingController(_registerService, _calculatorService);

            _lab08ParkingLotUnitOfWork.Setup(r => r.VehicleRepository.Insert(It.IsAny <Vehicle>())).Verifiable();

            _fixture = new Fixture();
        }
コード例 #12
0
        //Constructor
        public ParkingLotTestCase()
        {
            var context = new ParkingLotDbContext(dbContextOptions);

            _IVehicalParkingDetailsRL = new VehicalParkingDetailsRL(context);
            _IVehicalParkingDetailsBL = new VehicalParkingDetailsBL(_IVehicalParkingDetailsRL);

            _IUserRL = new UserRL(context);
            _IUserBL = new UserBL(_IUserRL);

            parkingController = new ParkingController(_IVehicalParkingDetailsBL, distributedCache);
            userController    = new UserController(_IUserBL, configuration);
        }
コード例 #13
0
        public void GivenWrongParkedTypePasses_BadRequestResult_Exception()
        {
            var controller = new ParkingController(_businessLayerparking, _configuration, dBContext);
            var result     = new Information
            {
                VehicalNumber = "MH 17 QW 5162",
                VehicalBrand  = "Toyata",
                VehicalColor  = "Black",
                ParkingType   = "abcd"
            };
            var okResult = controller.ParkVehicle(result);

            Assert.IsType <BadRequestObjectResult>(okResult);
        }
コード例 #14
0
        public void GivenSameForParkedVehicleDataPasses_BadRequestResult_Exception()
        {
            var controller = new ParkingController(_businessLayerparking, _configuration, dBContext);
            var result     = new Information
            {
                VehicalNumber = "MH 07 BT 1895",
                VehicalBrand  = "BMW",
                VehicalColor  = "Black",
                ParkingType   = "Owner"
            };
            var okResult = controller.ParkVehicle(result);

            Assert.IsType <BadRequestObjectResult>(okResult);
        }
コード例 #15
0
        public void GivenDataForParkedVehiclePasses_Ok()
        {
            var controller = new ParkingController(_businessLayerparking, _configuration, dBContext);
            var result     = new Information
            {
                VehicalNumber = "MH 15 ES 1234",
                VehicalBrand  = "Toyota",
                VehicalColor  = "White",
                ParkingType   = "Vallet"
            };
            var okResult = controller.ParkVehicle(result);

            Assert.IsType <OkObjectResult>(okResult);
        }
コード例 #16
0
        private void ParkingDGMenuDel(object sender, RoutedEventArgs e)
        {
            if (ParkingDG.SelectedItem != null)
            {
                var parkingSlot = ParkingDG.SelectedItem as ParkingSlot;



                ParkingController.Delete(parkingSlot);
                Application.Current.MainWindow.DataContext = new ParkingView();
            }
            else
            {
                MessageBox.Show("Nie wybrano elementu", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #17
0
        public void Parking_ExistingParkedVehicalShouldReturnConflict()
        {
            //Setting Values.
            parkingDetails.VehicalOwnerName = "Rahul";
            parkingDetails.VehicalNumber    = "MH 01 AB 1234";
            parkingDetails.Brand            = "Skoda";
            parkingDetails.Color            = "Black";

            dbContext.ParkingDetails.Add(new ParkingDetails {
                ReceiptNumber = 2, VehicalOwnerName = "Rahul", VehicalNumber = "MH 01 AB 1234", Brand = "Skoda", Color = "Black", DriverName = "Ramesh", ParkingSlot = "D", Status = "Parked", TotalAmount = 0, TotalTime = 0, IsHandicap = false
            });
            dbContext.SaveChanges();
            var parkingRL         = new ParkingLotRL(dbContext);
            var parkingBL         = new ParkingLotBL(parkingRL);
            var parkingController = new ParkingController(parkingBL, distributedCache);

            //Setting JWT Claim - Name
            Claim          Name     = new Claim(ClaimTypes.Name, "Ramesh");
            ClaimsIdentity identity = new ClaimsIdentity();

            identity.AddClaim(Name);
            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal();

            claimsPrincipal.AddIdentity(identity);
            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.User).Returns(claimsPrincipal);
            parkingController.ControllerContext.HttpContext = contextMock.Object;


            //Act
            var response        = parkingController.Park(parkingDetails) as ConflictObjectResult;
            var dataResponse    = JToken.Parse(JsonConvert.SerializeObject(response.Value));
            var responseSuccess = dataResponse["Success"].ToObject <bool>();
            var responseMessage = dataResponse["Message"].ToString();

            //Expected Values.
            string Message = "Vehical Is Already Parked";

            //Asserting Values.
            Assert.IsType <ConflictObjectResult>(response);
            Assert.Equal(SuccessFalse, responseSuccess);
            Assert.Equal(Message, responseMessage);
        }
コード例 #18
0
ファイル: LimitTests.cs プロジェクト: jackinf/ParkingHouse
        public void TestLimitCap()
        {
            var car  = GenerateCar(501, 4, 2, true);
            var cars = GenerateCars(4, 2, true, 500);

            var mock       = new Mock <ICarsParkingRepository>();
            var enumerable = cars as IList <Car> ?? cars.ToList();

            mock.Setup(m => m.Cars).Returns(enumerable.AsQueryable());

            var target        = new ParkingController(mock.Object, Repository);
            var cannotAddCars = target.AddParkingCar(car);

            Assert.IsNotNull(cannotAddCars);
            Assert.AreEqual(500, enumerable.Count());

            var result = target.List();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
コード例 #19
0
        public async void UpdateParkingByID_IfIdExist_Expected204StatusCode()
        {
            //Arrange
            var profile       = new MappedProfile();
            var configuration = new MapperConfiguration(x => x.AddProfile(profile));
            var mapper        = new Mapper(configuration);

            var parkingRepo = new Mock <IParkingRepo>();

            parkingRepo.Setup(x => x.GetParkingById(It.IsAny <int>(), It.IsAny <Boolean>(), It.IsAny <Boolean>()))
            .Returns(Task.FromResult(new Parking()));
            parkingRepo.Setup(x => x.Save()).Returns(Task.FromResult(true));

            var actionDescriptor       = new List <ActionDescriptor>();
            var descriptorProviderMock = new Mock <ActionDescriptorCollectionProvider>();

            descriptorProviderMock.Setup(x => x.ActionDescriptors).Returns(new ActionDescriptorCollection(actionDescriptor, 0));

            var controller = new ParkingController(parkingRepo.Object, mapper, descriptorProviderMock.Object);

            int id  = 1;
            var dto = new ParkingDTO
            {
                ParkingID        = 1,
                Country          = "Sweden",
                City             = "Stockholm",
                StreetAdress     = "Drottninggatan",
                FreeParkingStart = "18:00",
                FreeParkingEnd   = "07:00",
                UserID           = 1
            };

            //Act
            var result = await controller.UpdateParkingByID(id, dto);

            var contentResult = result as NoContentResult;

            //Assert
            Assert.Equal(204, contentResult.StatusCode);
        }
コード例 #20
0
        /// <summary>
        /// Adds cars into parking spaces according if car has contract or not.
        /// </summary>
        /// <param name="car">Car which is being added</param>
        /// <param name="parkingController">Used to set modelstate to false if any errors occur</param>
        public void AddCarToParkingLot(Car car, ParkingController parkingController)
        {
            var carsInParkingLotWithContract = context.Cars.Count(c => c.HasContract);
            var carsInParkingLot             = context.Cars.Count();

            if (!HasFreeParkingSpaces(carsInParkingLot))
            {
                parkingController.ModelState.AddModelError("error",
                                                           "The parking house is full. Come back later.");
                return;
            }

            // try to add a car with contract
            if (CanAddCarsWhenNoFreeSpaceLeft(carsInParkingLot, carsInParkingLotWithContract, car.HasContract))
            {
                context.Cars.Add(car);
                return;
            }

            // try to add a car with no contract
            if (CanAddCarsWhenNoFreeSpaceLeft(carsInParkingLot, carsInParkingLotWithContract, !car.HasContract))
            {
                var reservedSpaces = GetReservedSpaces(carsInParkingLotWithContract);
                if (GetFreeSpaces(carsInParkingLotWithContract, reservedSpaces) <= 0)
                {
                    parkingController.ModelState.AddModelError("error",
                                                               string.Format(
                                                                   "Last {0} spot(s) reserved for clients with a contract. Come back later.",
                                                                   reservedSpaces));
                    return;
                }

                // Add a car only if there are free spaces left
                context.Cars.Add(car);
            }
        }
コード例 #21
0
 /// <summary>
 /// Declare Constructor
 /// </summary>
 public ParkingTestCase()
 {
     parkingLotRL      = new ParkingRL();
     parkingLotBL      = new ParkingBL(parkingLotRL);
     parkingController = new ParkingController(parkingLotBL, distributedCache);
 }