Exemple #1
0
        public void GetRideLevel_ReturnsHardWith12Rides5IsNormal()
        {
            Member    member = new Member();
            BikeRoute route1 = new BikeRoute();
            BikeRoute route2 = new BikeRoute();

            route1.Difficulty = Difficulty.Easy;
            route2.Difficulty = Difficulty.Normal;
            for (int i = 0; i < 7; i++)
            {
                Ride ride = new Ride();
                ride.Route = route1;
                member.Add(ride);
            }
            for (int i = 0; i < 5; i++)
            {
                Ride ride = new Ride();
                ride.Route = route2;
                member.Add(ride);
            }
            Difficulty expectedDifficulty = Difficulty.Hard;

            //Act
            Difficulty actualDiffculty = member.RideLevel;

            //Assert
            Assert.Equal(expectedDifficulty, actualDiffculty);
        }
Exemple #2
0
        public void GetRideLevel_ReturnsNormalWith12Rides4IsNormal()
        {
            Member    member = new Member();
            BikeRoute route  = new BikeRoute();
            BikeRoute route2 = new BikeRoute();

            route.Difficulty  = Difficulty.Easy;
            route2.Difficulty = Difficulty.Normal;
            for (int i = 0; i < 8; i++)
            {
                Ride ride = new Ride();
                ride.Route = route;
                member.Add(ride);
            }
            for (int i = 0; i < 4; i++)
            {
                Ride ride = new Ride();
                ride.Route = route2;
                member.Add(ride);
            }
            Difficulty expectedDifficulty = Difficulty.Normal;

            Difficulty actualDifficulty = member.RideLevel;

            Assert.Equal <Difficulty>(expectedDifficulty, actualDifficulty);
        }
Exemple #3
0
        public void GetRideLevel_ReturnsHardWith30Rides9IsHard()
        {
            Member    member = new Member();
            BikeRoute route  = new BikeRoute();
            BikeRoute route2 = new BikeRoute();
            BikeRoute route3 = new BikeRoute();

            route.Difficulty  = Difficulty.Easy;
            route2.Difficulty = Difficulty.Normal;
            route3.Difficulty = Difficulty.Hard;
            for (int i = 0; i < 7; i++)
            {
                Ride ride = new Ride();
                ride.Route = route;
                member.Add(ride);
            }
            for (int i = 0; i < 5; i++)
            {
                Ride ride = new Ride();
                ride.Route = route2;
                member.Add(ride);
            }
            for (int i = 0; i < 9; i++)
            {
                Ride ride = new Ride();
                ride.Route = route3;
                member.Add(ride);
            }
            Difficulty expectedDifficulty = Difficulty.Hard;

            Difficulty actualDifficulty = member.RideLevel;

            Assert.Equal <Difficulty>(expectedDifficulty, actualDifficulty);
        }
Exemple #4
0
        public void GetRideLevel_ReturnsNormalWith5Rides()
        {
            //Arrange
            Member    member = new Member();
            Ride      ride1  = new Ride();
            BikeRoute route  = new BikeRoute();

            route.Difficulty = Difficulty.Easy;
            ride1.Route      = route;
            member.Add(ride1);
            Ride ride2 = new Ride();

            ride2.Route = route;
            member.Add(ride2);
            Ride ride3 = new Ride();

            ride3.Route = route;
            member.Add(ride3);
            Ride ride4 = new Ride();

            ride4.Route = route;
            member.Add(ride4);
            Ride ride5 = new Ride();

            ride5.Route = route;
            member.Add(ride5);
            Difficulty expectedDifficulty = Difficulty.Normal;

            //Act
            Difficulty actualDiffculty = member.RideLevel;

            //Assert
            Assert.Equal(expectedDifficulty, actualDiffculty);
        }
Exemple #5
0
        public void AddRide_ReturnsFalseRideWasntAdded()
        {
            Member    member = new Member();
            BikeRoute route  = new BikeRoute();

            route.Difficulty = Difficulty.Normal;
            Ride ride = new Ride();

            ride.Route = route;

            Assert.False(member.Add(ride));
        }
