Esempio n. 1
0
        public void WithReadonlyImmutableThrows(ReferenceHandling referenceHandling)
        {
            var expected = this is FieldValues.Throws
                ? "Copy.FieldValues(x, y) failed.\r\n" +
                           "The readonly field WithReadonlyProperty<Immutable>.<Value>k__BackingField differs after copy.\r\n" +
                           " - Source value (Immutable): Gu.State.Tests.CopyTests.CopyTypes+Immutable.\r\n" +
                           " - Target value (Immutable): Gu.State.Tests.CopyTests.CopyTypes+Immutable.\r\n" +
                           "Solve the problem by any of:\r\n" +
                           "* Use FieldsSettings and specify how copying is performed:\r\n" +
                           "  - ReferenceHandling.Structural means that a the entire graph is traversed and immutable property values are copied.\r\n" +
                           "    - For structural Activator.CreateInstance is used to create instances so a parameterless constructor may be needed, can be private.\r\n" +
                           "  - ReferenceHandling.References means that references are copied.\r\n" +
                           "  - Exclude a combination of the following:\r\n" +
                           "    - The field WithReadonlyProperty<Immutable>.<Value>k__BackingField.\r\n"

                  : "Copy.PropertyValues(x, y) failed.\r\n" +
                           "The readonly property WithReadonlyProperty<Immutable>.Value differs after copy.\r\n" +
                           " - Source value (Immutable): Gu.State.Tests.CopyTests.CopyTypes+Immutable.\r\n" +
                           " - Target value (Immutable): Gu.State.Tests.CopyTests.CopyTypes+Immutable.\r\n" +
                           "Solve the problem by any of:\r\n" +
                           "* Use PropertiesSettings and specify how copying is performed:\r\n" +
                           "  - ReferenceHandling.Structural means that a the entire graph is traversed and immutable property values are copied.\r\n" +
                           "    - For structural Activator.CreateInstance is used to create instances so a parameterless constructor may be needed, can be private.\r\n" +
                           "  - ReferenceHandling.References means that references are copied.\r\n" +
                           "  - Exclude a combination of the following:\r\n" +
                           "    - The property WithReadonlyProperty<Immutable>.Value.\r\n";

            var source = new WithReadonlyProperty <Immutable>(new Immutable(1));
            var target = new WithReadonlyProperty <Immutable>(new Immutable(2));

            var exception = Assert.Throws <InvalidOperationException>(() => this.CopyMethod(source, target, referenceHandling));

            Assert.AreEqual(expected, exception.Message);
        }
Esempio n. 2
0
        public void WithReadonlyGuid(string xv, string yv, bool expected)
        {
            var x      = new WithReadonlyProperty <Guid>(Guid.Parse(xv));
            var y      = new WithReadonlyProperty <Guid>(Guid.Parse(yv));
            var result = this.EqualMethod(x, y, ReferenceHandling.Structural);

            Assert.AreEqual(expected, result);
        }
Esempio n. 3
0
        public void WithReadonlyComplex(string xv, string yv, bool expected)
        {
            var x      = new WithReadonlyProperty <ComplexType>(new ComplexType(xv, 1));
            var y      = new WithReadonlyProperty <ComplexType>(new ComplexType(yv, 1));
            var result = this.EqualMethod(x, y, ReferenceHandling.Structural);

            Assert.AreEqual(expected, result);
        }
Esempio n. 4
0
        public void WithReadonlyHappyPath()
        {
            var x = new WithReadonlyProperty <int>(1);
            var y = new WithReadonlyProperty <int>(1);

            this.CopyMethod(x, y);
            Assert.AreEqual(1, x.Value);
            Assert.AreEqual(1, y.Value);
        }
Esempio n. 5
0
        public void WithReadonlyComplex()
        {
            var source = new WithReadonlyProperty <ComplexType>(new ComplexType("a", 1));
            var target = new WithReadonlyProperty <ComplexType>(new ComplexType("b", 2));

            this.CopyMethod(source, target, ReferenceHandling.Structural);
            Assert.AreEqual("a", source.Value.Name);
            Assert.AreEqual("a", target.Value.Name);
            Assert.AreEqual(1, source.Value.Value);
            Assert.AreEqual(1, target.Value.Value);
        }
Esempio n. 6
0
        public void WithReadonlyIntHappyPath(int xv, int yv, ReferenceHandling?referenceHandling, bool expected)
        {
            var x = new WithReadonlyProperty <int>(xv);
            var y = new WithReadonlyProperty <int>(yv);

            if (referenceHandling == null)
            {
                var result = this.EqualMethod(x, y);
                Assert.AreEqual(expected, result);
            }
            else
            {
                var result = this.EqualMethod(x, y, referenceHandling.Value);
                Assert.AreEqual(expected, result);
            }
        }
Esempio n. 7
0
        public void WithReadonlyComplex(string xv, string yv, string expected)
        {
            expected = expected?.Replace(
                "<member1>",
                this is FieldValues.Classes
                    ? "<Value>k__BackingField"
                    : "Value")
                       .Replace(
                "<member2>",
                this is FieldValues.Classes
                                        ? "name"
                                        : "Name");
            var x      = new WithReadonlyProperty <ComplexType>(new ComplexType(xv, 1));
            var y      = new WithReadonlyProperty <ComplexType>(new ComplexType(yv, 1));
            var result = this.DiffMethod(x, y, ReferenceHandling.Structural);

            Assert.AreEqual(expected, result.ToString(string.Empty, " "));
        }
Esempio n. 8
0
        public void WithReadonlyIntHappyPath(int xv, int yv, ReferenceHandling?referenceHandling, string expected)
        {
            expected = expected?.Replace(
                "<member>",
                this is FieldValues.Classes
                    ? "<Value>k__BackingField"
                    : "Value");
            var x = new WithReadonlyProperty <int>(xv);
            var y = new WithReadonlyProperty <int>(yv);

            if (referenceHandling == null)
            {
                var result = this.DiffMethod(x, y);
                Assert.AreEqual(expected, result.ToString(string.Empty, " "));
            }
            else
            {
                var result = this.DiffMethod(x, y, referenceHandling.Value);
                Assert.AreEqual(expected, result.ToString(string.Empty, " "));
            }
        }