public void TestGetEnumerator() { TagPrimitiveCollection collection = new TagPrimitiveCollection(); const int firstTagID = 1236; const int secondTagID = 76409; TagPrimitive firstTag = new TagPrimitive(firstTagID, "tag_1236"); TagPrimitive secondTag = new TagPrimitive(secondTagID, "tag_654709"); collection.AddTag(firstTag); collection.AddTag(secondTag); Assert.AreEqual(2, collection.Count); foreach (TagPrimitive tagPrimitive in collection) { switch (tagPrimitive.ID) { case firstTagID: case secondTagID: continue; default: Assert.Fail(string.Format("TagID = [{0}] shouldn't be in collection", tagPrimitive.ID)); break; } } }
public void TestClear() { TagPrimitiveCollection collection = new TagPrimitiveCollection(); TagPrimitive firstTag = new TagPrimitive(1236, "tag_1236"); TagPrimitive secondTag = new TagPrimitive(654709, "tag_654709"); collection.AddTag(firstTag); collection.AddTag(secondTag); Assert.AreEqual(2, collection.Count); collection.Clear(); Assert.AreEqual(0, collection.Count); }
public void TestMaterializeAdd() { TagPrimitiveCollection collection = new TagPrimitiveCollection(); int firstTagID = 1236; int secondTagID = 76409; Expression<Func<long, TagPrimitive>> materializeFirstTag = tagID => GetTag(firstTagID); Expression<Func<long, TagPrimitive>> materializeSecondTag = tagID => GetTag(secondTagID); TagPrimitive firstTag = new TagPrimitive(firstTagID, materializeFirstTag); TagPrimitive secondTag = new TagPrimitive(secondTagID, materializeSecondTag); collection.AddTag(firstTag); collection.AddTag(secondTag); Assert.AreEqual(2, collection.Count); TagPrimitive firstRetrievedTag = collection.GetTag(firstTagID); Assert.AreEqual(firstTag.ID, firstRetrievedTag.ID); StringAssert.IsMatch(firstTag.Text, firstRetrievedTag.Text); TagPrimitive secondRetrievedTag = collection.GetTag(secondTagID); Assert.AreEqual(secondTag.ID, secondRetrievedTag.ID); StringAssert.IsMatch(secondTag.Text, secondRetrievedTag.Text); }
private TagPrimitive GetTag(long id) { ManualResetEvent wait = new ManualResetEvent(false); TagPrimitive result = new TagPrimitive(); OperationFinished<ExportTagsStatus, TagPrimitive> getTagFinishedHandler = (status, tag) => { result = tag; wait.Reset(); }; GetTag(id, getTagFinishedHandler); wait.WaitOne(); return result; }