Skip to content

Request: Add support of indexers to the PropertyConstraint #2211

Closed
@Ch0senOne

Description

@Ch0senOne

At the moment it is only possible to test values of normal properties and no way to test indexer values. I need to write a test that looks something like this:

  [TestFixture]
  public class TestClass
  {
    class Example
    {
      private Dictionary<string, string> dictionary = new Dictionary<string, string>();

      public string this[string key]
      {
        get { return dictionary[key]; }
        set { dictionary[key] = value; }
      }
    }

    [Test]
    public void Test()
    {
      var obj = new Example
      {
        ["TEST1"] = "1",
        ["TEST2"] = "2",
      };

      Assert.That(obj, Has.Property("Item", "TEST1").EqualTo("1").And.Property("Item", "TEST2").EqualTo("2"));
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions