Exemple #1
0
        public void BdioContentTest()
        {
            string      sampleBdio = Resources.sample;
            BdioContent content    = BdioContent.Parse(sampleBdio);
            BdioContent content2   = BdioContent.Parse(sampleBdio);

            Assert.AreEqual(6, content.Count);
            Assert.IsNotNull(content.ToString());
            Assert.IsTrue(content.Equals(content2));
            Assert.IsFalse(content.Equals(null));
            Assert.AreNotEqual(0, content.GetHashCode());

            foreach (BdioNode node in content2.Components)
            {
                if (node.Relationships != null && node.Relationships.Count > 0)
                {
                    node.Relationships[0].RelationshipType = "Not a type";
                    break;
                }
            }
            Assert.IsFalse(content.Equals(content2));

            BdioComponent component = new BdioComponent();

            component.Id = "Another component";
            content2.Components.Add(component);
            Assert.IsFalse(content.Equals(content2));
        }
Exemple #2
0
        public static BdioContent Parse(string bdio)
        {
            BdioContent bdioContent = new BdioContent();
            JToken      jBdio       = JArray.Parse(bdio);

            foreach (JToken jComponent in jBdio)
            {
                BdioNode node = jComponent.ToObject <BdioNode>();
                if (node.Type.Equals("BillOfMaterials"))
                {
                    bdioContent.BillOfMaterials = jComponent.ToObject <BdioBillOfMaterials>();
                }
                else if (node.Type.Equals("Project"))
                {
                    bdioContent.Project = jComponent.ToObject <BdioProject>();
                }
                else if (node.Type.Equals("Component"))
                {
                    bdioContent.Components.Add(jComponent.ToObject <BdioComponent>());
                }
            }
            return(bdioContent);
        }