/// <summary> /// Read setting object from stream. /// </summary> /// <param name="userSettings">Object that should be deserialized.</param> /// <param name="stream">Stream object; could be file, memory, other.</param> public void Read(IUserSettings userSettings, Stream stream) { if (stream == null || userSettings == null) { return; } using (var reader = new StreamReader(stream)) { try { Logger?.Log("Deserialize user settings"); var liteUserSettingsType = LiteObjectService.GetLiteObjectType(userSettings); if (liteUserSettingsType == null) { return; } var sourceSettings = (new XmlSerializer(liteUserSettingsType)).Deserialize(reader); LiteObjectService.CopyLiteObjectValues(userSettings, sourceSettings); } catch (InvalidOperationException) { } } }
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); }
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); }
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); }
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); }