public void ReturnWorkingSetters_ForEachPublicInstanceProperty() { // Arrange int i = 0; object[] expectedValues = { this.fixture.Create <int>(), this.fixture.Create <string>() }; TestPerson instance = new TestPerson(); IReadOnlyDictionary <string, IGetSetPair> expected = TestHelper.PersonPropertyAccesors .OrderBy(x => x.Key) .ToDictionary(x => x.Key, x => x.Value); // Act IReadOnlyDictionary <string, IGetSetPair> result = this.sut.GetPropertyAccessorFuncs(typeof(TestPerson)) .OrderBy(x => x.Key) .ToDictionary(x => x.Key, x => x.Value); // Assert Assert.That(() => result.Keys.Count() == expectedValues.Length); foreach (string key in result.Keys) { IGetSetPair actualFuncs = result[key]; actualFuncs.Set(instance, expectedValues[i]); object actualValue = expected[key].Get(instance); Assert.AreEqual(expectedValues[i], actualValue); i++; } }
public void ReturnWorkingGetters_ForEachPublicInstanceProperty() { // Arrange TestPerson instance = this.fixture.Create <TestPerson>(); IReadOnlyDictionary <string, IGetSetPair> expected = TestHelper.PersonPropertyAccesors; // Act IReadOnlyDictionary <string, IGetSetPair> result = this.sut.GetPropertyAccessorFuncs(typeof(TestPerson)); // Assert foreach (string key in expected.Keys) { IGetSetPair actualFuncs = result[key]; IGetSetPair expectedFuncs = expected[key]; Assert.AreEqual(expectedFuncs.Get(instance), actualFuncs.Get(instance)); } }
public IReadOnlyDictionary <string, IGetSetPair> GetPropertyAccessorFuncs(Type type) { type = type ?? throw new ArgumentNullException(nameof(type)); return(Cache.GetOrAdd("æ" + type.FullName, () => { var factories = new Dictionary <string, IGetSetPair>(); IEnumerable <PropertyInfo> props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => p.DeclaringType?.FullName != typeof(Indexed).FullName); foreach (PropertyInfo prop in props) { IGetSetPair functions = this.CompilePropertyMethods(prop); factories.Add(prop.Name, functions); } return factories; })); }