public void Should_handle_nested_types()
        {
            var message = new HeftyMessage
                {
                    Int = 47,
                    Long = 8675309,
                    Dub = 3.14159,
                    Flt = 1.234f,
                    Boo = true,
                    Now = new DateTime(2010, 3, 1)
                };

            var parentMessage = new ParentClass {Body = message};

            string text = _serializer.Serialize(parentMessage);

            text.ShouldEqual(@"---
            Body:
            Boo:true
            Dub:3.14159
            Flt:1.234
            Int:47
            Long:8675309
            Now:2010-03-01

            ...");
        }
		public void FieldAccessTest()
		{
			int privateFieldValue = _invoker.Fields["_privateField"].GetValue<int>();
			Assert.AreEqual(_fooValue, privateFieldValue);

			ParentClass parentClass = new ParentClass();
			NuGenInvoker invoker = new NuGenInvoker(parentClass);

			NuGenFieldInfo privateFieldInfo = invoker.Fields["privateField"];
			Assert.IsNotNull(privateFieldInfo);
		}
Example #3
0
    public void ConfigReifier_NestedDict_UpdatesInPlaceStructs()
    {
        var o = new ParentClass();

        o.nestedStructDict            = new Dictionary <string, ChildStruct>();
        o.nestedStructDict["dictKey"] = new ChildStruct {
            childIntKey = 11, childFloatKey = 6.54f
        };
        UpdateFromString(ref o, @"---
            nestedStructDict:
                dictKey:
                    childIntKey: 110
            ");
        Assert.AreEqual(o.nestedStructDict.Count, 1);
        Assert.AreEqual(o.nestedStructDict["dictKey"].childIntKey, 110);
        Assert.AreEqual(o.nestedStructDict["dictKey"].childFloatKey, 6.54f);
    }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbCard"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="checkId">if set to <c>true</c> [check id].</param>
        /// <param name="parentClass">The parent class.</param>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public DbCard(int id, bool checkId, ParentClass parentClass)
        {
            parent = parentClass;

            if (checkId)
            {
                connector.CheckCardId(id);
            }
            this.id = id;

            question            = new DbWords(id, Side.Question, WordType.Word, Parent.GetChildParentClass(this));
            questionExample     = new DbWords(id, Side.Question, WordType.Sentence, Parent.GetChildParentClass(this));
            questionDistractors = new DbWords(id, Side.Question, WordType.Distractor, Parent.GetChildParentClass(this));
            answer            = new DbWords(id, Side.Answer, WordType.Word, Parent.GetChildParentClass(this));
            answerExample     = new DbWords(id, Side.Answer, WordType.Sentence, Parent.GetChildParentClass(this));
            answerDistractors = new DbWords(id, Side.Answer, WordType.Distractor, Parent.GetChildParentClass(this));
        }
Example #5
0
    public void ConfigReifier_NestedDict_RemovesMissingPairs()
    {
        var o = new ParentClass();

        o.nestedDict            = new Dictionary <string, TestClass>();
        o.nestedDict["dictKey"] = new TestClass {
            intKey = 200, floatKey = 10099.2f
        };
        UpdateFromString(ref o, @"---
            nestedDict:
                newKey:
                    intKey: 999
            ");
        Assert.AreEqual(o.nestedDict.Count, 1);
        Assert.IsFalse(o.nestedDict.ContainsKey("dictKey"));
        Assert.AreEqual(o.nestedDict["newKey"].intKey, 999);
    }
        public void CanDisposeFactoryWhenDependentObjectCallsFactoryInDispose()
        {
            AbstractObjectFactory factory = CreateObjectFactory(false);

            ConfigureObjectFactory(factory as IObjectDefinitionRegistry);

            ParentClass parent = (ParentClass)factory.GetObject("Parent");

            Assert.That(parent, Is.Not.Null);

            DisposableClass innerObject = (DisposableClass)parent.InnerObject;

            innerObject.ObjectFactory = factory;

            factory.Dispose();

            Assert.Pass("Test concluded successfully.");
        }
        public void PropertyFromProperties()
        {
            var expected = "string";
            var instance = new ParentClass {
                Basic = new BasicClass {
                    Test = expected
                }
            };

            var property1 = typeof(ParentClass).GetProperty(nameof(ParentClass.Basic));
            var property2 = typeof(BasicClass).GetProperty(nameof(BasicClass.Test));

            var data = PropertyMetadataHelper.GetPropertyMetadata(instance.GetType(), new[] { property1 }, property2);

            Assert.IsNotNull(data);
            Assert.AreEqual($"{nameof(ParentClass.Basic)}.{nameof(BasicClass.Test)}", data.PropertyName);
            Assert.AreEqual(expected, data.Getter(instance));
        }
Example #8
0
        public ActionResult FinalChecklist()
        {
            ParentClass pc = new ParentClass();

            pc.Homes1  = db.Homes.ToList <Home>();
            pc.Gardens = db.Gardens.ToList <Garden>();


            //ViewBag.Message = "Your page.";

            //HouseModel hm = new HouseModel();
            //using (ChecklistContext db = new ChecklistContext())
            //{
            //    hm.Homes1 = db.Homes.ToList<Home>();
            //}

            return(View(pc));
        }
        public void ShallowCloneToObjectHierarchy()
        {
            var source      = new ParentClass();
            var sourceChild = new ChildClass {
                Name = "John Doe"
            };

            source.Child = sourceChild;

            var destination      = new ParentClass();
            var destinationChild = new ChildClass();

            destination.Child = destinationChild;

            Cloneable <ParentClass> .ShallowCloneTo(source, destination);

            Assert.IsTrue(object.ReferenceEquals(sourceChild, destination.Child));
        }
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <param name="parentClass">The parent class.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public static MsSqlCeLearnLoggingConnector GetInstance(ParentClass parentClass)
        {
            lock (instances)
            {
                ConnectionStringStruct connection = parentClass.CurrentUser.ConnectionString;

                if (!instances.ContainsKey(connection))
                {
                    instances.Add(connection, new MsSqlCeLearnLoggingConnector(parentClass));
                }
                else if (instances[connection].Parent.CurrentUser.Id != parentClass.CurrentUser.Id)
                {
                    instances[connection].Parent = parentClass;
                }

                return(instances[connection]);
            }
        }
Example #11
0
        public void Properties_should_return_a_single_metadata_for_a_enumerable_property()
        {
            // Arrange
            var model = new ParentClass
            {
                Children = new List <NestedClass>
                {
                    new NestedClass(),
                    new NestedClass()
                }
            };

            // Action
            var properties = ModelMetadataProviders.Current.GetMetadataForType(() => model, typeof(ParentClass)).Properties.ToList();

            // Assert
            Assert.AreEqual(1, properties.Count);
            Assert.AreEqual("ParentClass.Children", properties[0].FullName);
        }
        public void NestedNullableNonStringProperty()
        {
            var instance = new ParentClass {
                Basic = new BasicClass {
                    NullableTest = "Test Value", Id = 1
                }
            };

            Expression <Func <ParentClass, int?> > func = (ParentClass x) => x.Basic == null ? default(int?) : x.Basic.NullableTest == null ? default : x.Basic.NullableTest.Length;

                                                          var data = PropertyMetadataHelper.GetPropertyMetadata(func);

                                                          Assert.IsNotNull(data);
                                                          Assert.AreEqual(10, data.Getter(instance));
                                                          Assert.AreEqual(typeof(int?), data.PropertyType);
                                                          Assert.AreEqual(typeof(ParentClass), data.ObjectType);

                                                          Assert.IsNull(data as IFullPropertyMetadata);
        }
        public void NestedNullableProperty()
        {
            var instance = new ParentClass {
                Basic = new BasicClass {
                    NullableTest = "Test Value"
                }
            };
            Expression <Func <ParentClass, string?> > func = (ParentClass x) => x.Basic.NullableTest;

            var data = PropertyMetadataHelper.GetPropertyMetadata(func);

            Assert.IsNotNull(data);
            Assert.AreEqual("BasicNullableTest", data.PropertyName);
            Assert.AreEqual("Test Value", data.Getter(instance));
            Assert.AreEqual(typeof(string), data.PropertyType);
            Assert.AreEqual(typeof(ParentClass), data.ObjectType);

            Assert.IsNotNull(data as IFullPropertyMetadata);
        }
    public static int Main(string[] args)
    {
        var parent = new ParentClass
        {
            SomeClass = new SomeClass
            {
                WrappedMoney = new Money {
                    Amount = 1.25M, CurrencyCode = "USD"
                }
            }
        };
        var serializer = new XmlSerializer(typeof(ParentClass));

        using (var writer = new StreamWriter("output.xml"))
        {
            serializer.Serialize(writer, parent);
        }
        return(0);
    }
Example #15
0
        private static void LearnLogWriter()
        {
            Thread.CurrentThread.IsBackground = true;
            Thread.CurrentThread.Name         = "LogWriterThread";

            ParentClass parent = new ParentClass(new DummyUser(new ConnectionStringStruct()), null);

            while (true)
            {
                try
                {
                    LearnLogStruct?lls = null;
                    lock (logQueue)
                    {
                        while (logQueue.Count == 0)
                        {
                            Monitor.Wait(logQueue);
                        }

                        if (logQueue.Count > 0)
                        {
                            lls = logQueue.Dequeue();
                        }
                    }

                    if (lls.HasValue)
                    {
                        if (hasParentChanged)
                        {
                            lock (globalParent)
                            {
                                parent           = globalParent;
                                hasParentChanged = false;
                            }
                        }

                        IDbLearnLoggingConnector learnLogConnector = GetLearnLoggingConnector(parent);
                        learnLogConnector.CreateLearnLogEntry(lls.Value);
                    }
                }
                catch (Exception ex) { Trace.WriteLine("Error in learnLogWriter: " + ex.Message); }
            }
        }
Example #16
0
    public void ConfigReifier_NestedList_UpdatesInPlace()
    {
        var o = new ParentClass();

        o.nestedList = new List <TestClass>();
        o.nestedList.Add(new TestClass {
            intKey = 78, floatKey = 1.2f
        });
        var saved = o.nestedList[0];

        UpdateFromString(ref o, @"---
            nestedList:
                - intKey: 4404
            ");
        Assert.AreEqual(o.nestedList.Count, 1);
        Assert.IsTrue(object.ReferenceEquals(o.nestedList[0], saved));
        Assert.AreEqual(o.nestedList[0].intKey, 4404);
        Assert.AreEqual(o.nestedList[0].floatKey, 1.2f);
    }
Example #17
0
        public override object Get(Token name)
        {
            if (EnvTracker.ContainsKey(name.Lexeme))
            {
                var value = EnvTracker[name.Lexeme];
                if (value.IsPrivate)
                {
                    throw new RuntimeError(name, $"'{name.Lexeme}' is inaccessible due to it's protection level");
                }
                return(ClassEnv.Values[name.Lexeme]);
            }

            if (ParentClass != null)
            {
                return(ParentClass.Get(name));
            }

            throw new RuntimeError(name, $"Can't get undefined static property '{name.Lexeme}'");
        }
Example #18
0
    public void ConfigReifier_NestedDict_UpdatesInPlace()
    {
        var o = new ParentClass();

        o.nestedDict            = new Dictionary <string, TestClass>();
        o.nestedDict["dictKey"] = new TestClass {
            intKey = 22, floatKey = 4.56f
        };
        var saved = o.nestedDict["dictKey"];

        UpdateFromString(ref o, @"---
            nestedDict:
                dictKey:
                    intKey: 56
            ");
        Assert.AreEqual(o.nestedDict.Count, 1);
        Assert.IsTrue(object.ReferenceEquals(o.nestedDict["dictKey"], saved));
        Assert.AreEqual(o.nestedDict["dictKey"].intKey, 56);
    }
        public void NestedReadonlyProperty()
        {
            var instance = new ParentClass {
                Basic = new BasicClass {
                    Test = "Test Value"
                }
            };
            Expression <Func <ParentClass, string> > func = (ParentClass x) => x.Basic.Test.ToLower();

            var data = PropertyMetadataHelper.GetPropertyMetadata(func);

            Assert.IsNotNull(data);
            Assert.AreEqual("x => x.Basic.Test.ToLower()", data.PropertyName);
            Assert.AreEqual("test value", data.Getter(instance));
            Assert.AreEqual(typeof(string), data.PropertyType);
            Assert.AreEqual(typeof(ParentClass), data.ObjectType);

            Assert.IsNull(data as IFullPropertyMetadata);
        }
        public void NestedReadonlyNonStringProperty()
        {
            var instance = new ParentClass {
                Basic = new BasicClass {
                    Test = "Test Value", Id = 1
                }
            };
            Expression <Func <ParentClass, int> > func = (ParentClass x) => x.Basic.Id * 2;

            var data = PropertyMetadataHelper.GetPropertyMetadata(func);

            Assert.IsNotNull(data);
            Assert.AreEqual("x => (x.Basic.Id * 2)", data.PropertyName);
            Assert.AreEqual(2, data.Getter(instance));
            Assert.AreEqual(typeof(int), data.PropertyType);
            Assert.AreEqual(typeof(ParentClass), data.ObjectType);

            Assert.IsNull(data as IFullPropertyMetadata);
        }
        public void Serialization_DoesNotBreakInpc()
        {
            var obj = new ParentClass();
            obj.Child = new ChildClass();
            obj.Child.AutoProp = "C";
            obj.AutoProp = "D";

            var serializer = new DataContractSerializer( typeof(ParentClass) );
            var stream = new MemoryStream();
            serializer.WriteObject( stream, obj );
            stream.Position = 0;
            obj = (ParentClass) serializer.ReadObject( stream );

            TestHelpers.DoInpcTest( obj, o =>
                {
                    o.ChangeFields();
                    o.Child.AutoProp = "Z";
                }, 2,
                "CompoundProp", "NestedProp");
        }
        public void Should_handle_nested_types()
        {
            var message = new HeftyMessage
            {
                Int  = 47,
                Long = 8675309,
                Dub  = 3.14159,
                Flt  = 1.234f,
                Boo  = true,
                Now  = new DateTime(2010, 3, 1)
            };

            var parentMessage = new ParentClass {
                Body = message
            };

            string text = _serializer.Serialize(parentMessage);

            text.ShouldEqual("{Body:{Boo:true,Dub:3.14159,Flt:1.234,Int:47,Long:8675309,Now:2010-03-01}}");
        }
Example #23
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            displayedObject = (e.Parameter as CodeEditorContext).displayedObject;
            tableName       = (e.Parameter as CodeEditorContext).tableName;
            populateContent();

            localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            if (tableName == "Scratchpad" || tableName == "Examples" || tableName == "LessonExample")
            {
                CommandBar   bottomCommandBar = this.BottomAppBar as CommandBar;
                AppBarButton b = bottomCommandBar.PrimaryCommands[2] as AppBarButton;
                b.Click -= Verify;
                bottomCommandBar.PrimaryCommands.RemoveAt(2);
            }

            progressbar = StatusBar.GetForCurrentView().ProgressIndicator;

            this.navigationHelper.OnNavigatedTo(e);
        }
        public ActionResult Create(ParentViewModel objParentViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    objParentViewModel.ProfilePicture = objParentViewModel.ProfilePicture;
                    HttpPostedFileBase File     = objParentViewModel.ImagePath;
                    string             FileName = "";
                    if (File != null)
                    {
                        FileName = FileUpload.UploadParentProfileImage(File);
                        objParentViewModel.ProfilePicture = FileName;
                    }
                    //var objParent = _mapper.Map<TblParent>(objParentViewModel);

                    if (objParentViewModel.ParentId != 0)
                    {
                        //objParent.UpdatedDate = DateTime.Now;
                        //clsParent.UpdateParent(objParent);
                    }
                    else
                    {
                        objParentViewModel.IPAddress = CommonMethods.GetIPAddress();
                        ParentClass.CreateParent(objParentViewModel);
                    }

                    TempData["MessageType"] = ViewBag.MessageType = "success";
                    TempData["Message"]     = ViewBag.Message = "Data Saved Successfully";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(Json(new { message = "The model is not valid, please fill form correctly.", url = Url.Action("Index", "Parent") }));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #25
0
        public void Serialization_DoesNotBreakInpc()
        {
            var obj = new ParentClass();

            obj.Child          = new ChildClass();
            obj.Child.AutoProp = "C";
            obj.AutoProp       = "D";

            var serializer = new DataContractSerializer(typeof(ParentClass));
            var stream     = new MemoryStream();

            serializer.WriteObject(stream, obj);
            stream.Position = 0;
            obj             = (ParentClass)serializer.ReadObject(stream);

            TestHelpers.DoInpcTest(obj, o =>
            {
                o.ChangeFields();
                o.Child.AutoProp = "Z";
            }, 2,
                                   "CompoundProp", "NestedProp");
        }
Example #26
0
    public void ConfigReifier_NestedDict_AddsNewPairs()
    {
        var o = new ParentClass();

        o.nestedDict            = new Dictionary <string, TestClass>();
        o.nestedDict["dictKey"] = new TestClass {
            intKey = 67, floatKey = 1.06f
        };
        UpdateFromString(ref o, @"---
            nestedDict:
                dictKey:
                    intKey: 42
                newKey:
                    intKey: 43
                    floatKey: 12
            ");
        Assert.AreEqual(o.nestedDict.Count, 2);
        Assert.AreEqual(o.nestedDict["dictKey"].intKey, 42);
        Assert.AreEqual(o.nestedDict["dictKey"].floatKey, 1.06f);
        Assert.AreEqual(o.nestedDict["newKey"].intKey, 43);
        Assert.AreEqual(o.nestedDict["newKey"].floatKey, 12f);
    }
        public void UpdateManyToMany_TwoExistingElement_AddOneElement()
        {
            using (var transaction = connection.BeginTransaction())
            {
                parent = new ParentClass();
                connection.Save(parent);

                var newChildren = new[] { new ChildDto {
                                              Test = "First"
                                          }, new ChildDto {
                                              Test = "Second"
                                          } };
                connection.UpdateManyToMany(parent, parent.Children, newChildren, mapper);

                connection.Cache.Clear();

                var first  = connection.SelectAllFrom <ChildClass>().Where(c => c.Test == "First").Single();
                var second = connection.SelectAllFrom <ChildClass>().Where(c => c.Test == "Second").Single();

                var newParent        = connection.Load <ParentClass>(parent.Id);
                var modifiedChildren = new[] { new ChildDto {
                                                   Test = "First", Id = first.Id
                                               }, new ChildDto {
                                                   Test = "Second", Id = second.Id
                                               }, new ChildDto {
                                                   Test = "Third"
                                               } };
                connection.UpdateManyToMany(newParent, newParent.Children, modifiedChildren, mapper);

                connection.Cache.Clear();

                var final = connection.Load <ParentClass>(parent.Id);
                Assert.Equal(3, final.Children.Count);
                Assert.True(final.Children.Any(c => c.Child.Test == "First"));
                Assert.True(final.Children.Any(c => c.Child.Test == "Second"));
                Assert.True(final.Children.Any(c => c.Child.Test == "Third"));
                transaction.Rollback();
            }
        }
        public void NestedStringExpression()
        {
            var instance = new ParentClass {
                Basic = new BasicClass {
                    Test = "Test Value"
                }
            };
            Expression <Func <ParentClass, string> > func = (ParentClass x) => $"{x.Basic} {x.Basic.Test}";

            var data = PropertyMetadataHelper.GetExpressionMetadata(func);

            Assert.IsNotNull(data);
            Assert.AreEqual("RapidCMS.Common.Tests.PropertyMetadata.PropertyMetadataTests+BasicClass Test Value", data.StringGetter(instance));

            var propertyData = PropertyMetadataHelper.GetPropertyMetadata(func);

            Assert.IsNotNull(propertyData);
            Assert.IsNull(propertyData as IFullPropertyMetadata);
            Assert.AreEqual("x => Format(\"{0} {1}\", x.Basic, x.Basic.Test)", propertyData.PropertyName);
            Assert.AreEqual("RapidCMS.Common.Tests.PropertyMetadata.PropertyMetadataTests+BasicClass Test Value", propertyData.Getter(instance));
            Assert.AreEqual(typeof(string), propertyData.PropertyType);
        }
Example #29
0
        private void button07_Click_addedEvent()
        {
            parentList = new List <ParentClass>();

            var pel1 = new ParentClass();

            pel1.ParentId  = 1;
            pel1.ChildList = new List <ChildClass>();
            pel1.ChildList.Add(new ChildClass {
                ChildId = 1, ChildName = "c1"
            });
            pel1.ChildList.Add(new ChildClass {
                ChildId = 2, ChildName = "c2"
            });
            parentList.Add(pel1);


            var pel2 = new ParentClass();

            pel2.ParentId  = 2;
            pel2.ChildList = new List <ChildClass>();
            pel2.ChildList.Add(new ChildClass {
                ChildId = 2, ChildName = "c3"
            });
            pel2.ChildList.Add(new ChildClass {
                ChildId = 3, ChildName = "c4"
            });
            pel2.ChildList.Add(new ChildClass {
                ChildId = 4, ChildName = "c5"
            });
            parentList.Add(pel2);



            int childElementCount = parentList.Sum(x => x.ChildList.ToList().Count);

            Console.WriteLine(childElementCount);
        }
Example #30
0
        /// <summary>
        /// Closes the user session.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <remarks>Documented by Dev08, 2008-09-05</remarks>
        public static void CloseUserSession(ParentClass parent)
        {
            if (lastSessionId < 0)             //return if CloseUserSession(...) happens before OpenUserSession(...)
            {
                return;
            }

            if (parent.CurrentUser.ConnectionString.Typ == DatabaseType.Xml)
            {
                return;
            }
            else
            {
                try
                {
                    GetSessionConnector(parent).CloseUserSession(lastSessionId);
                    FlushLogQueue(parent);                          //force writing all Log entries
                }
                catch (Exception ex) { Trace.WriteLine("Error ending session: " + ex.Message); }
            }

            lastSessionId = -1;
        }
Example #31
0
        internal DbUser(UserStruct?user, ParentClass parent, ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate, bool standAlone)
        {
            this.parent          = parent;
            connectionString     = connection;
            ErrorMessageDelegate = errorMessageDelegate;

            cache = new Cache(true);

            if (!user.HasValue)
            {
                throw new NoValidUserException();
            }

            this.authenticationStruct = user.Value;
            this.username             = user.Value.UserName;
            this.hashedPassword       = user.Value.Password;

            this.standAlone = standAlone;
            this.user       = user;

            securityFramework = MLifter.DAL.Security.SecurityFramework.GetDataAdapter(this);
            if (username != null && securityFramework != null)
            {
                try
                {
                    securityToken           = securityFramework.CreateSecurityToken(this.username);
                    securityToken.IsCaching = cachePermissions;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Failed to create security token! (" + ex.Message + ")");
                }
            }

            Login();
        }
Example #32
0
        /// <summary>
        /// Creates the learn log entry.
        /// </summary>
        /// <param name="learnLogStruct">The learn log struct.</param>
        /// <param name="parent">The parent.</param>
        /// <remarks>Documented by Dev08, 2008-09-05</remarks>
        public static void CreateLearnLogEntry(LearnLogStruct learnLogStruct, ParentClass parent)
        {
            if (lastSessionId < 0)             //Only write if there is a valid userSession
            {
                return;
            }

            if (parent.CurrentUser.ConnectionString.Typ == DatabaseType.Xml)
            {
                return;
            }
            else
            {
                try
                {
                    lock (logQueue)
                    {
                        logQueue.Enqueue(learnLogStruct);
                        Monitor.Pulse(logQueue);
                    }
                }
                catch (Exception ex) { Trace.WriteLine("Error writing log: " + ex.Message); }
            }
        }
        public void ShallowCloneToObjectHierarchyWithNullSourceChild()
        {
            var source = new ParentClass();

            var destination = new ParentClass {Child = new ChildClass {Name = "John Doe"}};

            Cloneable<ParentClass>.ShallowCloneTo(source, destination);

            Assert.IsNull(destination.Child);
        }
        public void ShallowCloneToObjectHierarchyWithNullDestinationChild()
        {
            var source = new ParentClass();
            var sourceChild = new ChildClass { Name = "John Doe" };

            source.Child = sourceChild;

            var destination = new ParentClass();

            Cloneable<ParentClass>.ShallowCloneTo(source, destination);

            Assert.IsTrue(object.ReferenceEquals(sourceChild, destination.Child));
            Assert.AreEqual(sourceChild.Name, destination.Child.Name);
        }
 public void ShallowCloneToWithSameDestinationAsSourceWillNotWork()
 {
     var testClass = new ParentClass();
     Assert.Throws<InvalidOperationException>(() => Cloneable<ParentClass>.ShallowCloneTo(testClass, testClass));
 }
        public void CloneObjectHierarchy()
        {
            var parent = new ParentClass();
            parent.Child = new ChildClass { Name = "John Doe" };

            Assert.IsTrue(Cloneable<ParentClass>.CanClone());
            Assert.IsTrue(Cloneable<ParentClass>.CanShallowClone());

            var parentClone = Cloneable<ParentClass>.Clone(parent);
            
            Assert.IsFalse(object.ReferenceEquals(parent.Child, parentClone.Child));
            Assert.AreEqual("John Doe", parentClone.Child.Name);
        }
Example #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DbStatistic"/> class.
 /// </summary>
 /// <param name="id">The sessionId.</param>
 /// <param name="parent">The parent.</param>
 /// <remarks>Documented by Dev08, 2008-11-13</remarks>
 public DbStatistic(int id, ParentClass parent)
 {
     this.parent = parent;
     this.id     = id;
 }
Example #38
0
        public ChildClass(int val)
        {
            myp = new ParentClass(val);
	    int tmp = myp.GetHashCode();
        }