예제 #1
0
        public void AddRecordBackupTest()
        {
            RankListStorage storage = new RankListStorage(FilePath);

            storage.AddReccord(new RankListRecord(20, "PlayerThree"), false);
            storage.AddReccord(new RankListRecord(12, "Pesho"), false);
            storage.AddReccord(new RankListRecord(19, "otherPlayer"), true);

            StringBuilder expectedOutput = new StringBuilder();

            expectedOutput.AppendLine("Pesho, 12");
            expectedOutput.AppendLine("otherPlayer, 19");
            expectedOutput.AppendLine("PlayerThree, 20");

            StreamReader reader = new StreamReader(FilePath);
            string       currentLine;

            using (reader)
            {
                currentLine = reader.ReadToEnd();
            }

            bool areEqual = true;

            if (currentLine != expectedOutput.ToString())
            {
                areEqual = false;
            }
            Assert.IsTrue(areEqual, "The result from AddRecord() is incorrect");
        }
예제 #2
0
        public void AddRecordSortTest()
        {
            RankListStorage       storage          = new RankListStorage(FilePath);
            List <RankListRecord> expectedCurrList = new List <RankListRecord>();

            expectedCurrList.Add(new RankListRecord(12, "Pesho"));
            expectedCurrList.Add(new RankListRecord(13, "Ivan"));
            expectedCurrList.Add(new RankListRecord(16, "somePlayer"));
            expectedCurrList.Add(new RankListRecord(19, "otherPlayer"));
            expectedCurrList.Add(new RankListRecord(20, "PlayerThree"));

            var actualCurrList = storage.CurrentRankList;

            storage.AddReccord(new RankListRecord(20, "PlayerThree"), false);
            storage.AddReccord(new RankListRecord(12, "Pesho"), false);
            storage.AddReccord(new RankListRecord(19, "otherPlayer"), false);
            storage.AddReccord(new RankListRecord(13, "Ivan"), false);
            storage.AddReccord(new RankListRecord(16, "somePlayer"), false);

            bool areEqual = true;

            for (int i = 0; i < actualCurrList.Count; i++)
            {
                if (actualCurrList[i].Name != expectedCurrList[i].Name || actualCurrList[i].Value != expectedCurrList[i].Value)
                {
                    areEqual = false;
                }
            }
            Assert.IsTrue(areEqual, "The result from AddRecord() is incorrect");
        }