コード例 #1
0
 /// <summary>
 /// Grid click event
 /// </summary>
 /// <param name="sender">Grid row object details</param>
 /// <param name="e">Event Arguments</param>
 /// <returns>Select function name on List box</returns>
 /// 2019/07/13, Vinoth N,  Initial Version
 private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     try
     {
         int selected_index = counterGrid.SelectedIndex;
         if (counterGrid.SelectedItem is CounterModel item)
         {
             if (item.Error == true)
             {
                 int errorIndex = ErrorCollection.ToList().FindIndex(a => a.Contains("<<<" + item.FunctionName + ">>>"));
                 //l_PODetails.SelectedIndex = errorIndex;
                 //l_PODetails.ScrollIntoView(l_PODetails.SelectedItem);
             }
             else
             {
                 //l_PODetails.UnselectAll();
             }
             int detailIndex = DetailCollection.ToList().FindIndex(a => a.Contains("<<<" + item.FunctionName + ">>>"));
             l_FunctionDetail.SelectedIndex = detailIndex;
             l_FunctionDetail.ScrollIntoView(l_FunctionDetail.SelectedItem);
         }
     }
     catch (Exception ex)
     {
         LogModel.Log(ex.Message);
     }
 }
コード例 #2
0
        /// <summary>Gets roles allowed for a certain permission stored in a content item.</summary>
        /// <param name="item">The item whose permitted roles get.</param>
        /// <param name="permission">The permission asked for.</param>
        /// <returns>Permitted roles.</returns>
        public static IEnumerable <string> GetRoles(ContentItem item, Permission permission)
        {
            List <string> roles = null;

            foreach (Permission permissionLevel in SplitPermission(permission))
            {
                if (permissionLevel == Permission.Read)
                {
                    foreach (AuthorizedRole role in item.AuthorizedRoles)
                    {
                        AddTo(ref roles, role.Role);
                    }
                    continue;
                }

                DetailCollection roleDetails = item.GetDetailCollection(AuthorizedRolesPrefix + permissionLevel, false);
                if (roleDetails == null)
                {
                    continue;
                }

                foreach (string role in roleDetails)
                {
                    roles = AddTo(ref roles, role);
                }
            }
            return(roles);
        }
コード例 #3
0
ファイル: TagBox.ascx.cs プロジェクト: nikita239/Aspect
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            Categories = new List <AppliedTags>();
            DetailCollection tags = CurrentPage.GetDetailCollection("Tags", false);

            if (tags == null)
            {
                return;
            }

            foreach (ITag tag in tags)
            {
                AppliedTags applied = Categories.Find(at => at.Group == tag.Category);
                if (applied == null)
                {
                    applied = new AppliedTags {
                        Group = tag.Category, Tags = new List <string>()
                    };
                    Categories.Add(applied);
                }
                applied.Tags.Add(tag.Title);
            }
        }
コード例 #4
0
        public void CanRead_WithCollectionOfLinks()
        {
            XmlableItem item = CreateOneItem <XmlableItem>(1, "item", null);

            CreateOneItem <XmlableItem>(2, "child1", item);
            CreateOneItem <XmlableItem>(3, "child2", item);
            CreateOneItem <XmlableItem>(4, "child3", item);
            CreateOneItem <XmlableItem>(5, "child4", item);
            CreateOneItem <XmlableItem>(6, "child5", item);

            foreach (ContentItem child in item.Children)
            {
                DetailCollection dc = child.GetDetailCollection("Siblings", true);
                foreach (ContentItem sibling in item.Children)
                {
                    if (sibling != child)
                    {
                        dc.Add(sibling);
                    }
                }
            }

            ContentItem readItem = Mangle(item);

            foreach (ContentItem child in readItem.Children)
            {
                Assert.IsNotNull(child.GetDetailCollection("Siblings", false));
                Assert.AreEqual(4, child.GetDetailCollection("Siblings", false).Count);
            }
        }
