I have an interface ITransaction as follows:
public interface ITransaction {
DateTime EntryTime { get; }
DateTime ExitTime { get; }
}
and I have a derived class PaymentTransaction as follows:
public class PaymentTransaction : ITransaction {
public virtual DateTime LastPaymentTime
{
get { return DateTime.Now; }
}
#region ITransaction Members
public DateTime EntryTime
{
get { throw new NotImplementedException(); }
}
public DateTime ExitTime
{
get { throw new NotImplementedException(); }
}
#endregion
}
I wanted to Mock all three properties of PaymentTransaction Object.
I have tried the following, but it doesnt work:
var mockedPayTxn = new Mock<PaymentTransaction>();
mockedPayTxn.SetUp(pt => pt.LastPaymentTime).Returns(DateTime.Now); // This works
var mockedTxn = mockedPayTxn.As<ITransaction>();
mockedTxn.SetUp(t => t.EntryTime).Returns(DateTime.Today);
mockedTxn.SetUp(t => t.ExitTime).Returns(DateTime.Today);
but when I inject
(mockedTxn.Object as PaymentTransaction)
in the method I am testing (as it is only takes a PaymentTransaction and not ITransaction, I can't change it either) the debugger shows null reference for entry time and exit time.
I was wondering if someone could help me please.
Thanks in anticipation.