Exemple #6
0
        public void AddRide_ReturnsTrueRideWasAdded()
        {
            Member    member = new Member();
            BikeRoute route  = new BikeRoute();

            route.Difficulty = Difficulty.Easy;
            Ride ride = new Ride();

            ride.Route = route;

            Assert.True(member.Add(ride));
        }
Exemple #7
0
        public bool AddToDB(BikeRoute bikeRoute)                                                                                                                           // Adds a BikeRoute to the database
        {
            string sql = $"INSERT INTO BikeRoutes VALUES('{bikeRoute.Name}', {bikeRoute.Length}, {(int)bikeRoute.Difficulty}, '{bikeRoute.Country}', '{bikeRoute.City}')"; // Creates the SQL query used to add the BikeRoute to the database

            try
            {
                ExecuteNonQuery(sql); // Tries to run the query
            }
            catch (Exception)         // If the query fails, an exception is cast
            {
                return(false);        // Returns false if the code casts an exception
            }
            return(true);             // Returns true if the code runs succesfully with no exceptions
        }
Exemple #8
0
        public void IsValidRide_ReturnsFalseWithNoDate()
        {
            Member    member = new Member();
            BikeRoute route  = new BikeRoute();

            route.Difficulty = Difficulty.Easy;
            Ride ride = new Ride();

            ride.Member = member;
            ride.Route  = route;

            (bool isValid, string errMsg)result = ride.IsValidRide;

            Assert.False(result.isValid, result.errMsg);
        }
Exemple #9
0
        public void IsValidRide_ReturnsFalseWithNoMember()
        {
            BikeRoute route = new BikeRoute();

            route.Difficulty = Difficulty.Easy;
            Ride     ride = new Ride();
            DateTime date = DateTime.Today.AddDays(-10);

            ride.Route    = route;
            ride.RideDate = date;

            (bool isValid, string errMsg)result = ride.IsValidRide;

            Assert.False(result.isValid, result.errMsg);
        }
Exemple #10
0
        public void AddRide_ReturnsFalseRideWasntAdded()
        {
            //Arrange
            Member    member    = new Member();
            BikeRoute bikeRoute = new BikeRoute();

            bikeRoute.Difficulty = Difficulty.Hard;
            Ride ride = new Ride();

            ride.Route = bikeRoute;


            //Act

            //Assert
            Assert.False(member.Add(ride));
        }
Exemple #11
0
        public void AddRide_ReturnsTrueRideWasAdded()
        {
            //Arrange
            Member    member    = new Member();
            BikeRoute bikeRoute = new BikeRoute();

            bikeRoute.Difficulty = Difficulty.Easy;
            Ride ride = new Ride();

            ride.Route = bikeRoute;


            //Act

            //Assert
            Assert.True(member.Add(ride));
        }
Exemple #12
0
        public void GetRideLevel_ReturnsEasyWith4Rides()
        {
            Member    member = new Member();
            BikeRoute route  = new BikeRoute();

            route.Difficulty = Difficulty.Easy;
            for (int i = 0; i < 4; i++)
            {
                Ride ride = new Ride();
                ride.Route = route;
                member.Add(ride);
            }
            Difficulty expectedDifficulty = Difficulty.Easy;

            Difficulty actualDifficulty = member.RideLevel;

            Assert.Equal <Difficulty>(expectedDifficulty, actualDifficulty);
        }
Exemple #13
0
        public void GetRideLevel_ReturnsNormalWith11Rides()
        {
            //Arrange
            Member    member = new Member();
            BikeRoute route  = new BikeRoute();

            route.Difficulty = Difficulty.Easy;
            for (int i = 0; i < 11; i++)
            {
                Ride ride = new Ride();
                ride.Route = route;
                member.Add(ride);
            }
            Difficulty expectedDifficulty = Difficulty.Normal;

            //Act
            Difficulty actualDiffculty = member.RideLevel;

            //Assert
            Assert.Equal(expectedDifficulty, actualDiffculty);
        }
