Пример #1
0
    public override void Begin()
    {
        Level.BackgroundColor = Color.Gray;

        //MessageDisplay.Position = new Vector(100, 100);
        MessageDisplay.MaxMessageCount = (int)(Screen.Height / Font.Default.CharacterHeight - 1);
        MessageDisplay.BackgroundColor = Color.Transparent;
        MessageDisplay.MessageTime     = TimeSpan.MaxValue;
        MessageDisplay.RealTime        = true;
        MessageDisplay.TextColor       = Color.LightGray;

        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, null);
        PhoneBackButton.Listen(Exit, null);

        StorageFile tiedosto = null;

        try
        {
            DataStorage.Delete("testi.txt");

            tiedosto = DataStorage.Create("testi.txt");
            Assert(tiedosto.Name.EndsWith("testi.txt"), "tiedosto.Name.EndsWith(\"testi.txt\")");
            AssertNotNull(tiedosto.Stream, "tiedosto.Stream");
            tiedosto.Close();

            Assert(DataStorage.Exists("testi.txt"), "DataStorage.Exists(\"testi.txt\")");

            tiedosto = DataStorage.Open("testi.txt", false);
            Assert(tiedosto.Name.EndsWith("testi.txt"), "tiedosto.Name.EndsWith(\"testi.txt\")");
            AssertNotNull(tiedosto.Stream, "tiedosto.Stream");
            Assert(!tiedosto.Stream.CanWrite, "!tiedosto.Stream.CanWrite");
            tiedosto.Close();

            DataStorage.Delete("testi.txt");
            Assert(!DataStorage.Exists("testi.txt"), "!DataStorage.Exists(\"testi.txt\")");

            MessageDisplay.Add("---");

            DataStorage.MkDir("kansio");
            Assert(DataStorage.Exists("kansio"), "DataStorage.Exists(\"kansio\")");
            Assert(DataStorage.ChDir("kansio") == true, "DataStorage.ChDir( \"kansio\" ) == true");
            AssertValue(DataStorage.GetFileList().Count, 0, "DataStorage.GetFileList().Count");
            Assert(DataStorage.Exists("kansio") == false, "DataStorage.Exists(\"kansio\") == false");
            Assert(DataStorage.ChDir("..") == true, "DataStorage.ChDir( \"..\" ) == true");
            Assert(DataStorage.Exists("kansio") == true, "DataStorage.Exists(\"kansio\") == true");
            DataStorage.RmDir("kansio");

            Assert(DataStorage.Exists("kansio") == false, "DataStorage.Exists(\"kansio\") == false");
            Assert(DataStorage.ChDir("kansio") == false, "DataStorage.ChDir( \"kansio\" ) == false");

            DataStorage.Delete("topten.xml");
            Assert(!DataStorage.Exists("topten.xml"), "!DataStorage.Exists(\"topten.xml\")");
            ScoreList score = new ScoreList();
            score.Add("sata", 100);
            score.Add("yksi", 1);
            score.Add("kaksi", 2);
            DataStorage.Save(score, "topten.xml");
            Assert(DataStorage.Exists("topten.xml"), "DataStorage.Exists(\"topten.xml\")");

            ScoreList score2 = new ScoreList();
            score2 = DataStorage.Load(score2, "topten.xml");
            Assert(score2.Equals(score), "score2.Equals( score )");

            MessageDisplay.Add("---");
            MessageDisplay.Add("PASSED!", Color.LimeGreen);
        }
        catch (TestException)
        {
            MessageDisplay.Add("---");
            MessageDisplay.Add("FAILED!", Color.Red);
        }
        finally
        {
            if (tiedosto != null && tiedosto.Stream.CanRead)
            {
                tiedosto.Close();
            }

            DataStorage.Delete("testi.txt");
            DataStorage.Delete("topten.xml");
        }
    }