コード例 #5
0
        public void TracksUrl_ToImages()
        {
            RootDirectory        rootDir;
            FakeMemoryFileSystem fs;

            SetupFileSystem(out rootDir, out fs);
            fs.files["/FileSystem/upload/Image.jpg"] = new FileData {
                Name = "Image.jpg"
            };
            fs.files["/FileSystem/upload/OtherImage.jpg"] = new FileData {
                Name = "OtherImage.jpg"
            };

            string propertyName = "TestDetail";

            root[propertyName] = @"<img src=""/FileSystem/upload/Image.jpg"" />";
            persister.Save(root);

            DetailCollection links = root.GetDetailCollection("TrackedLinks", false);

            Assert.That(links, Is.Not.Null);
            Assert.That(links.Details[0].LinkedItem, Is.Null);
            Assert.That(links.Details[0].IntValue, Is.EqualTo(10));
            Assert.That(links.Details[0].Meta, Is.EqualTo(propertyName));
            Assert.That(links.Details[0].StringValue, Is.EqualTo("/FileSystem/upload/Image.jpg"));
        }
コード例 #6
0
ファイル: XmlReaderTests.cs プロジェクト: wrohrbach/n2cms
        public void CanRead_DetailCollection(IEnumerable values)
        {
            XmlableItem      item = CreateOneItem <XmlableItem>(1, "item", null);
            DetailCollection dc   = item.GetDetailCollection("Details", true);

            foreach (object detail in values)
            {
                dc.Add(detail);
            }

            ContentItem readItem = Mangle(item);

            DetailCollection readCollection = readItem.GetDetailCollection("Details", false);

            Assert.IsNotNull(readCollection);
            foreach (object detail in values)
            {
                if (detail is string)
                {
                    EnumerableAssert.Contains(readCollection, HttpUtility.HtmlEncode((string)detail));
                }
                else
                {
                    EnumerableAssert.Contains(readCollection, detail);
                }
            }
        }
コード例 #7
0
        private void ApplyChanges(AppliedTags change, ContentItem item)
        {
            DetailCollection links = item.GetDetailCollection(Name, false);

            if (links == null)
            {
                if (change.Tags.Count == 0)
                {
                    return;
                }
                links = item.GetDetailCollection(Name, true);
            }

            List <ITag> currentTags = GetCurrentTags(change.Group, links);

            IEnumerable <string> addedTags = GetAddedTags(currentTags, change.Tags);

            foreach (string tagName in addedTags)
            {
                ITag tag = change.Group.GetOrCreateTag(tagName);
                links.Add(tag);
            }

            foreach (ContentItem tag in currentTags)
            {
                if (!change.Tags.Contains(tag.Title))
                {
                    links.Remove(tag);
                }
            }
        }
コード例 #8
0
		public void DetailCollection_ContenItem()
		{
			var dc = new DetailCollection();
			dc.Add(new AnItem { ID = 123 });

			dc.Details[0].ValueTypeKey.ShouldBe(ContentDetail.TypeKeys.LinkType);
			((ContentItem)dc[0]).ID.ShouldBe(123);
		}
コード例 #9
0
        public void DoesntThrow_WhenCollection_ContainsNullValue()
        {
            DetailCollection collection = new DetailCollection();

            collection.Details.Add(new ContentDetail());

            Assert.That(collection.IndexOf("something"), Is.EqualTo(-1));
        }
コード例 #10
0
		public void DetailCollection_String()
		{
			var dc = new DetailCollection();
			dc.Add("hello");

			dc.Details[0].ValueTypeKey.ShouldBe(ContentDetail.TypeKeys.StringType);
			dc[0].ShouldBe("hello");
		}
コード例 #11
0
		public void DetailCollection_Int()
		{
			var dc = new DetailCollection();
			dc.Add(123);

			dc.Details[0].ValueTypeKey.ShouldBe(ContentDetail.TypeKeys.IntType);
			dc[0].ShouldBe(123);
		}
コード例 #12
0
		public void CanAddRange()
		{
			DetailCollection collection = new DetailCollection();
			collection.AddRange(new[] {"hello", "world"});

			Assert.That(collection[0], Is.EqualTo("hello"));
			Assert.That(collection[1], Is.EqualTo("world"));
		}
コード例 #13
0
        public void CanClone_Collection()
        {
            DetailCollection collection = new DetailCollection();
            collection.Add("hello");

            DetailCollection cloned = collection.Clone();
            Assert.That(cloned.Contains("hello"));
        }
