Exemple #1
0
        private static void AddCustomProperty(XmlReader reader, SsdpDevice device)
        {
            var newProp = new SsdpDeviceProperty()
            {
                Namespace = reader.Prefix, Name = reader.LocalName
            };
            int depth = reader.Depth;

            reader.Read();
            while (reader.NodeType == XmlNodeType.Whitespace || reader.NodeType == XmlNodeType.Comment)
            {
                reader.Read();
            }

            if (reader.NodeType != XmlNodeType.CDATA && reader.NodeType != XmlNodeType.Text)
            {
                while (!reader.EOF && (reader.NodeType != XmlNodeType.EndElement || reader.Name != newProp.Name || reader.Prefix != newProp.Namespace || reader.Depth != depth))
                {
                    reader.Read();
                }
                if (!reader.EOF)
                {
                    reader.Read();
                }
                return;
            }

            newProp.Value = reader.Value;

            // We don't support complex nested types or repeat/multi-value properties
            if (!device.CustomProperties.Contains(newProp.FullName))
            {
                device.CustomProperties.Add(newProp);
            }
        }
 public void SsdpDevicePropertiesCollection_Add_EmptyFullNameThrows()
 {
     var properties = new SsdpDevicePropertiesCollection();
     var p = new SsdpDeviceProperty()
     {
         Name = String.Empty,
         Namespace = String.Empty
     };
     properties.Add(p);
 }
