In addition, other answers point in the right direction, if you really need to test as you described, do the following:
Create a TestA class that inherits from A. Use this to make protected properties of B public to the test. if you have
class B { protected string Name {get; set;} } class A: B { public void DoSomething(string msg) { Name = msg.Trim(); } } class TestA: A { public string GetName() { return Name; } }
In your test now use TestA. I don't know the syntax of MsTest, but something like this:
[Test] public void TestThatNameWasSet() { TestA systemUnderTest = new TestA(); systemUnderTest.DoSomething(" new name "); Assert.That(systemUnderTest.GetName(), Is.EqualTo("new name"); }
source share