I'm trying to unit test a method where a property is non-virtual, and there are two layers of inheritance - therefore I can not create a mock. I've created a fake, however for some reason the property value is still empty.
public class Cart {
public string Currency { get; set; } // I'm trying to override this
}
// My fake class
public class CartFake : Cart
{
public new string Currency { // This should hide SomeBaseBase.Cart.Currency - but it does not
get { return "USD"; }
set { value = "USD"; }
}
}
public abstract class SomeBaseBase {
public virtual Cart Cart { get; set; }
}
public class Base : SomeBaseBase {
public string OtherProperties { get; set; }
}
// class under test
public class SomeClassFake : Base {
public override Cart Cart => new CartFake();
// Then when test is running I have this
var currency = Cart.Currency // returns "" - when debugging I see two "Currency" properties and currency gets populated with ""
}
For some reason when the test is running I see two Currency properties and var currency = gets currency "" instead of "USD"
why is that? how can I make it so that USD is populated?
EDIT:
public class CartFake : Cart
{
public CartFake() : base()
{
Currency = "USD";
}
}
For some reason line: Cart.Currency is still empty :(