示例#1
0
		public void Should_allow_starting_at_another_index()
		{
			var strings = new[] {"A", "B", "C"};

			var result = strings.Index(47, (x,i) => new { Index = i, Value = x});

			Assert.IsNotNull(result);

			var resultArray = result.ToArray();

			Assert.AreEqual(strings.Length, resultArray.Length);

			Assert.AreEqual(resultArray[0].Index, 47);
			Assert.AreEqual(resultArray[1].Index, 48);
		}
示例#2
0
		public void Should_return_an_indexed_enumeration_of_a_new_type()
		{
			var strings = new[] {"A", "B", "C"};

			var result = strings.Index((x,i) => new { Index = i, Value = x});

			Assert.IsNotNull(result);

			var resultArray = result.ToArray();

			Assert.AreEqual(strings.Length, resultArray.Length);

			Assert.AreEqual(resultArray[0].Index, 0);
			Assert.AreEqual(resultArray[1].Index, 1);
		}
示例#3
0
        public void StringRepresentations()
        {
            var infos = from member in new[] { null, "foo" }
                        from file in new[] { null, "bar" }
                        from line in new[] { 0, 42 }
                        select new CallerInfo(member, file, line);

            var expectations = new[]
            {
                "<?member>@<?filename>:0",
                "<?member>@<?filename>:42",
                "<?member>@bar:0",
                "<?member>@bar:42",
                "foo@<?filename>:0",
                "foo@<?filename>:42",
                "foo@bar:0",
                "foo@bar:42",
            };

            var assertions = // TODO Zip instead of joining when on .NET 4
                from info in infos.Index()
                join exp in expectations.Index() on info.Key equals exp.Key
                orderby info.Key
                select new
                {
                    Expected = exp.Value,
                    Actual   = info.Value.ToString(),
                };

            foreach (var a in assertions)
                Assert.Equal(a.Expected, a.Actual);
        }