コード例 #1
0
ファイル: TeamData.cs プロジェクト: mnedelman/scorer
 public static TeamData Load(string filename)
 {
     if (File.Exists(filename)) {
     XmlSerializer ser = new XmlSerializer(typeof(TeamData));
     using (TextReader reader = File.OpenText(filename)) {
       return (TeamData)ser.Deserialize(reader);
     }
       } else {
     TeamData team_data = new TeamData();
     team_data.Save(filename);
     return team_data;
       }
 }
コード例 #2
0
ファイル: TeamDataTest.cs プロジェクト: mnedelman/scorer
        public void TestGetScoresEqual()
        {
            EventScore score_zero = new EventScore();

            score_zero.Zero();

            Team team1 = new Team("1", string.Empty);

            Team team2 = new Team("2", string.Empty);

            team2.Scores[0] = score_zero;
            team2.Scores[2] = score_zero;

            Team team3 = new Team("3", string.Empty);

            team3.Scores[1] = score_zero;

            Team team4 = new Team("4", string.Empty);

            team4.Scores[0] = score_zero;
            team4.Scores[1] = score_zero;
            team4.Scores[2] = score_zero;

            TeamData team_data = new TeamData();

            team_data.Teams = new Team[] { team1, team2, team3, team4 };
            ScoreRow[] scores = team_data.GetScores();
            Assert.AreEqual(4, scores.Length);
            Assert.AreEqual("4", scores[0].Number);
            Assert.AreEqual(1, scores[0].Rank);
            Assert.AreEqual("2", scores[1].Number);
            Assert.AreEqual(1, scores[0].Rank);
            Assert.AreEqual("3", scores[2].Number);
            Assert.AreEqual(1, scores[0].Rank);
            Assert.AreEqual("1", scores[3].Number);
            Assert.AreEqual(1, scores[0].Rank);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: mnedelman/scorer
        /// <summary>
        /// Loads team data from a file.
        /// </summary>
        /// <param name="filename">The file to load.</param>
        /// <returns>True if the file was successfully loaded.</returns>
        protected bool SelectFile(string filename)
        {
            try {
              	    team_data_ = TeamData.Load(filename);
            } catch (Exception e) {
              string message = string.Format(
              "There was an error opening {0}.  Please select a different file.\n{1}",
              filename, e);
              MessageBox.Show(this, message, "File Error", MessageBoxButtons.OK);
              return false;
            }
            Config.FileName = filename;

            UpdateFileItems();
            return true;
        }
コード例 #4
0
ファイル: TeamDataTest.cs プロジェクト: mnedelman/scorer
        public void TestGetScoresEqual()
        {
            EventScore score_zero = new EventScore();
              score_zero.Zero();

              Team team1 = new Team("1", string.Empty);

              Team team2 = new Team("2", string.Empty);
              team2.Scores[0] = score_zero;
              team2.Scores[2] = score_zero;

              Team team3 = new Team("3", string.Empty);
              team3.Scores[1] = score_zero;

              Team team4 = new Team("4", string.Empty);
              team4.Scores[0] = score_zero;
              team4.Scores[1] = score_zero;
              team4.Scores[2] = score_zero;

              TeamData team_data = new TeamData();
              team_data.Teams = new Team[] {team1, team2, team3, team4};
              ScoreRow[] scores = team_data.GetScores();
              Assert.AreEqual(4, scores.Length);
              Assert.AreEqual("4", scores[0].Number);
              Assert.AreEqual(1, scores[0].Rank);
              Assert.AreEqual("2", scores[1].Number);
              Assert.AreEqual(1, scores[0].Rank);
              Assert.AreEqual("3", scores[2].Number);
              Assert.AreEqual(1, scores[0].Rank);
              Assert.AreEqual("1", scores[3].Number);
              Assert.AreEqual(1, scores[0].Rank);
        }