Ejemplo n.º 1
0
        public void CopyLiteObjectValues_Should_ReturnPropertiesFromDerivedAndBasedType()
        {
            var testObject = new ExtendedDefaultsObject
            {
                Name    = "SomeName",
                Count   = 30,
                Title   = "SomeTitle",
                Indexed = false
            };
            var parentObject = new ExtendedDefaultsObject();

            var exception = Record.Exception(() =>
            {
                var service        = new LiteObjectService();
                dynamic liteObject = service.GetLiteObject(testObject, false);
                parentObject       = service.CopyLiteObjectValues(parentObject, liteObject, false);
            });

            // check correct properties
            Assert.Null(exception);
            Assert.NotNull(parentObject);

            Assert.Equal(testObject.Name, parentObject.Name);
            Assert.Equal(testObject.Count, parentObject.Count);
            Assert.Equal(testObject.Title, parentObject.Title);
            Assert.Equal(testObject.Indexed, parentObject.Indexed);
            Assert.Equal(testObject.Id, parentObject.Id);
            Assert.Equal(testObject.LastDateTime, parentObject.LastDateTime);
        }
Ejemplo n.º 2
0
        public void CopyLiteObjectValues_Should_ReturnObjectWithAllProperties(bool top)
        {
            var testObject = new DefaultsObject
            {
                Name  = "SomeName",
                Count = 30,
                Title = "SomeTitle"
            };
            var parentObject = new DefaultsObject();

            var exception = Record.Exception(() =>
            {
                var service        = new LiteObjectService();
                dynamic liteObject = service.GetLiteObject(testObject, top);
                parentObject       = service.CopyLiteObjectValues(parentObject, liteObject, top);
            });

            // check correct properties
            Assert.Null(exception);
            Assert.NotNull(parentObject);

            Assert.Equal(testObject.Name, parentObject.Name);
            Assert.Equal(testObject.Count, parentObject.Count);
            Assert.Equal(testObject.Indexed, parentObject.Indexed);
            Assert.Equal(testObject.Title, parentObject.Title);
            Assert.Equal(testObject.Id, parentObject.Id);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Write setting object to stream.
        /// </summary>
        /// <param name="userSettings">Object that should be serialized.</param>
        /// <param name="stream">Stream object; could be file, memory, other.</param>
        protected void Write(IUserSettings userSettings, Stream stream)
        {
            if (stream == null || userSettings == null)
            {
                return;
            }

            using (var writer = new StreamWriter(stream))
            {
                Logger?.Log("Serialize user settings");

                var liteUserSettings = LiteObjectService.GetLiteObject(userSettings);
                if (liteUserSettings == null)
                {
                    return;
                }
                (new XmlSerializer(liteUserSettings.GetType())).Serialize(writer, liteUserSettings);
            }
        }
Ejemplo n.º 4
0
        public void CopyLiteObjectValues_Should_ReturnNullOnWrongParentObject()
        {
            var testObject = new ExtendedDefaultsObject
            {
                Name  = "SomeName",
                Count = 30,
                Title = "SomeTitle"
            };
            object parentObject = new DefaultsObject();

            var exception = Record.Exception(() =>
            {
                var service    = new LiteObjectService();
                var liteObject = service.GetLiteObject(testObject);
                parentObject   = service.CopyLiteObjectValues(parentObject, liteObject);
            });

            // check correct properties
            Assert.Null(exception);
            Assert.Null(parentObject);
        }
Ejemplo n.º 5
0
        public void CopyLiteObjectValues_Should_ReturnNullOnDifferentTopValue(bool top1, bool top2)
        {
            var testObject = new ExtendedDefaultsObject
            {
                Name    = "SomeName",
                Count   = 30,
                Title   = "SomeTitle",
                Indexed = false
            };
            var parentObject = new ExtendedDefaultsObject();

            var exception = Record.Exception(() =>
            {
                var service        = new LiteObjectService();
                dynamic liteObject = service.GetLiteObject(testObject, top1);
                parentObject       = service.CopyLiteObjectValues(parentObject, liteObject, top2);
            });

            // check correct properties
            Assert.Null(exception);
            Assert.Null(parentObject);
        }