Ejemplo n.º 1
0
        public void TestChallangeConstructorWithInvalidParameters()
        {
            string name = "John Doe";
            string description = "Complete me";
            Time startTime = new Time(00, 20, 30);
            Time endTime = new Time(01, 30, 20);
            List<Activity> requirements = new List<Activity>();

            Challenge challange = new Challenge(name, description, startTime, endTime, requirements);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructs a CurrentChallenge with its fields.
 /// </summary>
 /// <param name="challenge">Which challenge to take on. Null is not allowed as challenge.</param>
 public CurrentChallenge(Challenge challenge)
 {
     if (challenge == null)
     {
         throw new ArgumentException("Null Object is not allowed as challenge for current challenge.");
     }
     Challenge = challenge;
     DateTime now = DateTime.Now;
     StartTime = new Time(now.Hour, now.Minute, now.Second);
 }
Ejemplo n.º 3
0
        public void TestChallangeConstructorWithValidParameters()
        {
            string name = "John Doe";
            string description = "Complete me";
            Time startTime = new Time(00, 20, 30);
            Time endTime = new Time(01, 30, 20);
            List<Activity> requirements = new List<Activity>();
            requirements.Add(new Activity("John Doe", "Complete me", 3, 4, null));

            Challenge challange = new Challenge(name, description, startTime, endTime, requirements);

            Assert.AreEqual(name, challange.Name);
            Assert.AreEqual(description, challange.Description);
            Assert.AreEqual(startTime, challange.StartTime);
            Assert.AreEqual(endTime, challange.EndTime);
            Assert.AreEqual(requirements, challange.Requirements);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method for getting an Challenge from the database.
        /// </summary>
        /// <param name="challenge"></param>Name of the Challenge.
        /// <returns></returns>Returns the Challenge with the given name from param. 
        public Challenge GetChallengeQuery(String challenge)
        {
            OpenConnection();
            string commandTextGetActivitiesNames = "SELECT activityName FROM ChallengeRequires WHERE challengeName = @ChallengeName";
            var mySqlCommand = new MySqlCommand(commandTextGetActivitiesNames, Connection);
            mySqlCommand.Parameters.AddWithValue("@ChallengeName", challenge);
            var reader = mySqlCommand.ExecuteReader();
            List<string> activitiesName = new List<string>();

            int i = 0;
            while (reader.Read())
            {
                activitiesName.Add(reader.GetString(0));
                i++;
            }

            CloseConnection();

            List<Activity> activities = new List<Activity>();

            foreach (String s in activitiesName)
            {
                activities.Add(GetActivityQuery(s));
            }

            OpenConnection();

            string commandTextFromActivity = "SELECT * FROM Challenge WHERE Name = @Challenge";
            var mySqlCommand2 = new MySqlCommand(commandTextFromActivity, Connection);
            mySqlCommand2.Parameters.AddWithValue("@Challenge", challenge);
            var reader2 = mySqlCommand2.ExecuteReader();
            Challenge a = null;

            if (reader2.Read())
            {
                String startTime = reader2.GetString(2);
                String endTime = reader2.GetString(3);

                string[] s1 = startTime.Split(':');
                string[] s2 = endTime.Split(':');

                a = new Challenge("" + reader2.GetString(0), "" + reader2.GetString(1), new Time(int.Parse(s1[0]), int.Parse(s1[1]), int.Parse(s1[2])), new Time(int.Parse(s2[0]), int.Parse(s2[1]), int.Parse(s2[2])), activities);
            }
            CloseConnection();
            return a;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets the current challenge, if there already is one then throws AlreadyInAChallengeException.
        /// </summary>
        /// <param name="newChallenge">Which challenge to undertake for the user.</param>
        public void SetCurrentChallenge(Challenge challenge)
        {

            // can not start a new challenge before completing the old one
            
            if (connectToDatabase.onGoingChallenge(Username))
            {
                CurrentChallenge = new CurrentChallenge(challenge);
            }
            
            // new challenge is set for the user
            else
            {
                if (connectToDatabase.setCurrentChallenge(Username, challenge.Name))
                {
                    Debug.WriteLine("connectToDatabase.setCurrentChallenge(Username,challenge.Name); has run.");
                    CurrentChallenge = new CurrentChallenge(challenge);
                }
            }
        }
Ejemplo n.º 6
0
        public void TestFailCurrentChallenge()
        {
            string UserName = "******";
            User User = new User(UserName);
            List<Activity> requirements = new List<Activity>();
            requirements.Add(new Activity("John Doe", "Complete me", 3, 4, null));
            Challenge Challange = new Challenge("test", "do me", new Time(0, 0, 0), new Time(0, 0, 01), requirements);

            User.SetCurrentChallenge(Challange);

            Assert.AreEqual(Challange, User.CurrentChallenge.Challenge);

            User.FailCurrentChallenge();

            Assert.AreEqual(null, User.CurrentChallenge);
        }
Ejemplo n.º 7
0
        public void TestCompleteCurrentChallengeWhenDeadlineExpired()
        {
            string UserName = "******";
            User User = new User(UserName);
            List<Activity> requirements = new List<Activity>();
            requirements.Add(new Activity("John Doe", "Complete me", 3, 4, null));
            Challenge Challange = new Challenge("test", "do me", new Time(0, 0, 0), new Time(0, 0, 01), requirements);

            User.SetCurrentChallenge(Challange);

            User.CompleteCurrentChallenge();
        }
Ejemplo n.º 8
0
        public void TestCompleteCurrentChallengeWhenPossible()
        {
            string UserName = "******";
            User User = new User(UserName);
            List<Activity> requirements = new List<Activity>();
            requirements.Add(new Activity("John Doe", "Complete me", 3, 4, null));
            Challenge Challenge = new Challenge("test", "do me", new Time(0, 0, 0), new Time(23, 59, 59), requirements);

            Assert.AreEqual(false, User.CompletedChallenges.Contains(Challenge));

            User.SetCurrentChallenge(Challenge);
            User.CompleteCurrentChallenge();

            Assert.AreEqual(null, User.CurrentChallenge);
            Assert.AreEqual(true, User.CompletedChallenges.Contains(Challenge));
        }
Ejemplo n.º 9
0
        public void TestIsOverEvaluatesToTrue()
        {
            string name = "John Doe";
            string description = "Complete me";
            Time startTime = new Time(00, 00, 00);
            Time endTime = new Time(00, 00, 01);
            List<Activity> requirements = new List<Activity>();
            requirements.Add(new Activity("John Doe", "Complete me", 3, 4, null));

            Challenge challenge = new Challenge(name, description, startTime, endTime, requirements);
            bool expectedToBeTrue = true;

            Assert.AreEqual(expectedToBeTrue, challenge.IsOver());
        }
Ejemplo n.º 10
0
 public void TestChallangeConstructorWithNullParameters()
 {
     Challenge challenge = new Challenge(null, null, null, null, null);
 }
Ejemplo n.º 11
0
        public void TestCurrentChallangeConstructorWithValidParameter()
        {
            List<Activity> requirements = new List<Activity>();
            requirements.Add(new Activity("John Doe", "Complete me", 3, 4, null));
            Challenge challenge = new Challenge("test", "test", new Time(0, 0, 0), new Time(1, 0, 0), requirements);
            CurrentChallenge currentChallange = new CurrentChallenge(challenge);

            DateTime now = DateTime.Now;

            Assert.AreEqual(challenge, currentChallange.Challenge);
        }