コード例 #14
0
        public void Contains_IsTrue_ForContainedString()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add("hello");

            Assert.That(collection.Contains("hello"));
        }
コード例 #15
0
        protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal)
        {
            Dictionary <string, string> attributes = GetAttributes(navigator);
            Type type = Utility.TypeFromName(attributes["typeName"]);

            string meta = attributes.ContainsKey("meta") ? attributes["meta"] : null;

            if (type == typeof(ContentItem))
            {
                int         referencedItemID = int.Parse(navigator.Value);
                ContentItem referencedItem   = journal.Find(referencedItemID);
                if (referencedItem != null)
                {
                    collection.Add(ContentDetail.New(
                                       collection.EnclosingItem,
                                       attributes["name"],
                                       referencedItem,
                                       meta));
                }
                else
                {
                    journal.Register(referencedItemID, (item) =>
                    {
                        collection.Add(ContentDetail.New(
                                           collection.EnclosingItem,
                                           attributes["name"],
                                           item,
                                           meta));
                    }, relationType: "collectionlink");
                }
            }
            else if (type == typeof(Enum))
            {
                if (!string.IsNullOrEmpty(meta))
                {
                    collection.Add(ContentDetail.New(
                                       collection.EnclosingItem,
                                       attributes["name"],
                                       Parse(navigator.Value, Type.GetType(meta))));
                }
            }
            else if (type == typeof(IMultipleValue))
            {
                var detail = detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name);
                detail.Meta = meta;
                detail.AddTo(collection);
            }
            else
            {
                object value = Parse(navigator.Value, type);
                if (value is string)
                {
                    value = detailReader.PrepareStringDetail(collection.EnclosingItem, collection.Name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"]));
                }

                collection.Add(ContentDetail.New(collection.EnclosingItem, attributes["name"], value, meta));
            }
        }
コード例 #16
0
        private void SetRightsToControls()
        {
            bool temp = DetailCollection.HasAccess(Users.CurrentUser.Role, DataEvent.Create);

            buttonAddDetail.Enabled      = temp;
            toolStripMenuItemAdd.Enabled = temp;
            headerControl1.ActionControl.ShowEditButton =
                DetailCollection.HasAccess(Users.CurrentUser.Role, DataEvent.Update);
        }
コード例 #17
0
        public void CanClear_DetailCollection()
        {
            DetailCollection collection = new DetailCollection();
            collection.Add("hello");

            collection.Clear();

            Assert.That(collection.Count, Is.EqualTo(0));
        }
コード例 #18
0
        public void CanAdd_StringDetail()
        {
            DetailCollection collection = new DetailCollection();
            collection.Add("hello");

            Assert.That(collection[0], Is.EqualTo("hello"));
            Assert.That(collection.Details[0], Is.TypeOf(typeof(StringDetail)));
            Assert.That(collection.Details[0].Value, Is.EqualTo("hello"));
        }
コード例 #19
0
        public void CanAdd_IntDetail()
        {
            DetailCollection collection = new DetailCollection();
            collection.Add(1);

            Assert.That(collection[0], Is.EqualTo(1));
            Assert.That(collection.Details[0], Is.TypeOf(typeof(IntegerDetail)));
            Assert.That(collection.Details[0].Value, Is.EqualTo(1));
        }
コード例 #20
0
        public void HashCode_RemainsTheSame_AfterUpdatingID()
        {
            DetailCollection collection = new DetailCollection();
            int originalHashCode        = collection.GetHashCode();

            collection.ID = 123;

            Assert.That(collection.GetHashCode(), Is.EqualTo(originalHashCode));
        }
コード例 #21
0
        public void CanRemove_AtIndex()
        {
            DetailCollection collection = new DetailCollection(null, null, "hello", "world");

            collection.RemoveAt(0);

            Assert.That(collection.Count, Is.EqualTo(1));
            Assert.That(collection[0], Is.EqualTo("world"));
        }
コード例 #22
0
        public void CanAddRange()
        {
            DetailCollection collection = new DetailCollection();

            collection.AddRange(new[] { "hello", "world" });

            Assert.That(collection[0], Is.EqualTo("hello"));
            Assert.That(collection[1], Is.EqualTo("world"));
        }
