Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing an inheriting C# class

I have the following code in c♯ but can not work out how to test it; I need to test aMethodUnderTest. I can not change ABaseClass as it is in a library. But if I am to test AClass I need to be able to set what theThing returns. Does anyone have any ideas, or experience with this type of code testing?

public ABaseClass
{
  protected ThingBaseClass theThing {get;}
  public virtual ....
  ...
}


public AClassUnderTest : ABaseClass
{
  public MyThing Thing
  {
    get
    {
      return (MyThing)base.theThing;
    }
  }

  public void aMethedUnderTest()
  {
    Thing.doSomething();
  }
}

Note: The initial value of theThing is null. theThing has no public setter.

like image 746
ctrl-alt-delor Avatar asked Apr 23 '26 01:04

ctrl-alt-delor


1 Answers

I think you can create mock that inherits ABaseClass and then check if AClass.Thing returns the same result as ABaseClassMock.theThing

like image 68
Denis Palnitsky Avatar answered Apr 25 '26 13:04

Denis Palnitsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!