示例#1
0
        public void CollectionAsserts()
        {
            var somePersons = new Person[] { new Person(), new VipPerson() };

            // Some trivial collection asserts
            CollectionAssert.AllItemsAreNotNull(somePersons);
            CollectionAssert.Contains(somePersons, somePersons[0]);

            // Some more interesting checks
            CollectionAssert.AllItemsAreInstancesOfType(somePersons, typeof(Person));

            CollectionAssert.AllItemsAreUnique(somePersons);
            // CollectionAssert.AllItemsAreUnique(new [] { "A", "A" }); --> this would fail.

            var someStrings = new[] { "AB", "CD" };
            var someOtherStrings = new[] { $"{"A"}B", "CD" };
            var evenMoreStrings = new[] { "CD", $"{"A"}B" };
            CollectionAssert.AreEqual(someStrings, someOtherStrings);
            // CollectionAssert.AreEqual(someStrings, evenMoreStrings); -> this would fail

            // Note that AreEquivalent ignores order, so this works:
            CollectionAssert.AreEquivalent(someStrings, evenMoreStrings);

            CollectionAssert.IsSubsetOf(new[] { "AB" }, someStrings);
        }
        public void Map_ClassDifferentCollections_Success()
        {
            TinyMapper.Bind<Person, PersonDto>();

            var source = new Person
            {
                Contacts = new List<Contact>
                {
                    new Contact
                    {
                        Int = 1,
                        String = "2"
                    }
                }
            };

            var actual = TinyMapper.Map<PersonDto>(source);

            Assert.Equal(source.Contacts.Count, actual.Contacts.Count);
            for (int i = 0; i < source.Contacts.Count; i++)
            {
                Contact expectedItem = source.Contacts[i];
                ContactDto actualItem = actual.Contacts[i];

                Assert.Equal(expectedItem.Int, actualItem.Int);
                Assert.Equal(expectedItem.String, actualItem.String);
            }
        }