public void When_an_item_is_loaded_Then_it_should_be_retrievable_by_ID() { var item = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); repository.ItemLoaded(item); Assert.IsNotNull(repository.GetItemById(item.Id), "The item is not retrievable."); }
public void When_an_item_is_reloaded_Then_the_old_item_should_be_replaced() { var parentData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); repository.ItemLoaded(parentData); var childBuilder = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parentData.Id)).WithName("old"); var childData = childBuilder.Build(); repository.ItemLoaded(childData); childBuilder.WithName("new"); var childDataNew = childBuilder.Build(); repository.ItemLoaded(childDataNew); var parent = repository.GetItemById(parentData.Id); var firstChild = parent.Children.First(); Assert.AreEqual(childDataNew.Name, firstChild.Name); var child = repository.GetItemById(childData.Id); Assert.AreEqual(childDataNew.Name, child.Name); }
public RepositoryItemBuilder WithoutTaggedValue(TaggedValues key) { var copy = new RepositoryItemBuilder(this); copy.taggedValues.Remove(key); return(copy); }
public RepositoryItemBuilder WithParent(RepositoryItemBuilder value) { return(new RepositoryItemBuilder(this) { parent = value }); }
public RepositoryItemBuilder WithChild(RepositoryItemBuilder value) { var copy = new RepositoryItemBuilder(this); copy.children.Add(value); return(copy); }
public void When_an_item_is_deleted_Then_a_deletion_event_should_be_generated_for_its_children() { var parentData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); var childData1 = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parentData.Id)).Build(); var childData2 = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parentData.Id)).Build(); var childData3 = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(childData2.Id)).Build(); repository.ItemLoaded(parentData); repository.ItemLoaded(childData1); repository.ItemLoaded(childData2); repository.ItemLoaded(childData3); var expectedItemIds = new List <ItemId> { parentData.Id, childData1.Id, childData2.Id, childData3.Id }; repository.OnItemDeleted += item => expectedItemIds.Remove(item.Id); repository.ItemDeleted(parentData.Id); Assert.AreEqual(0, expectedItemIds.Count, "the expected events were not generated"); }
public RepositoryItemBuilder WithTaggedValue(TaggedValues key, string value) { var copy = new RepositoryItemBuilder(this); copy.taggedValues[key] = value; return(copy); }
public void When_a_package_has_a_non_UPCC_stereotype_Then_return_null() { var repositoryItem = new RepositoryItemBuilder().WithParent(new RepositoryItemBuilder().WithId(ItemId.ForPackage(1))) .WithItemType(ItemId.ItemType.Package) .WithStereotype("foobar") .Build(); object wrappedObject = CCItemWrapper.Wrap(repositoryItem); Assert.IsNull(wrappedObject, "Object with unknown stereotype not wrapped to null, but wrapped as " + (wrappedObject == null ? null : wrappedObject.GetType())); }
public void When_an_item_with_parentId_0_is_loaded_Then_it_should_be_inserted_right_below_the_root() { var item = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); repository.ItemLoaded(item); var root = repository.Root; var firstChild = root.Children.First(); Assert.AreEqual(item.Id, firstChild.Id); }
private static void AssertPackageWithStereotypeIsWrappedAs <TExpected>(string stereotype) { var parent = new RepositoryItemBuilder().WithParent(new RepositoryItemBuilder().WithId(ItemId.ForPackage(1))).WithItemType(ItemId.ItemType.Package).Build(); var repositoryItem = new RepositoryItemBuilder() .WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parent.Id)) .WithStereotype(stereotype) .Build(); object wrappedObject = CCItemWrapper.Wrap(repositoryItem); Assert.IsNotNull(wrappedObject, "Wrapped object is null."); Assert.IsTrue(wrappedObject is TExpected, "\nWrapped object is not of expected type:\n expected: " + typeof(TExpected) + "\n but was: " + wrappedObject.GetType()); }
public void When_an_item_is_deleted_Then_it_should_be_removed_from_its_parent() { var parentData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); repository.ItemLoaded(parentData); var childData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parentData.Id)).Build(); repository.ItemLoaded(childData); repository.ItemDeleted(childData.Id); var parent = repository.GetItemById(parentData.Id); Assert.AreEqual(0, parent.Children.Count(), "parent still has a child"); }
public void When_an_item_is_loaded_Then_it_should_be_added_as_a_child_to_its_parent() { var parent = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); repository.ItemLoaded(parent); var child = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parent.Id)).Build(); repository.ItemLoaded(child); var retrievedParent = repository.GetItemById(parent.Id); var firstChild = retrievedParent.Children.First(); Assert.AreEqual(child.Id, firstChild.Id); }
private RepositoryItemBuilder(RepositoryItemBuilder other) { id = other.id; name = other.name; stereotype = other.stereotype; taggedValues = new Dictionary <TaggedValues, string>(other.taggedValues); parent = other.parent != null ? new RepositoryItemBuilder(other.parent) : null; children = new List <RepositoryItemBuilder>(); if (other.children != null) { foreach (var otherChild in other.children) { children.Add(new RepositoryItemBuilder(otherChild)); } } }
public void When_an_item_is_reloaded_Then_it_should_retain_its_children() { var parentData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); repository.ItemLoaded(parentData); var parent = repository.GetItemById(parentData.Id); var childData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parentData.Id)).Build(); repository.ItemLoaded(childData); Assert.AreEqual(1, parent.Children.Count()); repository.ItemLoaded(parentData); var parentReloaded = repository.GetItemById(parentData.Id); Assert.AreEqual(1, parentReloaded.Children.Count()); }
public void When_an_item_is_loaded_Then_the_parents_previous_children_should_still_be_there() { var parentData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); repository.ItemLoaded(parentData); var parent = repository.GetItemById(parentData.Id); var child1 = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parent.Id)).Build(); repository.ItemLoaded(child1); Assert.AreEqual(1, parent.Children.Count()); Assert.AreEqual(child1.Id, parent.Children.First().Id); var child2 = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parent.Id)).Build(); repository.ItemLoaded(child2); Assert.AreEqual(2, parent.Children.Count()); Assert.AreEqual(child1.Id, parent.Children.First().Id); }
public void When_an_item_is_deleted_Then_a_modification_event_should_be_generated_for_its_parent() { var parentData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).Build(); var childData = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(parentData.Id)).Build(); repository.ItemLoaded(parentData); repository.ItemLoaded(childData); bool expectedEventGenerated = false; repository.OnItemCreatedOrModified += item => { if (item.Id == parentData.Id) { expectedEventGenerated = true; } }; repository.ItemDeleted(childData.Id); Assert.IsTrue(expectedEventGenerated, "the expected event was not generated"); }
public void When_an_item_with_an_unknown_parentId_is_loaded_Then_it_should_throw_an_ArgumentException() { var item = new RepositoryItemBuilder().WithItemType(ItemId.ItemType.Package).WithParent(new RepositoryItemBuilder().WithId(ItemId.ForPackage(2))).Build(); repository.ItemLoaded(item); }