예제 #1
0
        public void PropertyTests()
        {
            string[]  array  = { "abc", "bca", "xyz", "qrs" };
            string[]  array2 = { "a", "ab", "abc" };
            ArrayList list   = new ArrayList(array);

            // Not available using the classic syntax

            // Helper syntax
            Ensure.That(list, Has.Property("Count"));
            Ensure.That(list, Has.No.Property("Length"));

            Ensure.That("Hello", Has.Property("Length", 5));
            Ensure.That("Hello", Has.Length(5));
            Ensure.That("Hello", Has.Property("Length").EqualTo(5));
            Ensure.That("Hello", Has.Property("Length").GreaterThan(3));

            Ensure.That(array, Has.Property("Length", 4));
            Ensure.That(array, Has.Length(4));
            Ensure.That(array, Has.Property("Length").LessThan(10));

            Ensure.That(array, Has.All.Property("Length", 3));
            Ensure.That(array, Has.All.Length(3));
            Ensure.That(array, Is.All.Length(3));
            Ensure.That(array, Has.All.Property("Length").EqualTo(3));
            Ensure.That(array, Is.All.Property("Length").EqualTo(3));

            Ensure.That(array2, Has.Some.Property("Length", 2));
            Ensure.That(array2, Has.Some.Length(2));
            Ensure.That(array2, Has.Some.Property("Length").GreaterThan(2));

            Ensure.That(array2, Is.Not.Property("Length", 4));
            Ensure.That(array2, Is.Not.Length(4));
            Ensure.That(array2, Has.No.Property("Length").GreaterThan(3));

            Ensure.That(List.Map(array2).Property("Length"), Is.EqualTo(new int[] { 1, 2, 3 }));
            Ensure.That(List.Map(array2).Property("Length"), Is.EquivalentTo(new int[] { 3, 2, 1 }));
            Ensure.That(List.Map(array2).Property("Length"), Is.SubsetOf(new int[] { 1, 2, 3, 4, 5 }));
            Ensure.That(List.Map(array2).Property("Length"), Is.Unique);

            Ensure.That(list, Has.Count(4));

            // Inherited syntax
            EnsuranceHelper.Expect(list, Property("Count"));
            EnsuranceHelper.Expect(list, Not.Property("Nada"));

            EnsuranceHelper.Expect("Hello", Property("Length", 5));
            EnsuranceHelper.Expect("Hello", Length(5));
            EnsuranceHelper.Expect("Hello", Property("Length").EqualTo(5));
            EnsuranceHelper.Expect("Hello", Property("Length").GreaterThan(0));

            EnsuranceHelper.Expect(array, Property("Length", 4));
            EnsuranceHelper.Expect(array, Length(4));
            EnsuranceHelper.Expect(array, Property("Length").LessThan(10));

            EnsuranceHelper.Expect(array, All.Property("Length", 3));
            EnsuranceHelper.Expect(array, All.Length(3));
            EnsuranceHelper.Expect(array, All.Property("Length").EqualTo(3));

            EnsuranceHelper.Expect(array2, Some.Property("Length", 2));
            EnsuranceHelper.Expect(array2, Some.Length(2));
            EnsuranceHelper.Expect(array2, Some.Property("Length").GreaterThan(2));

            EnsuranceHelper.Expect(array2, None.Property("Length", 4));
            EnsuranceHelper.Expect(array2, None.Length(4));
            EnsuranceHelper.Expect(array2, None.Property("Length").GreaterThan(3));

            EnsuranceHelper.Expect(new ListMapper(array2).Property("Length"), EqualTo(new int[] { 1, 2, 3 }));
            EnsuranceHelper.Expect(new ListMapper(array2).Property("Length"), EquivalentTo(new int[] { 3, 2, 1 }));
            EnsuranceHelper.Expect(new ListMapper(array2).Property("Length"), SubsetOf(new int[] { 1, 2, 3, 4, 5 }));
            EnsuranceHelper.Expect(new ListMapper(array2).Property("Length"), Unique);

            EnsuranceHelper.Expect(list, Count(4));
        }