public void ShouldNotAffectTheImmutable_WhenExtractFunctionTriesToAssign() { // Arrange var value = new ComplexTestClass(); var immutable = new Immutable <ComplexTestClass>(value); // Act var result = immutable.Extract(i => { i.Name = "My Name"; return(i.Things); }); // Assert immutable.Value("Name").As <string>().Should().BeNull(); }
public void ShouldThrowException_WhenPropertyIsNotAValueType() { // Arrange var value = new ComplexTestClass(); var immutable = new Immutable <ComplexTestClass>(value); // Act Action result = () => immutable.Value("Things"); // Assert result.Should().Throw <ArgumentException>().WithMessage("Property 'Things' is not a immutable value type."); }
public void ShouldReturnValue_WhenPropertyExistsAndIsAValueType() { // Arrange var value = new ComplexTestClass(); var immutable = new Immutable <ComplexTestClass>(value); // Act var result = immutable.Value("Id"); // Assert result.Should().Be(value.Id); }
public void ShouldThrowException_WhenPropertyDoesNotExist() { // Arrange var value = new ComplexTestClass(); var immutable = new Immutable <ComplexTestClass>(value); // Act Action result = () => immutable.Value("Thing"); // Assert result.Should().Throw <ArgumentException>().WithMessage("Property 'Thing' does not exist on this object."); }
public async Task Do(Immutable <RequestProcessingAction> action) { await action.Value(); }