Exemple #3
0
        private static void AddCustomProperty(XmlReader reader, SsdpDevice device)
        {
            var newProp = new SsdpDeviceProperty()
            {
                Namespace = reader.Prefix, Name = reader.LocalName, Value = reader.ReadElementContentAsString()
            };

            // We don't support complex nested types or repeat/multi-value properties
            if (!device.CustomProperties.Contains(newProp.FullName))
            {
                device.CustomProperties.Add(newProp);
            }
        }
 public void SsdpDevicePropertiesCollection_Contains_PropertyWithEmptyNameThrows()
 {
     var properties = new SsdpDevicePropertiesCollection();
     var p = new SsdpDeviceProperty()
         {
             Name = String.Empty,
             Namespace=  String.Empty
         };
     properties.Contains(p);
 }
        public void SsdpDevicePropertiesCollection_Remove_RemoveInstanceSucceeds()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var p = new SsdpDeviceProperty()
            {
                Name = "TestProp1",
                Namespace = "TestNamespace"
            };

            properties.Add(p);

            Assert.AreEqual(true, properties.Remove(p));
            Assert.AreEqual(0, properties.Count);
        }
        public void SsdpDevicePropertiesCollection_Remove_RemoveInstanceForDifferentInstanceWithSameKeyReturnsFalse()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var p = new SsdpDeviceProperty()
            {
                Name = "TestProp1",
                Namespace = "TestNamespace"
            };

            var p2 = new SsdpDeviceProperty()
            {
                Name = "TestProp1",
                Namespace = "TestNamespace"
            };

            properties.Add(p);

            Assert.AreEqual(false, properties.Remove(p2));
            Assert.AreEqual(1, properties.Count);
        }
 public void SsdpDevicePropertiesCollection_Remove_NullFullNameThrows()
 {
     var properties = new SsdpDevicePropertiesCollection();
     var p = new SsdpDeviceProperty();
     properties.Remove(p);
 }
        public void SsdpDevicePropertiesCollection_Indexer_ThrowsOnUnknownKey()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var p = new SsdpDeviceProperty()
            {
                Name = "Test",
                Namespace = "TestNamespace",
                Value = "some value"
            };
            properties.Add(p);

            Assert.AreEqual(p, properties["NotAValidKey"]);
        }
        public void SsdpDevicePropertiesCollection_Indexer_Succeeds()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var p = new SsdpDeviceProperty()
            {
                Name = "Test",
                Namespace = "TestNamespace",
                Value = "some value"
            };
            properties.Add(p);

            Assert.AreEqual(p, properties[p.FullName]);
        }
        private SsdpRootDevice CreateSampleRootDevice()
        {
            var retVal = new SsdpRootDevice()
            {
                CacheLifetime = TimeSpan.FromMinutes(30),
                DeviceType = "TestDeviceType",
                DeviceTypeNamespace = "test-device-ns",
                FriendlyName = "Test Device 1",
                Location = new Uri("http://testdevice:1700/xml"),
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testman.com"),
                ModelDescription = "A test device",
                ModelName = "Test Model",
                ModelNumber = "1234",
                ModelUrl = new Uri("http://testmodel.com"),
                PresentationUrl = new Uri("http://testmodel.com/presentation"),
                SerialNumber = "TM-12345",
                Upc = "123456789012",
                UrlBase = new Uri("http://testdevice:1700"),
                Uuid = Guid.NewGuid().ToString()
            };

            var customProp = new SsdpDeviceProperty() { Namespace = "custom-ns", Name = "TestProp1", Value = "Test" };
            retVal.CustomProperties.Add(customProp);
            customProp = new SsdpDeviceProperty() { Namespace = "custom-ns", Name = "TestProp2", Value = "Test" };
            retVal.CustomProperties.Add(customProp);

            var icon = new SsdpDeviceIcon() { ColorDepth = 32, Height = 48, Width = 48, MimeType = "image/png", Url = new Uri("icons/48", UriKind.Relative) };
            retVal.Icons.Add(icon);
            icon = new SsdpDeviceIcon() { ColorDepth = 32, Height = 120, Width = 120, MimeType = "image/png", Url = new Uri("icons/120", UriKind.Relative) };
            retVal.Icons.Add(icon);

            return retVal;
        }
        public void SsdpDevicePropertiesCollection_Count_ReturnsZeroAfterLastItemRemoved()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var prop = new SsdpDeviceProperty()
            {
                Name = "TestProperty",
                Namespace = "MyNamespace",
                Value = "1.0"
            };

            properties.Remove(prop);
            Assert.AreEqual(0, properties.Count);
        }
        public void SsdpDevicePropertiesCollection_Count_ReturnsOneAfterItemAdded()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var prop = new SsdpDeviceProperty()
            {
                Name = "TestProperty",
                Namespace = "MyNamespace",
                Value = "1.0"
            };

            properties.Add(prop);

            Assert.AreEqual(1, properties.Count);
        }
        public void SsdpDevicePropertiesCollection_Contains_ReturnsTrueForExistingKey()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var prop = new SsdpDeviceProperty()
            {
                Name = "TestProperty",
                Namespace = "MyNamespace",
                Value = "1.0"
            };

            properties.Add(prop);

            Assert.AreEqual(true, properties.Contains(prop.FullName));
        }
        public void SsdpDevicePropertiesCollection_Contains_ReturnsFalseForNonExistentProperty()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var prop = new SsdpDeviceProperty()
            {
                Name = "TestProperty",
                Namespace = "MyNamespace",
                Value = "1.0"
            };

            var prop2 = new SsdpDeviceProperty()
            {
                Name = "TestProperty1",
                Namespace = "MyNamespace",
                Value = "1.0"
            };

            properties.Add(prop);

            Assert.AreEqual(false, properties.Contains(prop2));
        }
 public void SsdpDevicePropertiesCollection_Contains_PropertyWithNullNameThrows()
 {
     var properties = new SsdpDevicePropertiesCollection();
     var p = new SsdpDeviceProperty();
     properties.Contains(p);
 }
        public void SsdpDevicePropertiesCollection_GetEnumerator_Success()
        {
            var properties = new SsdpDevicePropertiesCollection();
            var prop = new SsdpDeviceProperty()
            {
                Name = "TestProperty",
                Namespace = "MyNamespace",
                Value = "1.0"
            };

            properties.Add(prop);
            var enumerator = ((IEnumerable)properties).GetEnumerator();

            Assert.AreEqual(true, enumerator.MoveNext());
            Assert.AreEqual(prop, enumerator.Current);
            Assert.AreEqual(false, enumerator.MoveNext());
        }
Exemple #17
0
 private static void AddCustomProperty(XmlReader reader, SsdpDevice device)
 {
     var newProp = new SsdpDeviceProperty() { Namespace = reader.Prefix, Name = reader.LocalName, Value = reader.ReadElementContentAsString() };
     // We don't support complex nested types or repeat/multi-value properties
     if (!device.CustomProperties.Contains(newProp.FullName))
         device.CustomProperties.Add(newProp);
 }