public void Immutable_When_CreatingFromBuilder_TheResultIsCached()
        {
            var builder = new MyImmutableEntity.Builder
            {
                MyField1 = 42
            };

            var r1 = builder.ToImmutable();
            var r2 = builder.ToImmutable();

            r1.Should().NotBeNull();
            r1.MyField1.Should().Be(42);
            r1.Should().BeSameAs(r2);
        }
Пример #2
0
        public void Immutable_When_CreatingABuilderFromExisting_And_NoChanges_Then_ReferenceIsSame()
        {
            MyImmutableEntity original = new MyImmutableEntity.Builder
            {
                MyField1 = 42
            };

            var builder     = new MyImmutableEntity.Builder(original);
            var newInstance = builder.ToImmutable();

            newInstance.Should().BeSameAs(original);
        }