コード例 #23
0
 /// <summary>
 /// Clear Grid and Listbox
 /// </summary>
 /// <returns></returns>
 /// 2019/07/13, Vinoth N,  Initial Version
 private void Clear()
 {
     LineCollection.Clear();
     DetailCollection.Clear();
     ErrorCollection.Clear();
     counterStatus.Content = "";
     b_Download.IsEnabled  = false;
     tbk_counter.Text      = "0";
 }
コード例 #24
0
		public void CanFind_IndexOfInteger()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add(1);
			collection.Add(2);

			Assert.That(collection.IndexOf(1), Is.EqualTo(0));
			Assert.That(collection.IndexOf(2), Is.EqualTo(1));
		}
コード例 #25
0
		public void CanInsert_IntoCollection()
		{
			DetailCollection collection = new DetailCollection();
			collection.Insert(0, "hello");
			collection.Insert(0, "world");

			Assert.That(collection.IndexOf("hello"), Is.EqualTo(1));
			Assert.That(collection.IndexOf("world"), Is.EqualTo(0));
		}
コード例 #26
0
        public void IndexOf_NotFoundItem_IsNegativeOne()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add("hello");
            collection.Add("world");

            Assert.That(collection.IndexOf("sweden"), Is.EqualTo(-1));
        }
コード例 #27
0
		public void CanRemove_AtIndex()
		{
			DetailCollection collection = new DetailCollection(null, null, "hello", "world");

			collection.RemoveAt(0);

			Assert.That(collection.Count, Is.EqualTo(1));
			Assert.That(collection[0], Is.EqualTo("world"));
		}
コード例 #28
0
        private IEnumerable <ContentItem> UpdateLinksInternal(ContentItem item, bool recursive)
        {
            logger.DebugFormat("Updating link: {0}", item);

            if (recursive)
            {
                foreach (var part in item.Children.FindParts())
                {
                    foreach (var updatedItem in UpdateLinksInternal(part, recursive))
                    {
                        yield return(updatedItem);
                    }
                }
            }

            var referencedItems    = FindLinkedObjects(item).ToList();
            DetailCollection links = item.GetDetailCollection(LinkDetailName, false);

            if (links == null && referencedItems.Count == 0)
            {
                logger.Debug("Exiting due to no links and none to update");
                yield break;
            }

            if (links == null)
            {
                links = item.GetDetailCollection(LinkDetailName, true);
            }

            logger.DebugFormat("Updating {0} links to {1} existing", referencedItems.Count, links.Count);

            // replace existing items
            for (int i = 0; i < referencedItems.Count && i < links.Count; i++)
            {
                var extracted = referencedItems[i];
                var stored    = links.Details[i];
                if (stored.StringValue == extracted.StringValue && stored.Meta == extracted.Meta && stored.IntValue == extracted.IntValue && stored.BoolValue == extracted.BoolValue)
                {
                    // this prevents clearing item references to children when moving hierarchies
                    continue;
                }
                stored.Extract(extracted);
            }
            // add any new items
            for (int i = links.Details.Count; i < referencedItems.Count; i++)
            {
                links.Add(referencedItems[i]);
            }
            // remove any extra items
            while (links.Count > referencedItems.Count)
            {
                links.RemoveAt(links.Count - 1);
            }

            yield return(item);
        }
コード例 #29
0
        public void CanFind_IndexOfString()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add("hello");
            collection.Add("world");

            Assert.That(collection.IndexOf("hello"), Is.EqualTo(0));
            Assert.That(collection.IndexOf("world"), Is.EqualTo(1));
        }
コード例 #30
0
		public void CanAdd_StringDetail()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add("hello");

			Assert.That(collection[0], Is.EqualTo("hello"));
			Assert.That(collection.Details[0].ValueType, Is.EqualTo(typeof(string)));
			Assert.That(collection.Details[0].ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.StringType));
			Assert.That(collection.Details[0].Value, Is.EqualTo("hello"));
		}
コード例 #31
0
        public void CanInsert_IntoCollection()
        {
            DetailCollection collection = new DetailCollection();

            collection.Insert(0, "hello");
            collection.Insert(0, "world");

            Assert.That(collection.IndexOf("hello"), Is.EqualTo(1));
            Assert.That(collection.IndexOf("world"), Is.EqualTo(0));
        }
