0

I've a class that has a IEnumerable<object> property:

interface ICore {

    IEnumerable<object> enumerable { get; }

}

I need to substitute the return values of this IEnumerable<object>. I've rtied with Returns, nevertheless, I'm getting a message telling me it's not available on an IEnumerable.

Any ideas?

Jordi
  • 20,868
  • 39
  • 149
  • 333

1 Answers1

3

NSubstitute works with the IEnumerable interface perfectly fine. Here's an example:

using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace NSubstitute.Acceptance.Specs.FieldReports
{
    [TestFixture]
    public class SO_42159342
    {
        public interface ICore
        {
            IEnumerable<object> Enumerable { get; }
        }

        [Test]
        public void Test()
        {
            var sub = Substitute.For<ICore>();
            sub.Enumerable.Returns(Enumerable.Empty<object>());
            sub.Enumerable.Returns(new List<object>());
            sub.Enumerable.Returns(_ => new[] {new object()});

            Assert.True(sub.Enumerable.Count() == 1);
        }
    }
}
Alexandr Nikitin
  • 7,258
  • 2
  • 34
  • 42