Exemple #1
0
        public void SerializeTest1()
        {
            IAttribute uut1 = new ImageUrlAttribute(null);
            IAttribute uut2 = new ImageUrlAttribute(null);

            string serializedValue = uut1.Serialize();

            uut2.Deserialize(serializedValue);

            Assert.AreEqual(uut1, uut2);
        }
Exemple #2
0
        public void SerializeTest2()
        {
            IAttribute uut1 = new ImageUrlAttribute("/MyImage.jpg")
            {
                Height = 100,
                Width  = 101
            };

            IAttribute uut2 = new ImageUrlAttribute(null);

            string serializedValue = uut1.Serialize();

            uut2.Deserialize(serializedValue);

            Assert.AreEqual(uut1, uut2);
        }
Exemple #3
0
        public void ValidateAttributeTest()
        {
            ImageUrlAttribute attr = new ImageUrlAttribute
            {
                Value = null
            };

            ImageUrlAttributeType uut = new ImageUrlAttributeType
            {
                Key      = "Some Asset",
                Required = true
            };

            // Null should throw an exception, if required is set to true.
            {
                uut.Required = true;
                ListedValidationException e;

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute(attr));
                Assert.AreEqual(1, e.Errors.Count());

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute((IAttribute)attr));
                Assert.AreEqual(1, e.Errors.Count());
            }

            // Null should not throw an exception if required is set to false.
            {
                uut.Required = false;
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // No exceptions should be thrown if required is false and a value is set.
            {
                uut.Required = false;
                attr.Value   = "https://someUrl.org/derp.jpg";
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // http:// is okay.
            {
                uut.Required = false;
                attr.Value   = "http://someUrl.com/derp.jpg";
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // No exceptions should be thrown if required is true and a value is set.
            {
                uut.Required = true;
                attr.Value   = "/Somevalue/pic.jpg";
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // No exceptions should be thrown if height and width are set, but are both are 0.
            {
                uut.Required = true;
                attr.Value   = "/Somevalue/pic2.jpg";
                attr.Height  = 0;
                attr.Width   = 0;
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // No exceptions should be thrown if height and width are set, but are both are greater than 0.
            {
                uut.Required = true;
                attr.Value   = "/Somevalue/pic2.jpg";
                attr.Height  = 1;
                attr.Width   = 1;
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // Height can not be negative.
            {
                attr.Value  = "https://shendrick.net/Somevalue/pic2.jpg";
                attr.Height = -1;
                attr.Width  = null;
                ListedValidationException e;

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute(attr));
                Assert.AreEqual(1, e.Errors.Count());

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute((IAttribute)attr));
                Assert.AreEqual(1, e.Errors.Count());
            }

            // Width can not be negative.
            {
                attr.Value  = "https://shendrick.net/Somevalue/pic3.jpg";
                attr.Height = null;
                attr.Width  = -1;
                ListedValidationException e;

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute(attr));
                Assert.AreEqual(1, e.Errors.Count());

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute((IAttribute)attr));
                Assert.AreEqual(1, e.Errors.Count());
            }

            {
                uut.Required = false;

                // If its starts with file://///, this should fail.
                attr.Value  = "file://///users/seth/somePic.jpg";
                attr.Height = null;
                attr.Width  = null;
                ListedValidationException e;

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute(attr));
                Assert.AreEqual(1, e.Errors.Count());

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute((IAttribute)attr));
                Assert.AreEqual(1, e.Errors.Count());
            }
        }
Exemple #4
0
        public void EqualsTest()
        {
            ImageUrlAttribute uut1 = new ImageUrlAttribute("/MyImage.jpg");
            ImageUrlAttribute uut2 = new ImageUrlAttribute(uut1.Value);

            Assert.AreNotEqual(uut1, 1);
            Assert.AreNotEqual(uut1, null);

            Assert.AreEqual(uut1, uut2);
            Assert.AreEqual(uut1.GetHashCode(), uut2.GetHashCode());

            // Start changing things.
            {
                uut1.Value = uut2.Value + "1";
                Assert.AreNotEqual(uut1, uut2);
                Assert.AreNotEqual(uut1.GetHashCode(), uut2.GetHashCode());
                uut1.Value = uut2.Value;
            }

            {
                uut1.Value = null;
                Assert.AreNotEqual(uut1, uut2);
                Assert.AreNotEqual(uut1.GetHashCode(), uut2.GetHashCode());
                uut1.Value = uut2.Value;
            }

            {
                uut1.Width = null;
                uut2.Width = 1;
                Assert.AreNotEqual(uut1, uut2);
                Assert.AreNotEqual(uut1.GetHashCode(), uut2.GetHashCode());
                uut1.Width = null;
                uut2.Width = null;
            }

            {
                uut1.Height = null;
                uut2.Height = 1;
                Assert.AreNotEqual(uut1, uut2);
                Assert.AreNotEqual(uut1.GetHashCode(), uut2.GetHashCode());
                uut1.Height = null;
                uut2.Height = null;
            }

            {
                uut1.Width = 1;
                uut2.Width = uut1.Width + 1;
                Assert.AreNotEqual(uut1, uut2);
                Assert.AreNotEqual(uut1.GetHashCode(), uut2.GetHashCode());
                uut1.Width = null;
                uut2.Width = null;
            }

            {
                uut1.Height = 1;
                uut2.Height = uut1.Height + 1;
                Assert.AreNotEqual(uut1, uut2);
                Assert.AreNotEqual(uut1.GetHashCode(), uut2.GetHashCode());
                uut1.Height = null;
                uut2.Height = null;
            }
        }