Example #1
0
        public object Clone()
        {
            var b = (Battle)MemberwiseClone();

            if (Details != null)
            {
                b.Details = (BattleDetails)Details.Clone();
            }
            if (Users != null)
            {
                b.Users = new List <UserBattleStatus>(Users);
            }
            if (Rectangles != null)
            {
                // copy the dictionary
                b.Rectangles = new Dictionary <int, BattleRect>();
                foreach (var kvp in Rectangles)
                {
                    b.Rectangles.Add(kvp.Key, kvp.Value);
                }
            }

            if (DisabledUnits != null)
            {
                b.DisabledUnits = new List <string>(DisabledUnits);
            }
            return(b);
        }
        public void test_object_clone_does_not_return_the_same_reference_object()
        {
            // Arrange
            var details = new Details {
                Input = "test1", Number = 57, additional = new AdditionalDetails {
                    DateOfBirth = new DateTime(1973, 5, 1)
                }
            };

            // Act
            var result = details.Clone();

            // Assert
            result.Should().NotBeSameAs(details);
        }
        public void test_object_clone_returns_an_equivalent_object()
        {
            // Arrange
            var details = new Details {
                Input = "test1", Number = 57, additional = new AdditionalDetails {
                    DateOfBirth = new DateTime(1973, 5, 1)
                }
            };

            // Act
            var result = details.Clone();

            // Assert
            result.Should().BeEquivalentTo(details);
        }