public void MemberWiseDeepClone_Test_2() { //Arrange AirlineCompany airCompany = new AirlineCompany("Momola Airlines", 12555, "here_must_be_64base_string_immage", "fhf53dg5525", "aAS23", 12565); Administrator admin = new Administrator("John", "65df56dfd56f", 7254, airCompany); Customer customer = new Customer("Nadgad", "Konstantinski", "not a house nor a street", "22333222356", "355-353-530", "image_image_where_are_you", "sdf54sf54sdf", 4587); Flight flight = new Flight { AIRLINECOMPANY_ID = 1, DEPARTURE_TIME = DateTime.Now, DESTINATION_COUNTRY_CODE = 123, ID = 21, IDENTIFIER = "sg546rfgv54fgv54", LANDING_TIME = DateTime.Now.AddDays(5).AddHours(8).AddMinutes(55), ORIGIN_COUNTRY_CODE = 446, REMAINING_TICKETS = 568 }; Country country = new Country { COUNTRY_NAME = "Bolivia", ID = 658, IDENTIFIER = "fgb52df54dg54dgv", admin = admin }; CheckingObject checkingObj = new CheckingObject(customer, flight, country); CompositeObject original = new CompositeObject(admin, airCompany, checkingObj); checkingObj.composite = original; original.checking = checkingObj; //Act CompositeObject clonedObject = original.MemberWiseDeepClone(); var deepCloned = clonedObject; var shallowCloned = original.SimpleMemberWiseClone(); //Assert Assert.IsNotNull(deepCloned); Assert.IsFalse(ReferenceEquals(original, deepCloned)); Assert.That(original.AirCompany == deepCloned.AirCompany); Assert.AreEqual(original.AirCompany, deepCloned.AirCompany); string str = string.Empty; var originalFields = original.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Instance); var deepClonedFields = deepCloned.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Instance); Assert.AreEqual(originalFields.Length, deepClonedFields.Length); for (int i = 0; i < originalFields.Length; i++) { str += $"{originalFields[i].Name}: {originalFields[i].GetValue(original)}"; //Assert.AreEqual(originalFields[i].GetValue(original), deepClonedFields[i].GetValue(deepCloned)); } var originalAdministrator = original.GetType().GetField("_administrator", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Instance).GetValue(original); var deepClonedAdministrator = deepCloned.GetType().GetField("_administrator", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Instance).GetValue(deepCloned); Assert.AreEqual(originalAdministrator, deepClonedAdministrator); Assert.AreEqual(original.CheckingObject.composite.AirCompany, deepCloned.CheckingObject.composite.AirCompany); //Failing the test //Assert.AreEqual(original.CheckingObject, deepCloned.CheckingObject); }
public void UnsetValue(CompositeObject obj) { if (_wasSet) { var propToUnset = PropertyManager.Instance.GetProperties(obj.GetType()) .FirstOrDefault(p => p.PropName == Property); obj.SetValue(propToUnset, Value); _oldValue = CompositeObjectProperty.UnsetValue; _wasSet = false; } }
public bool Matches(CompositeObject obj) { if (_typeName is not null) { if (!_classes.Any() || obj is not IStylable stylable) { return(obj.GetType().Name == _typeName); } return(MatchClasses(stylable)); } return(false); }
public bool TryAttach(CompositeObject obj) { bool attached = false; var props = PropertyManager.Instance.GetProperties(obj.GetType()); foreach (var setter in Setters.Where(s => props.Any(p => p.PropName == s.Property))) { setter.SetValue(obj); attached = true; } return(attached); }
public void SetValue(CompositeObject obj) { var propToSet = PropertyManager.Instance.GetProperties(obj.GetType()) .FirstOrDefault(p => p.PropName == Property); if (propToSet is null) { throw new Exception(); } _wasSet = obj.IsPropertySet(propToSet); if (_wasSet) { _oldValue = obj.GetValue <IPropertyValue>(propToSet); } obj.SetValue(propToSet, Value); }