public void it_should_return_all_values_from_the_original_collection_except_the_values_contained_in_the_second_collection()
        {
            var secretUsers = new[] { "Paul", "Jhon" };
            var allUsers = new DataRepositoryDummy().GetPeopleWithPets().ToList();

            allUsers.Add(new Person { Age = 12, LanguagesSpoken = Enumerable.Empty<Language>(), Name = "Jhon" });

            var q = allUsers.Select(x => x.Name).Distinct().Except(secretUsers);
            q.Should().HaveCount(3);
            q.Should().OnlyHaveUniqueItems();

            // alternate example 1
            var q1 = (from u in allUsers
                      from s in secretUsers
                      where u.Name == s
                      select u).Distinct();
            var q11 = allUsers.Except(q1);
            q11.Should().HaveCount(3);
            q11.Should().OnlyHaveUniqueItems();

            // alternate example 2 - does not work
            //var q2 = (from u in allUsers
            //          from s in secretUsers
            //          where u.Name != s
            //          select u).Distinct();
            //q2.Should().HaveCount(3);
            //q2.Should().OnlyHaveUniqueItems();
        }
        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);
        }
Example #3
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);
        }