コード例 #1
0
        public void Test_Fruits_Deserialization_Method()
        {
            FruitsHelper.CreateFruitsTestData();
            FruitsHelper.FruitsSerialization();
            using (StringWriter writer = new StringWriter())
            {
                Console.SetOut(writer);

                FruitsHelper.FruitsDeserialization();

                string expected =
                    "Fruit Apple and it's colour Red\r\n" +
                    "Fruit Banana and it's colour Yellow\r\n" +
                    "Fruit Pineapple and it's colour Yellow\r\n" +
                    "Citrus Pomelo, it's color Green and the amount of vitamin C 2\r\n" +
                    "Citrus Lemon, it's color Yellow and the amount of vitamin C 3\r\n" +
                    "Citrus Mandarin, it's color Orange and the amount of vitamin C 1\r\n";

                string actual = writer.ToString();

                Assert.AreEqual(expected, actual);

                writer.Close();
            }
        }
コード例 #2
0
        public void Catch_Exception_Create_Fruits_Data_From_Console_Method()
        {
            using (StringReader fruitreader = new StringReader(string.Format("{1}{0}{2}{0}",
                                                                             Environment.NewLine, null, null)))
            {
                Console.SetIn(fruitreader);

                Assert.Throws <NullReferenceException>(() => FruitsHelper.CreateFruitsDataFromConsole());
            }
        }
コード例 #3
0
        public void Test_Print_Yellow_Fruits_Method()
        {
            FruitsHelper.CreateFruitsTestData();
            using (StringWriter writer = new StringWriter())
            {
                Console.SetOut(writer);

                FruitsHelper.PrintYellowFruit();

                string expected =
                    "Fruit Banana and it's colour Yellow\r\n" +
                    "Fruit Pineapple and it's colour Yellow\r\n" +
                    "Citrus Lemon, it's color Yellow and the amount of vitamin C 3\r\n";

                string actual = writer.ToString();

                Assert.AreEqual(expected, actual);

                writer.Close();
            }
        }