public void SetValue_AssigningAPropertyOfTheSameType_ValueShouldBeSet() { var container = new StructWithPrimitives(); PropertyContainer.SetValue(ref container, nameof(StructWithPrimitives.Int32Value), 42); Assert.That(container.Int32Value, Is.EqualTo(42)); }
public void GetValue_WithInvalidName_ShouldThrow() { var container = new StructWithPrimitives(); Assert.Throws <InvalidPathException>(() => { PropertyContainer.GetValue <StructWithPrimitives, int>(ref container, "missing"); }); }
public void GetValue_WithNonConvertibleType_ShouldThrow() { var container = new StructWithPrimitives(); Assert.Throws <InvalidCastException>(() => { PropertyContainer.GetValue <StructWithPrimitives, StructWithNoFields>(ref container, nameof(StructWithPrimitives.Int32Value)); }); }
public void GetValue_WithPropertyOfTheSameType_ValueShouldBeReturned() { var container = new StructWithPrimitives { Int32Value = 42 }; var value = PropertyContainer.GetValue <StructWithPrimitives, int>(ref container, nameof(StructWithPrimitives.Int32Value)); Assert.That(value, Is.EqualTo(42)); }
public void PropertyVisitor_VisitingAStructWithPrimitiveFields_DoesNotAllocate() { var container = new StructWithPrimitives(); var visitor = new CountVisitor(); GCAllocTest.Method(() => { visitor.Count = 0; PropertyContainer.Visit(ref container, visitor); }) .ExpectedCount(0) .Warmup() .Run(); Assert.That(visitor.Count, Is.EqualTo(2)); }