I am doing some research. I want to use moq and pass it to the MVC to allow it to set some values ββin the session. I wrote code to find out if it is possible to "open" a property without a setter. I just donβt know if this is possible ...
The following code was my attempt to set the witn no setter property!
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Moq; namespace TestMoq { class Program { static void Main(string[] args) { var mock = new Mock<TestClass>(); mock.SetupProperty(f => f.VarWithNoSetter); mock.Object.VarWithNoSetter = "Set"; Console.WriteLine(mock.Object.VarWithNoSetter); Console.ReadLine(); } } public class TestClass { private string _varWithNoSetter; public string VarWithNoSetter { get { return _varWithNoSetter; } } public TestClass() { } } }
source share