public void CanUpdateItem() { ComplexContainersItem item = new ComplexContainersItem(); IDictionary<string, Control> added = AddEditors(item); TextBox tbp0 = added["MyProperty0"] as TextBox; TextBox tbp1 = added["MyProperty1"] as TextBox; TextBox tbp2 = added["MyProperty2"] as TextBox; FreeTextArea ftap3 = added["MyProperty3"] as FreeTextArea; CheckBox cbp4 = added["MyProperty4"] as CheckBox; Assert.IsEmpty(item.MyProperty0); Assert.IsEmpty(item.MyProperty1); Assert.IsEmpty(item.MyProperty2); Assert.IsEmpty(item.MyProperty3); Assert.IsFalse(item.MyProperty4); tbp0.Text = "one"; tbp1.Text = "two"; tbp2.Text = "three"; ftap3.Text = "rock"; cbp4.Checked = true; editManager.UpdateItem(definitions.GetDefinition(item.GetContentType()), item, added, CreatePrincipal("someone")); Assert.AreEqual("one", item.MyProperty0); Assert.AreEqual("two", item.MyProperty1); Assert.AreEqual("three", item.MyProperty2); Assert.AreEqual("rock", item.MyProperty3); Assert.IsTrue(item.MyProperty4); }
protected IDictionary<string, Control> AddEditors(ComplexContainersItem item) { Type itemType = item.GetContentType(); Control editorContainer = new Control(); IDictionary<string, Control> added = editManager.AddEditors(itemType, editorContainer, null); return added; }
protected IDictionary<string, Control> AddEditors(ComplexContainersItem item) { Type itemType = item.GetContentType(); Control editorContainer = new Control(); IDictionary<string, Control> added = editManager.AddEditors(definitions.GetDefinition(itemType), item, editorContainer, CreatePrincipal("someone")); return added; }
public void CanUpdateEditors() { ComplexContainersItem item = new ComplexContainersItem(); IDictionary<string, Control> added = AddEditors(item); TextBox tbp0 = added["MyProperty0"] as TextBox; TextBox tbp1 = added["MyProperty1"] as TextBox; TextBox tbp2 = added["MyProperty2"] as TextBox; FreeTextArea ftap3 = added["MyProperty3"] as FreeTextArea; CheckBox cbp4 = added["MyProperty4"] as CheckBox; Assert.IsEmpty(tbp0.Text); Assert.IsEmpty(tbp1.Text); Assert.IsEmpty(tbp2.Text); Assert.IsEmpty(ftap3.Text); Assert.IsFalse(cbp4.Checked); item.MyProperty0 = "one"; item.MyProperty1 = "two"; item.MyProperty2 = "three"; item.MyProperty3 = "rock"; item.MyProperty4 = true; editManager.UpdateEditors(item, added, null); Assert.AreEqual("one", tbp0.Text); Assert.AreEqual("two", tbp1.Text); Assert.AreEqual("three", tbp2.Text); Assert.AreEqual("rock", ftap3.Text); Assert.IsTrue(cbp4.Checked); }
protected static void AssertItemHasValuesFromEditors(ComplexContainersItem item) { Assert.AreEqual("one", item.MyProperty0); Assert.AreEqual("two", item.MyProperty1); Assert.AreEqual("three", item.MyProperty2); Assert.AreEqual("rock", item.MyProperty3); Assert.IsTrue(item.MyProperty4); }
public void CanSaveItem() { ComplexContainersItem item = new ComplexContainersItem(); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.SaveOnly); DoTheSaving(CreatePrincipal("someone"), editor); AssertItemHasValuesFromEditors(item); }
public override void SetUp() { base.SetUp(); editUrlManager = new EditUrlManager(new EditSection()); root = CreateOneItem<ComplexContainersItem>(0, "root", null); item = CreateOneItem<ComplexContainersItem>(0, "item", root); version = new ComplexContainersItem { Name = "version", Title = "version", VersionOf = item, VersionIndex = 2 }; version.SetVersionKey("VERSKEY"); }
public void DoesntSaveVersion_ForNewItems() { ComplexContainersItem item = new ComplexContainersItem(); item.ID = 0; Expect.On(versioner).Call(versioner.AddVersion(item)).Repeat.Never(); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); AssertItemHasValuesFromEditors(item); }
public void CanSave_ItemAndVersion() { ComplexContainersItem item = new ComplexContainersItem(); item.ID = 28; Expect.On(versioner).Call(versioner.AddVersion(item)).Return(item.Clone(false)); versioner.Expect(v => v.TrimVersionCountTo(item, 100)).IgnoreArguments().Repeat.Any(); versioner.Expect(v => v.IsVersionable(item)).Return(true); mocks.Replay(versioner); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); AssertItemHasValuesFromEditors(item); }
public void DisabledVersioning_DoesntSaveVersion() { editManager.EnableVersioning = false; ComplexContainersItem item = new ComplexContainersItem(); item.ID = 29; Expect.On(versioner).Call(versioner.SaveVersion(item)).Repeat.Never(); mocks.Replay(versioner); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); mocks.VerifyAll(); }
public void CanUpdateEditors() { var item = new ComplexContainersItem(); var added = AddEditors(item); var tbp0 = added["MyProperty0"] as TextBox; var tbp1 = added["MyProperty1"] as TextBox; var tbp2 = added["MyProperty2"] as TextBox; var ftap3 = added["MyProperty3"] as FreeTextArea; var cbp4 = added["MyProperty4"] as CheckBox; Assert.That(tbp0 != null); Assert.That(tbp1 != null); Assert.That(tbp2 != null); Assert.That(ftap3 != null); Assert.That(cbp4 != null); Assert.IsEmpty(tbp0.Text); Assert.IsEmpty(tbp1.Text); Assert.IsEmpty(tbp2.Text); Assert.IsEmpty(ftap3.Text); Assert.IsFalse(cbp4.Checked); item.MyProperty0 = "one"; item.MyProperty1 = "two"; item.MyProperty2 = "three"; item.MyProperty3 = "rock"; item.MyProperty4 = true; editManager.UpdateEditors(definitions.GetDefinition(item.GetContentType()), item, added, CreatePrincipal("someone")); Assert.AreEqual("one", tbp0.Text); Assert.AreEqual("two", tbp1.Text); Assert.AreEqual("three", tbp2.Text); Assert.AreEqual("rock", ftap3.Text); Assert.IsTrue(cbp4.Checked); }
public void CanSave_VersionOnly() { ComplexContainersItem item = new ComplexContainersItem(); item.ID = 28; ComplexContainersItem version = item.Clone(false) as ComplexContainersItem; Expect.On(versioner).Call(versioner.AddVersion(item)).Return(version); versioner.Expect(v => v.TrimVersionCountTo(item, 100)).IgnoreArguments().Repeat.Any(); versioner.Expect(v => v.IsVersionable(item)).Return(true); mocks.Replay(versioner); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionOnly); DoTheSaving(CreatePrincipal("someone"), editor); Assert.That(persister.Repository.Get(28), Is.Null); Assert.AreEqual("", item.MyProperty0); Assert.AreEqual("", item.MyProperty1); Assert.AreEqual("", item.MyProperty2); Assert.AreEqual("", item.MyProperty3); Assert.IsFalse(item.MyProperty4); AssertItemHasValuesFromEditors(version); }
public void UpdateItemWithChangesReturnsTrue() { var item = new ComplexContainersItem(); var added = AddEditors(item); var tbp0 = added["MyProperty0"] as TextBox; var tbp1 = added["MyProperty1"] as TextBox; var tbp2 = added["MyProperty2"] as TextBox; var ftap3 = added["MyProperty3"] as FreeTextArea; var cbp4 = added["MyProperty4"] as CheckBox; Assert.That(tbp0 != null, "tbp0 != null"); Assert.That(tbp1 != null, "tbp1 != null"); Assert.That(tbp2 != null, "tbp2 != null"); Assert.That(ftap3 != null, "ftap3 != null"); Assert.That(cbp4 != null, "cbp4 != null"); tbp0.Text = "one"; tbp1.Text = "two"; tbp2.Text = "three"; ftap3.Text = "rock"; cbp4.Checked = true; var result = editManager.UpdateItem(definitions.GetDefinition(item.GetContentType()), item, added, CreatePrincipal("someone")); Assert.That(result.Length, Is.GreaterThan(0), "UpdateItem didn't return true even though the editors were changed."); }
public void SaveVersionAsMaster_IsMadeMasterVersion() { ComplexContainersItem currentMaster = new ComplexContainersItem(1, "current master"); ComplexContainersItem versionToBeMaster = new ComplexContainersItem(29, "version of current"); versionToBeMaster.VersionOf = currentMaster; Expect.Call(versioner.AddVersion(currentMaster)).Return(null); versioner.Expect(v => v.TrimVersionCountTo(null, 100)).IgnoreArguments().Repeat.Any(); versioner.Expect(v => v.IsVersionable(versionToBeMaster)).Return(true); mocks.ReplayAll(); IItemEditor editor = SimulateEditor(versionToBeMaster, ItemEditorVersioningMode.SaveAsMaster); DoTheSaving(CreatePrincipal("someone"), editor); Assert.That(persister.Repository.Get(1), Is.EqualTo(currentMaster)); }
public void Using_PrivilegedUser_AddsAllEditors() { ComplexContainersItem item = new ComplexContainersItem(); IPrincipal user = CreatePrincipal("Joe", "ÜberEditor"); Control editorContainer = new Control(); IDictionary<string, Control> added = editManager.AddEditors(definitions.GetDefinition(typeof(ComplexContainersItem)), item, editorContainer, user); Assert.AreEqual(7, added.Count); }
public void UsingPrivilegedUserAddsAllEditors() { var item = new ComplexContainersItem(); var user = CreatePrincipal("Joe", "ÜberEditor"); var editorContainer = new Control(); var added = editManager.AddEditors(definitions.GetDefinition(typeof(ComplexContainersItem)), item, editorContainer, user); Assert.AreEqual(7, added.Count); }
public void UpdateItem_WithNoChanges_ReturnsFalse() { ComplexContainersItem item = new ComplexContainersItem(); Type itemType = item.GetContentType(); Control editorContainer = new Control(); IDictionary<string, Control> added = editManager.AddEditors(definitions.GetDefinition(itemType), item, editorContainer, CreatePrincipal("someone")); item.MyProperty0 = "one"; item.MyProperty1 = "two"; item.MyProperty2 = "three"; item.MyProperty3 = "rock"; item.MyProperty4 = true; editManager.UpdateEditors(definitions.GetDefinition(item.GetContentType()), item, added, CreatePrincipal("someone")); var result = editManager.UpdateItem(definitions.GetDefinition(item.GetContentType()), item, added, null); Assert.IsFalse(result.Length > 0, "UpdateItem didn't return false even though the editors were unchanged."); }
public void UpdateItem_WithNoChanges_IsNotSaved() { ComplexContainersItem item = new ComplexContainersItem(); item.ID = 22; item.MyProperty0 = "one"; item.MyProperty1 = "two"; item.MyProperty2 = "three"; item.MyProperty3 = "rock"; item.MyProperty4 = true; Expect.On(versioner).Call(versioner.SaveVersion(item)).Return(item.Clone(false)); versioner.Expect(v => v.TrimVersionCountTo(item, 100)).IgnoreArguments().Repeat.Any(); versioner.Expect(v => v.IsVersionable(item)).Return(true); mocks.Replay(versioner); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); Assert.That(persister.Repository.Get(22), Is.Null); }
public void UpdateItem_WithChanges_ReturnsTrue() { ComplexContainersItem item = new ComplexContainersItem(); IDictionary<string, Control> added = AddEditors(item); TextBox tbp0 = added["MyProperty0"] as TextBox; TextBox tbp1 = added["MyProperty1"] as TextBox; TextBox tbp2 = added["MyProperty2"] as TextBox; FreeTextArea ftap3 = added["MyProperty3"] as FreeTextArea; CheckBox cbp4 = added["MyProperty4"] as CheckBox; tbp0.Text = "one"; tbp1.Text = "two"; tbp2.Text = "three"; ftap3.Text = "rock"; cbp4.Checked = true; var result = editManager.UpdateItem(item, added, null); Assert.IsTrue(result.Length > 0, "UpdateItem didn't return true even though the editors were changed."); }
public void Save_WhenUnpublished_PublishesItem() { ComplexContainersItem newItem = new ComplexContainersItem(1, "an item"); newItem.Published = null; Expect.Call(versioner.AddVersion(newItem)).Return(new ComplexContainersItem(2, "ignored")); versioner.Expect(v => v.TrimVersionCountTo(null, 100)).IgnoreArguments().Repeat.Any(); versioner.Expect(v => v.IsVersionable(newItem)).Return(true); mocks.ReplayAll(); IItemEditor editor = SimulateEditor(newItem, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); Assert.That(persister.Repository.Get(1), Is.EqualTo(newItem)); Assert.IsNotNull(newItem.Published, "Unpublished item should have been published."); Assert.Greater(newItem.Published, N2.Utility.CurrentTime().AddSeconds(-10)); }
public void SavingVersion_InvokesEvent() { savingVersionEventInvoked = false; ComplexContainersItem item = new ComplexContainersItem(); item.ID = 29; Expect.On(versioner).Call(versioner.AddVersion(item)).Return(item.Clone(false)); versioner.Expect(v => v.TrimVersionCountTo(item, 100)).IgnoreArguments().Repeat.Any(); versioner.Expect(v => v.IsVersionable(item)).Return(true); mocks.Replay(versioner); editManager.SavingVersion += new EventHandler<CancellableItemEventArgs>(editManager_SavingVersion); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); Assert.IsTrue(savingVersionEventInvoked, "The saving version event wasn't invoked"); }
public void VersionOnly_WhenNewItem_SavesIt_ButUnpublishesIt() { ComplexContainersItem newItem = new ComplexContainersItem(0, "an item"); newItem.Published = N2.Utility.CurrentTime(); mocks.ReplayAll(); IItemEditor editor = SimulateEditor(newItem, ItemEditorVersioningMode.VersionOnly); DoTheSaving(CreatePrincipal("someone"), editor); Assert.That(newItem.ID, Is.GreaterThan(0)); Assert.IsNull(newItem.Published); }
public void NewItem_WithNoChanges_IsSaved() { ComplexContainersItem item = new ComplexContainersItem(); item.ID = 0; item.MyProperty0 = "one"; item.MyProperty1 = "two"; item.MyProperty2 = "three"; item.MyProperty3 = "rock"; item.MyProperty4 = true; Expect.On(versioner).Call(versioner.SaveVersion(null)).Repeat.Never(); mocks.Replay(versioner); IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); Assert.That(item.ID, Is.GreaterThan(0)); }
public void SaveVersionAsMaster_WhenMasterIsUnpublished_PublishesItem() { ComplexContainersItem currentMaster = new ComplexContainersItem(1, "current master"); currentMaster.Published = null; ComplexContainersItem versionToBeMaster = new ComplexContainersItem(29, "version of current"); versionToBeMaster.VersionOf = currentMaster; versionToBeMaster.Published = null; Expect.Call(versioner.AddVersion(currentMaster)).Return(null); versioner.Expect(v => v.TrimVersionCountTo(currentMaster, 100)).IgnoreArguments().Repeat.Any(); versioner.Expect(v => v.IsVersionable(versionToBeMaster)).Return(true); mocks.ReplayAll(); IItemEditor editor = SimulateEditor(versionToBeMaster, ItemEditorVersioningMode.SaveAsMaster); DoTheSaving(CreatePrincipal("someone"), editor); Assert.That(persister.Repository.Get(1), Is.EqualTo(currentMaster)); Assert.IsNotNull(currentMaster.Published); Assert.Greater(currentMaster.Published, N2.Utility.CurrentTime().AddSeconds(-10)); }
public void SavingWithLimitedPrincipal_DoesntChange_SecuredProperties() { ComplexContainersItem item = new ComplexContainersItem(); item.ID = 0; item.MyProperty1 = "I'm available"; item.MyProperty5 = true; item.MyProperty6 = "I'm secure!"; IPrincipal user = CreatePrincipal("Joe"); Control editorContainer = new Control(); IDictionary<string, Control> added = editManager.AddEditors(definitions.GetDefinition(typeof(ComplexContainersItem)), item, editorContainer, CreatePrincipal("someone")); Assert.AreEqual(5, added.Count); IItemEditor editor = mocks.StrictMock<IItemEditor>(); using (mocks.Record()) { Expect.Call(editor.CurrentItem).Return(item).Repeat.Any(); Expect.Call(editor.AddedEditors).Return(added); Expect.Call(editor.VersioningMode).Return(ItemEditorVersioningMode.VersionAndSave); } DoTheSaving(user, editor); Assert.AreEqual("", item.MyProperty0); Assert.AreEqual("I'm secure!", item.MyProperty6); Assert.IsTrue(item.MyProperty5); }
public void SavingVersionEvent_IsNotInvoked_WhenNewItem() { savingVersionEventInvoked = false; ComplexContainersItem item = new ComplexContainersItem(); item.ID = 0; editManager.SavingVersion += editManager_SavingVersion; IItemEditor editor = SimulateEditor(item, ItemEditorVersioningMode.VersionAndSave); DoTheSaving(CreatePrincipal("someone"), editor); Assert.IsFalse(savingVersionEventInvoked, "The saving version event should not have been invoked."); }
public void UpdateItem_PukesOnNullAddedEditors() { ContentItem item = new ComplexContainersItem(); Assert.Throws<ArgumentNullException>(() => editManager.UpdateItem(null, item, null, null)); }
public void UpdateItem_WithChanges_ReturnsTrue() { ComplexContainersItem item = new ComplexContainersItem(); IDictionary<string, Control> added = AddEditors(item); TextBox tbp0 = added["MyProperty0"] as TextBox; TextBox tbp1 = added["MyProperty1"] as TextBox; TextBox tbp2 = added["MyProperty2"] as TextBox; FreeTextArea ftap3 = added["MyProperty3"] as FreeTextArea; CheckBox cbp4 = added["MyProperty4"] as CheckBox; tbp0.Text = "one"; tbp1.Text = "two"; tbp2.Text = "three"; ftap3.Text = "rock"; cbp4.Checked = true; var result = editManager.UpdateItem(definitions.GetDefinition(item.GetContentType()), item, added, CreatePrincipal("someone")); Assert.That(result.Length, Is.GreaterThan(0), "UpdateItem didn't return true even though the editors were changed."); }
public void VersionOnly_WhenNewItem_SavesIt_ButUnpublishesIt() { ComplexContainersItem newItem = new ComplexContainersItem(0, "an item"); newItem.Published = DateTime.Now; mocks.ReplayAll(); IItemEditor editor = SimulateEditor(newItem, ItemEditorVersioningMode.VersionOnly); DoTheSaving(null, editor); Assert.That(newItem.ID, Is.GreaterThan(0)); Assert.IsNull(newItem.Published); }