예제 #1
0
        public void it_should_serialize_and_deserialize_the_Person_object()
        {
            var ser = new XmlSerializer(typeof(Person));
            var stream = new MemoryStream();
            var dataManager = new DataRepositoryDummy();
            var people = dataManager.GetPeopleWithPets();
            var person = people.First(x => x.Name.ToLower() == "jpol");

            // person.Nickname = "octopus";

            ser.Serialize(stream, person);
            var xml = UTF8Encoding.UTF8.GetString(stream.ToArray());
            xml.Should().NotBeBlank();
            Console.WriteLine(xml);

            stream.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(stream);
            var xmlRead = reader.ReadToEnd();
            xml.Should().Be(xmlRead);

            stream.Seek(0, SeekOrigin.Begin);
            var deserializedPerson = ser.Deserialize(new StreamReader(stream)) as Person;
            deserializedPerson.Should().NotBeNull();
            deserializedPerson.Name.Should().Be(person.Name);
        }
예제 #2
0
        public void TestingSelectMany()
        {
            // cross joins

            var d = new DataRepositoryDummy();
            var pets = d.GetPets();
            var people = d.GetPeopleWithPets();

            var q = from pet in pets
                    from person in people
                    select new { Person = person, Pet = pet };
            q.Should().HaveCount(24);

            var q1 = pets.SelectMany(x => people, (pet, person) => new { Pet = pet, Person = person });
            q1.Should().HaveCount(24);
        }