public void ContentList_Modify() { List <string> listDefs = new List <string>(); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF3' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); string listName = "List1"; string listPath = RepositoryPath.Combine(this.TestRoot.Path, listName); if (Node.Exists(listPath)) { Node.ForceDelete(listPath); } ContentList list = new ContentList(this.TestRoot); list.Name = listName; list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") }; list.Save(); Node car = new GenericContent(list, "Car"); car.Name = "Kispolszki"; car.Save(); int carId = car.Id; StringBuilder log = new StringBuilder(); for (int def = 0; def < listDefs.Count; def++) { Exception ex = null; for (var i = 0; i < 10; i++) { try { ex = null; list = Node.Load <ContentList>(listPath); list.ContentListDefinition = listDefs[def]; list.Save(); break; } catch (Exception e) { ex = e; System.Threading.Thread.Sleep(200); Debug.WriteLine("@> {0}. {1} / {2}", i, def, listDefs.Count); } } if (ex != null) { throw new ApplicationException("Exception after 10 iteration: " + ex.Message, ex); } car = Node.LoadNode(carId); log.Append("Def_").Append(def).Append(": "); for (int i = 0; i < 4; i++) { var propName = "#String_" + i; if (car.HasProperty(propName)) { log.Append("[").Append(propName).Append(" = ").Append(car.PropertyTypes[propName].Mapping).Append("]"); } } log.Append("\r\n"); } string realLog = log.Replace("\r\n", "").Replace(" ", "").Replace("\t", "").ToString(); string expectedLog = @" Def_0: Def_1: [#String_0 = 800000000][#String_1 = 800000001] Def_2: [#String_0 = 800000000] Def_3: Def_4: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002] Def_5: [#String_0 = 800000000][#String_2 = 800000002] Def_6: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002] Def_7: [#String_2 = 800000002] Def_8: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002] Def_9: [#String_0 = 800000000][#String_2 = 800000002][#String_3 = 800000003] " .Replace("\r\n", "").Replace(" ", "").Replace("\t", ""); Assert.IsTrue(realLog == expectedLog); }
public void ContentList_Modify() { List<string> listDefs = new List<string>(); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF3' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'> <Fields> <ContentListField name='#LF0' type='ShortText' /> <ContentListField name='#LF1' type='ShortText' /> <ContentListField name='#LF2' type='ShortText' /> </Fields> </ContentListDefinition> "); string listName = "List1"; string listPath = RepositoryPath.Combine(this.TestRoot.Path, listName); if (Node.Exists(listPath)) Node.ForceDelete(listPath); ContentList list = new ContentList(this.TestRoot); list.Name = listName; list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") }; list.Save(); Node car = new GenericContent(list, "Car"); car.Name = "Kispolszki"; car.Save(); int carId = car.Id; StringBuilder log = new StringBuilder(); for (int def = 0; def < listDefs.Count; def++) { Exception ex = null; for (var i = 0; i < 10; i++) { try { ex = null; list = Node.Load<ContentList>(listPath); list.ContentListDefinition = listDefs[def]; list.Save(); break; } catch(Exception e) { ex = e; System.Threading.Thread.Sleep(200); Debug.WriteLine("@> {0}. {1} / {2}", i, def, listDefs.Count); } } if (ex != null) throw new ApplicationException("Exception after 10 iteration: " + ex.Message, ex); car = Node.LoadNode(carId); log.Append("Def_").Append(def).Append(": "); for (int i = 0; i < 4; i++) { var propName = "#String_" + i; if(car.HasProperty(propName)) log.Append("[").Append(propName).Append(" = ").Append(car.PropertyTypes[propName].Mapping).Append("]"); } log.Append("\r\n"); } string realLog = log.Replace("\r\n", "").Replace(" ", "").Replace("\t", "").ToString(); string expectedLog = @" Def_0: Def_1: [#String_0 = 800000000][#String_1 = 800000001] Def_2: [#String_0 = 800000000] Def_3: Def_4: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002] Def_5: [#String_0 = 800000000][#String_2 = 800000002] Def_6: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002] Def_7: [#String_2 = 800000002] Def_8: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002] Def_9: [#String_0 = 800000000][#String_2 = 800000002][#String_3 = 800000003] ".Replace("\r\n", "").Replace(" ", "").Replace("\t", ""); Assert.IsTrue(realLog == expectedLog); }