示例#1
0
        public void XmlSerializeSimpleTestClassDirectory_TestClassExists_FileExists()
        {
            // Arrange
            SimpleTestClassDirectory testClassDirectory = new SimpleTestClassDirectory
            {
                TestClasses = new System.Collections.Generic.List <SimpleTestClassWithoutAttributes>
                {
                    new SimpleTestClassWithoutAttributes()
                    {
                        HouseNumber = 4, StreetName = "Edlinger Str.", City = "Baierbarch"
                    },
                    new SimpleTestClassWithoutAttributes()
                    {
                        HouseNumber = 5, StreetName = "Simssee Straße", City = "Stephanskirchen"
                    }
                }
            };

            string fileName = this.applicationPath + "\\simpleTestClassDirectory.xml";

            // Act
            XmlSerializer.Serialize(testClassDirectory, fileName);

            // Assert
            Assert.IsTrue(File.Exists(fileName));

            // Cleanup
            File.Delete(fileName);
        }
        public void DeserializeTestFileWithMultipleEntries_FileAndObjectExists_FileIsDeserializedToObjectCorrectly()
        {
            // Arrange
            SimpleTestClassDirectory simpleTestClassDirectory = new SimpleTestClassDirectory();
            string fileName = this.applicationPath + "\\FileHandling\\TestFiles\\TestFileWithMultipleEntries.xml";

            // Act
            simpleTestClassDirectory = XmlDeserializer.Deserialize <SimpleTestClassDirectory>(fileName);

            SimpleTestClassWithoutAttributes firstElement  = simpleTestClassDirectory.TestClasses[0];
            SimpleTestClassWithoutAttributes secondElement = simpleTestClassDirectory.TestClasses[1];

            // Assert
            Assert.IsTrue(
                firstElement.City == "Baierbach" && secondElement.City == "Stephanskirchen",
                "The deserialized object contains the expected Data.");
        }