public void StructWithoutOperatorsAlwaysRecreatesObjectWithoutValue() { var s1 = new SomeStructWithMultipleFields(1, 2); var v1 = ImmutableWithComplexStructField.Create(someStructField: s1); var v2 = v1.With(); // omit the struct value altogether Assert.Same(v1, v2); }
public void StructWithoutOperatorsAlwaysRecreatesObjectWithChangedValue() { var originalStruct = new SomeStructWithMultipleFields(5, 0); var structWithModifiedSecondField = new SomeStructWithMultipleFields(5, 1); var v1 = ImmutableWithComplexStructField.Create(someStructField: originalStruct); var v2 = v1.With(someStructField: structWithModifiedSecondField); Assert.Equal(structWithModifiedSecondField.Field2, v2.SomeStructField.Field2); }
public void StructWithoutOperatorsAlwaysRecreatesObjectWithSameValue() { var s1 = new SomeStructWithMultipleFields(1, 2); var v1 = ImmutableWithComplexStructField.Create(someStructField: s1); var v2 = v1.With(someStructField: s1); // The object should have been recreated since equality between the two struct values // cannot be determined without their operator defined. Assert.NotSame(v1, v2); Assert.Equal(s1.Field1, v2.SomeStructField.Field1); }