Exemple #14
0
        public void GetRideLevel_ReturnsExpertWith30Rides()
        {
            Member member = new Member();

            member.EnrollmentDate = DateTime.Parse("2017-05-20");
            BikeRoute route1 = new BikeRoute();
            BikeRoute route2 = new BikeRoute();
            BikeRoute route3 = new BikeRoute();

            route1.Difficulty = Difficulty.Easy;
            route2.Difficulty = Difficulty.Normal;
            route3.Difficulty = Difficulty.Hard;
            for (int i = 0; i < 7; i++)
            {
                Ride ride = new Ride();
                ride.Route = route1;
                member.Add(ride);
            }
            for (int i = 0; i < 13; i++)
            {
                Ride ride = new Ride();
                ride.Route = route2;
                member.Add(ride);
            }
            for (int i = 0; i < 10; i++)
            {
                Ride ride = new Ride();
                ride.Route = route3;
                member.Add(ride);
            }

            Difficulty expectedDifficulty = Difficulty.Expert;

            //Act
            Difficulty actualDiffculty = member.RideLevel;

            //Assert
            Assert.Equal(expectedDifficulty, actualDiffculty);
        }
Exemple #15
0
        public void GetRideLevel_ReturnsHardWith30Rides10IsHardLessThan1Year()
        {
            Member member = new Member();

            member.EnrollmentDate = DateTime.Today;
            BikeRoute route  = new BikeRoute();
            BikeRoute route2 = new BikeRoute();
            BikeRoute route3 = new BikeRoute();

            route.Difficulty  = Difficulty.Easy;
            route2.Difficulty = Difficulty.Normal;
            route3.Difficulty = Difficulty.Hard;
            for (int i = 0; i < 10; i++)
            {
                Ride ride = new Ride();
                ride.Route = route;
                member.Add(ride);
            }
            for (int i = 0; i < 10; i++)
            {
                Ride ride = new Ride();
                ride.Route = route2;
                member.Add(ride);
            }
            for (int i = 0; i < 10; i++)
            {
                Ride ride = new Ride();
                ride.Route = route3;
                member.Add(ride);
            }
            Difficulty expectedDifficulty = Difficulty.Hard;

            Difficulty actualDifficulty = member.RideLevel;

            Assert.Equal <Difficulty>(expectedDifficulty, actualDifficulty);
        }
Exemple #16
0
        public void GetRideLevel_ReturnsExpertWith30Rides() // Partial solution to an issue suggested by Morten
        {
            Member member = new Member();

            member.EnrollmentDate = DateTime.Today.AddYears(-2);
            BikeRoute route  = new BikeRoute();
            BikeRoute route2 = new BikeRoute();
            BikeRoute route3 = new BikeRoute();

            route.Difficulty  = Difficulty.Easy;
            route2.Difficulty = Difficulty.Normal;
            route3.Difficulty = Difficulty.Hard;
            for (int i = 0; i < 10; i++)
            {
                Ride ride = new Ride();
                ride.Route = route;
                member.Add(ride);
            }
            for (int i = 0; i < 10; i++)
            {
                Ride ride = new Ride();
                ride.Route = route2;
                member.Add(ride);
            }
            for (int i = 0; i < 10; i++)
            {
                Ride ride = new Ride();
                ride.Route = route3;
                member.Add(ride);
            }
            Difficulty expectedDifficulty = Difficulty.Expert;

            Difficulty actualDifficulty = member.RideLevel;

            Assert.Equal <Difficulty>(expectedDifficulty, actualDifficulty);
        }
Exemple #17
0
        public int Insert(BikeRoute bikeRoute)
        {
            string sql = $"INSERT INTO BikeRoutes VALUES ('{bikeRoute.Name}', {bikeRoute.Length.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)}, {(int)bikeRoute.Difficulty}, '{bikeRoute.Country}', '{bikeRoute.City}')";

            return(ExecuteNonQuery(sql));
        }