public void ShouldThrowException_WhenExtractFunctionReturnsUnsupportedType() { // Arrange var value = new ComplexTestClass(); var immutable = new Immutable <ComplexTestClass>(value); // Act Action result = () => immutable.Extract(i => i.LotsOfInts.Where(l => l > 100)); // Assert result.Should().Throw <InvalidOperationException>().WithMessage("*- Unable to clone interfaces. Use concrete types and implementations instead."); }
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 ShouldReturnValueOfPropertySelectByFunction_WhenCalled() { // Arrange var value = new ComplexTestClass(); var immutable = new Immutable <ComplexTestClass>(value); // Act var result = immutable.Extract(i => i.Things); // Assert result.Should().BeEquivalentTo(value.Things); }
public void ShouldReturnClonedValue_WhenCalled() { // Arrange var value = new ComplexTestClass(); var immutable = new Immutable <ComplexTestClass>(value); // Act var result = immutable.Extract(i => i.Things); result.Prop1 = 75; // Assert value.Things.Prop1.Should().NotBe(75); }