コード例 #32
0
        public void CanClear_DetailCollection()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add("hello");

            collection.Clear();

            Assert.That(collection.Count, Is.EqualTo(0));
        }
コード例 #33
0
 List<ITag> GetCurrentTags(IGroup group, DetailCollection links)
 {
     List<ITag> tags = new List<ITag>();
     foreach (ContentItem link in links)
     {
         if(link.Parent != null && link.Parent.Equals(group))
             tags.Add(link as ITag);
     }
     return tags;
 }
コード例 #34
0
        public void CanClone_Collection()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add("hello");

            DetailCollection cloned = collection.Clone();

            Assert.That(cloned.Contains("hello"));
        }
コード例 #35
0
        public void ClonedCollection_IdentifierIsCleared()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add("hello");

            DetailCollection cloned = collection.Clone();

            Assert.That(cloned.ID, Is.EqualTo(0));
        }
コード例 #36
0
		public void CanAdd_IntDetail()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add(1);

			Assert.That(collection[0], Is.EqualTo(1));
			Assert.That(collection.Details[0].ValueType, Is.EqualTo(typeof(int)));
			Assert.That(collection.Details[0].ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.IntType));
			Assert.That(collection.Details[0].Value, Is.EqualTo(1));
		}
コード例 #37
0
        public void CanReplace_ValuesInCollection()
        {
            DetailCollection collection = new DetailCollection(null, null, "hello", "world");

            collection.Replace(new[] { "hi", "world" });

            Assert.That(collection.Contains("hi"));
            Assert.That(collection.Contains("world"));
            Assert.That(!collection.Contains("hello"));
        }
コード例 #38
0
        public void CanFind_IndexOfInteger()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add(1);
            collection.Add(2);

            Assert.That(collection.IndexOf(1), Is.EqualTo(0));
            Assert.That(collection.IndexOf(2), Is.EqualTo(1));
        }
コード例 #39
0
        protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal)
        {
            Dictionary<string, string> attributes = GetAttributes(navigator);
            Type type = Utility.TypeFromName(attributes["typeName"]);

			string meta = attributes.ContainsKey("meta") ? attributes["meta"] : null;
            if (type == typeof(ContentItem))
            {
                int referencedItemID = int.Parse(navigator.Value);
                ContentItem referencedItem = journal.Find(referencedItemID);
                if (referencedItem != null)
                {
                    collection.Add(ContentDetail.New(
                        collection.EnclosingItem,
                        attributes["name"],
                        referencedItem, 
						meta));
                }
                else
                {
                    journal.Register(referencedItemID, (item) => 
                        {
                            collection.Add(ContentDetail.New(
                                collection.EnclosingItem,
                                attributes["name"],
                                item,
								meta));
                        }, relationType: "collectionlink");
                }
            }
            else if (type == typeof(Enum))
            {
                if (meta != null)
                {
                    collection.Add(ContentDetail.New(
                        collection.EnclosingItem,
                        attributes["name"],
                        Parse(navigator.Value, Type.GetType(meta))));
                }
            }
            else if (type == typeof(IMultipleValue))
            {
				var detail = detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name);
				detail.Meta = meta;
				detail.AddTo(collection);
            }
            else
            {
                object value = Parse(navigator.Value, type);
                if (value is string)
                    value = detailReader.PrepareStringDetail(collection.EnclosingItem, collection.Name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"]));

                collection.Add(ContentDetail.New(collection.EnclosingItem, attributes["name"], value, meta));
            }
        }
コード例 #40
0
		protected virtual void WriteDetailCollection(ContentItem item, XmlTextWriter writer, DetailCollection collection)
		{
			using (ElementWriter collectionElement = new ElementWriter("collection", writer))
			{
				collectionElement.WriteAttribute("name", collection.Name);
				foreach (ContentDetail detail in collection.Details)
				{
					WriteDetail(item, detail, writer);
				}
			}
		}
コード例 #41
0
        public void CanReplace_ValuesInCollection_WithoutRemoving_ExistingDetails()
        {
            DetailCollection collection = new DetailCollection(null, null, "hello", "world");

            collection.Details[0].ID = 666;
            collection.Details[1].ID = 777;

            collection.Replace(new[] { "hi", "world" });

            Assert.That(collection.Details.Where(d => d.ID == 777).Single().Value, Is.EqualTo("world"));
        }
コード例 #42
0
        public void CanAdd_StringDetail()
        {
            DetailCollection collection = new DetailCollection();

            collection.Add("hello");

            Assert.That(collection[0], Is.EqualTo("hello"));
            Assert.That(collection.Details[0].ValueType, Is.EqualTo(typeof(string)));
            Assert.That(collection.Details[0].ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.StringType));
            Assert.That(collection.Details[0].Value, Is.EqualTo("hello"));
        }
コード例 #43
0
        public void CanGet_StronglyTypeEnumerator()
        {
            DetailCollection collection = new DetailCollection();

            collection.AddRange(new object[] { 1, 2, 3 });

            foreach (int number in collection.Enumerate <int>())
            {
                Assert.That(number >= 1 && number <= 3);
            }
        }
コード例 #44
0
        public void CanConvert_ToArray()
        {
            DetailCollection collection = new DetailCollection();
            collection.AddRange(new[] { 1, 2, 3 });

            int[] array = collection.ToArray<int>();

            Assert.That(array.Length, Is.EqualTo(3));
            Assert.That(array[0], Is.EqualTo(1));
            Assert.That(array[2], Is.EqualTo(3));
        }
コード例 #45
0
        public void CanConvert_ToList()
        {
            DetailCollection collection = new DetailCollection();
            collection.AddRange(new[] { 1, 2, 3 });

            IList<int> list = collection.ToList<int>();

            Assert.That(list.Count, Is.EqualTo(3));
            Assert.That(list[0], Is.EqualTo(1));
            Assert.That(list[2], Is.EqualTo(3));
        }
コード例 #46
0
		protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal)
		{
			Dictionary<string, string> attributes = GetAttributes(navigator);
			Type type = Utility.TypeFromName(attributes["typeName"]);

			if (type == typeof(ContentItem))
			{
				int referencedItemID = int.Parse(navigator.Value);
				ContentItem referencedItem = journal.Find(referencedItemID);
				if (referencedItem != null)
				{
					collection.Add(ContentDetail.New(
						collection.EnclosingItem,
						attributes["name"],
						referencedItem));
				}
				else
				{
					journal.Register(referencedItemID, (item) => 
						{
							collection.Add(ContentDetail.New(
								collection.EnclosingItem,
								attributes["name"],
								item));
						});
				}
			}
			else if (type == typeof(Enum))
			{
				if (attributes.ContainsKey("meta"))
				{
					collection.Add(ContentDetail.New(
						collection.EnclosingItem,
						attributes["name"],
						Parse(navigator.Value, Type.GetType(attributes["meta"]))));
				}
			}
			else if (type == typeof(IMultipleValue))
			{
				detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name).AddTo(collection);
			}
			else
			{
				collection.Add(ContentDetail.New(
					collection.EnclosingItem,
					attributes["name"],
					Parse(navigator.Value, type)));
			}
		}
コード例 #47
0
        protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal)
        {
            Dictionary<string, string> attributes = GetAttributes(navigator);
            Type type = Utility.TypeFromName(attributes["typeName"]);

            if (type == typeof(ContentItem))
            {
                int referencedItemID = int.Parse(navigator.Value);
                ContentItem referencedItem = journal.Find(referencedItemID);
                if (referencedItem != null)
                {
                    collection.Add(ContentDetail.New(
                        collection.EnclosingItem,
                        attributes["name"],
                        referencedItem));
                }
                else
                {
                    journal.ItemAdded += delegate(object sender, ItemEventArgs e)
                                    {
                                        if (e.AffectedItem.ID == referencedItemID)
                                        {
                                            collection.Add(ContentDetail.New(
                                                collection.EnclosingItem,
                                                attributes["name"],
                                                e.AffectedItem));
                                        }
                                    };
                }
            }
            else if (type == typeof(IMultipleValue))
            {
                detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name).AddTo(collection);
            }
            else
            {
                collection.Add(ContentDetail.New(
                    collection.EnclosingItem,
                    attributes["name"],
                    Parse(navigator.Value, type)));
            }
        }
コード例 #48
0
		public void CanCopyToArray()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add("hello");

			string[] array = new string[1];
			collection.CopyTo(array, 0);

			Assert.That(array[0], Is.EqualTo("hello"));
		}
コード例 #49
0
		public void CanEnumerate_ValuesInCollection()
		{
			DetailCollection collection = new DetailCollection();
			collection.AddRange(new[] {1, 2, 3});

			int i = 0;
			foreach (var o in collection)
			{
				Assert.That(o, Is.EqualTo(++i));
			}
		}
コード例 #50
0
		public void CanFind_IndexOfString()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add("hello");
			collection.Add("world");

			Assert.That(collection.IndexOf("hello"), Is.EqualTo(0));
			Assert.That(collection.IndexOf("world"), Is.EqualTo(1));
		}
コード例 #51
0
		public void HashCode_RemainsTheSame_AfterUpdatingID()
		{
			DetailCollection collection = new DetailCollection();
			int originalHashCode = collection.GetHashCode();

			collection.ID = 123;

			Assert.That(collection.GetHashCode(), Is.EqualTo(originalHashCode));
		}
コード例 #52
0
		public void Contains_IsTrue_ForContainedString()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add("hello");

			Assert.That(collection.Contains("hello"));
		}
コード例 #53
0
		public void CanGet_StronglyTypeEnumerator()
		{
			DetailCollection collection = new DetailCollection();
			collection.AddRange(new object[] { 1, 2, 3 });

			foreach (int number in collection.Enumerate<int>())
			{
				Assert.That(number >= 1 && number <= 3);
			}
		}
コード例 #54
0
		public void UsesBusinessEquality_ToCompare_OnCollections()
		{
			DetailCollection collection = new DetailCollection();
			collection.ID = 123;

			DetailCollection collection2 = new DetailCollection();
			collection2.ID = 123;

			Assert.That(collection.Equals(collection2));
		}
コード例 #55
0
		public void Collection_CanCombine_MultipleTypes()
		{
			object[] objects = new object[] {"hello", 1, 3.1415, true, N2.Utility.CurrentTime(), new Content.AnItem(), new object[0]};
			DetailCollection collection = new DetailCollection();
			collection.AddRange(objects);

            foreach(object o in objects)
				Assert.That(collection.Contains(o));
		}
コード例 #56
0
		public void CanReplace_ValuesInCollection_WithoutRemoving_ExistingDetails()
		{
			DetailCollection collection = new DetailCollection(null, null, "hello", "world");
			collection.Details[0].ID = 666;
			collection.Details[1].ID = 777;

			collection.Replace(new[] { "hi", "world" });

			Assert.That(collection.Details.Where(d => d.ID == 777).Single().Value, Is.EqualTo("world"));
		}
コード例 #57
0
		public void UpdatedEnclosingItem_UpdatesDetails()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add("hello");

			var item = new Content.AnItem();
			collection.EnclosingItem = item;

			Assert.That(collection.EnclosingItem, Is.EqualTo(item));
			Assert.That(collection.Details[0].EnclosingItem, Is.EqualTo(item));
		}
コード例 #58
0
		public void ClonedCollection_IdentifierIsCleared()
		{
			DetailCollection collection = new DetailCollection();
			collection.Add("hello");

			DetailCollection cloned = collection.Clone();
			Assert.That(cloned.ID, Is.EqualTo(0));
		}
コード例 #59
0
		public void CanReplace_ValuesInCollection()
		{
			DetailCollection collection = new DetailCollection(null, null, "hello", "world");

			collection.Replace(new[] {"hi", "world"});

			Assert.That(collection.Contains("hi"));
			Assert.That(collection.Contains("world"));
			Assert.That(!collection.Contains("hello"));
		}
コード例 #60
0
		public void CanReplaceInDictionary()
		{
			DetailCollection collection = new DetailCollection();
			collection.Replace(new Dictionary<string, object> { { "One", 1 }, { "Two", 2 } });
			collection.Replace(new Dictionary<string, object> { { "One", 1 }, { "Three", 3 } });
			var dict = collection.AsDictionary();

			dict.Count.ShouldBe(2);
			dict["One"].ShouldBe(1);
			dict["Three"].ShouldBe(3);
		}