Ejemplo n.º 1
0
        public void Ctor_FromString_ToStringEqualsOriginal(string input)
        {
            // Arrange
            var val = new HiveIdValue(input);

            NUnit.Framework.Assert.AreEqual(val.ToString(), input);
        }
Ejemplo n.º 2
0
        public void ToString_ShouldShowValueOrNull()
        {
            // Arrange
            var val1 = new HiveIdValue("my-string-id");

            // Assert
            Assert.AreEqual("my-string-id", val1.ToString());
            Assert.AreEqual("(null)", HiveIdValue.Empty.ToString());
        }
Ejemplo n.º 3
0
        public void ToString_ShouldShowValueOrNull()
        {
            // Arrange
            var val1 = new HiveIdValue("my-string-id");

            // Assert
            Assert.AreEqual("my-string-id", val1.ToString());
            Assert.AreEqual("(null)", HiveIdValue.Empty.ToString());
        }
Ejemplo n.º 4
0
        public void ConvertIntToGuid_AsSystem()
        {
            // Arrange
            var val1 = HiveIdValue.ConvertIntToGuid(-345);

            Assert.AreEqual(HiveIdValueTypes.Guid, val1.Type);
            Assert.AreEqual(Guid.Parse("10000000-0000-0000-0000-000000000345"), (Guid)val1.Value);
            Assert.IsTrue(val1.IsSystem);
        }
Ejemplo n.º 5
0
        public void Hashcode_ShouldNotBeEqualAcrossInstancesOfDifferentValue()
        {
            // Arrange
            var val1 = new HiveIdValue("my-string-id");
            var val2 = new HiveIdValue("my-string-id2");

            // Assert
            Assert.AreNotEqual(val1.GetHashCode(), val2.GetHashCode());
            Assert.AreNotEqual(val1.GetHashCode(), HiveIdValue.Empty.GetHashCode());
        }
Ejemplo n.º 6
0
        public void Hashcode_ShouldNotBeEqualAcrossInstancesOfDifferentValue()
        {
            // Arrange
            var val1 = new HiveIdValue("my-string-id");
            var val2 = new HiveIdValue("my-string-id2");

            // Assert
            Assert.AreNotEqual(val1.GetHashCode(), val2.GetHashCode());
            Assert.AreNotEqual(val1.GetHashCode(), HiveIdValue.Empty.GetHashCode());
        }
Ejemplo n.º 7
0
        public void Equals_ShouldNotBeEqual_DueToDifferentTypes()
        {
            // Arrange
            var val  = new HiveIdValue("my-string-id");
            var val2 = new HiveIdValue(Guid.NewGuid());

            // Assert
            Assert.AreNotEqual(val, val2);
            Assert.IsFalse(val == val2);
            Assert.IsTrue(val != val2);
        }
Ejemplo n.º 8
0
        public void Constructed_As_Int_Sets_Type()
        {
            // Arrange
            var val = new HiveIdValue(5);

            // Act

            // Assert
            Assert.AreEqual(HiveIdValueTypes.Int32, val.Type);
            Assert.AreEqual(5, val.Value);
            Assert.AreEqual(5, (int)val);
        }
Ejemplo n.º 9
0
        public void Constructed_As_String_Sets_Type()
        {
            // Arrange
            var val = new HiveIdValue("my-string-id");

            // Act

            // Assert
            Assert.AreEqual(HiveIdValueTypes.String, val.Type);
            Assert.AreEqual("my-string-id", val.Value);
            Assert.AreEqual("my-string-id", (string)val);
        }
Ejemplo n.º 10
0
        public void Constructed_As_Guid_Sets_Type()
        {
            // Arrange
            var guid = Guid.NewGuid();
            var val  = new HiveIdValue(guid);

            // Act

            // Assert
            Assert.AreEqual(HiveIdValueTypes.Guid, val.Type);
            Assert.AreEqual(guid, val.Value);
            Assert.AreEqual(guid, (Guid)val);
        }
        public void Converts_From_Int()
        {
            //Arrange

            var id = new HiveIdValue(1234);
            var converter = TypeDescriptor.GetConverter(typeof(HiveIdValue));

            //Act


            //Assert

            Assert.IsTrue(converter.CanConvertFrom(typeof(int)));
            Assert.IsTrue(converter.CanConvertTo(typeof(string)));
            Assert.AreEqual(1234, converter.ConvertTo(id, typeof(int)));
            Assert.AreEqual(id, converter.ConvertFrom(1234));
        }
Ejemplo n.º 12
0
        public void Converts_From_Int()
        {
            //Arrange

            var id        = new HiveIdValue(1234);
            var converter = TypeDescriptor.GetConverter(typeof(HiveIdValue));

            //Act


            //Assert

            Assert.IsTrue(converter.CanConvertFrom(typeof(int)));
            Assert.IsTrue(converter.CanConvertTo(typeof(string)));
            Assert.AreEqual(1234, converter.ConvertTo(id, typeof(int)));
            Assert.AreEqual(id, converter.ConvertFrom(1234));
        }
        public void Converts_From_String()
        {
            //Arrange

            var rawId = new HiveIdValue("My-Test-Template.cshtml");
            var encodedId = rawId.ToString();
            var converter = TypeDescriptor.GetConverter(typeof(HiveIdValue));

            //Act


            //Assert

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsTrue(converter.CanConvertTo(typeof(string)));
            Assert.AreEqual(encodedId, converter.ConvertTo(rawId, typeof(string)));
            Assert.AreEqual(rawId, converter.ConvertFrom(encodedId));
        }
Ejemplo n.º 14
0
        public void Converts_From_String()
        {
            //Arrange

            var rawId     = new HiveIdValue("My-Test-Template.cshtml");
            var encodedId = rawId.ToString();
            var converter = TypeDescriptor.GetConverter(typeof(HiveIdValue));

            //Act


            //Assert

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)));
            Assert.IsTrue(converter.CanConvertTo(typeof(string)));
            Assert.AreEqual(encodedId, converter.ConvertTo(rawId, typeof(string)));
            Assert.AreEqual(rawId, converter.ConvertFrom(encodedId));
        }
Ejemplo n.º 15
0
        public void Converts_From_Guid()
        {
            //Arrange

            var guid      = Guid.NewGuid();
            var id        = new HiveIdValue(guid);
            var converter = TypeDescriptor.GetConverter(typeof(HiveIdValue));

            //Act


            //Assert

            Assert.IsTrue(converter.CanConvertFrom(typeof(Guid)));
            Assert.IsTrue(converter.CanConvertTo(typeof(string)));
            Assert.AreEqual(guid, converter.ConvertTo(id, typeof(Guid)));
            Assert.AreEqual(id, converter.ConvertFrom(guid));
        }
        public void Converts_From_Guid()
        {
            //Arrange

            var guid = Guid.NewGuid();
            var id = new HiveIdValue(guid);
            var converter = TypeDescriptor.GetConverter(typeof(HiveIdValue));

            //Act


            //Assert

            Assert.IsTrue(converter.CanConvertFrom(typeof(Guid)));
            Assert.IsTrue(converter.CanConvertTo(typeof(string)));
            Assert.AreEqual(guid, converter.ConvertTo(id, typeof(Guid)));
            Assert.AreEqual(id, converter.ConvertFrom(guid));

        }
Ejemplo n.º 17
0
        internal HiveIdValue NormaliseValue(HiveIdValue value)
        {
            Mandate.ParameterCondition(value.Type == HiveIdValueTypes.String, "id");

            var pathValue = (string)value.Value;

            pathValue = pathValue.Replace("/", "\\");

            if (!pathValue.IsNullOrWhiteSpace() && pathValue != "\\")
            {
                if (!pathValue.StartsWith(Settings.AbsoluteRootedPath))
                {
                    return(new HiveIdValue(pathValue));
                }
            }

            pathValue = pathValue.Replace(Settings.AbsoluteRootedPath, string.Empty);

            return(new HiveIdValue(pathValue));
        }
Ejemplo n.º 18
0
        public void Equals_ShouldNotBeEqual()
        {
            // Arrange
            var stringVal  = new HiveIdValue("my-string-id");
            var stringVal2 = new HiveIdValue("my-string-id2");
            var guidVal    = new HiveIdValue(Guid.NewGuid());
            var guidVal2   = new HiveIdValue(Guid.NewGuid());
            var intVal     = new HiveIdValue(5);
            var intVal2    = new HiveIdValue(6);

            // Assert
            Assert.IsFalse(stringVal.Equals(stringVal2));
            Assert.IsFalse(guidVal.Equals(guidVal2));
            Assert.IsFalse(intVal.Equals(intVal2));
            Assert.IsFalse(stringVal == stringVal2);
            Assert.IsFalse(guidVal == guidVal2);
            Assert.IsFalse(intVal == intVal2);
            Assert.IsTrue(stringVal != stringVal2);
            Assert.IsTrue(guidVal != guidVal2);
            Assert.IsTrue(intVal != intVal2);
        }
Ejemplo n.º 19
0
        public void Equals_ShouldBeEqual()
        {
            // Arrange
            var guid = Guid.NewGuid();
            var stringVal = new HiveIdValue("my-string-id");
            var stringVal2 = new HiveIdValue("my-string-id");
            var guidVal = new HiveIdValue(guid);
            var guidVal2 = new HiveIdValue(guid);
            var intVal = new HiveIdValue(5);
            var intVal2 = new HiveIdValue(5);

            // Assert
            Assert.IsTrue(stringVal.Equals(stringVal2));
            Assert.IsTrue(guidVal.Equals(guidVal2));
            Assert.IsTrue(intVal.Equals(intVal2));
            Assert.IsTrue(stringVal == stringVal2);
            Assert.IsTrue(guidVal == guidVal2);
            Assert.IsTrue(intVal == intVal2);
            Assert.IsFalse(stringVal != stringVal2);
            Assert.IsFalse(guidVal != guidVal2);
            Assert.IsFalse(intVal != intVal2);
        }
Ejemplo n.º 20
0
        public void Equals_ShouldNotBeEqual_DueToDifferentTypes()
        {
            // Arrange
            var val = new HiveIdValue("my-string-id");
            var val2 = new HiveIdValue(Guid.NewGuid());

            // Assert
            Assert.AreNotEqual(val, val2);
            Assert.IsFalse(val == val2);
            Assert.IsTrue(val != val2);
        }
Ejemplo n.º 21
0
        public void Constructed_As_String_Sets_Type()
        {
            // Arrange
            var val = new HiveIdValue("my-string-id");

            // Act

            // Assert
            Assert.AreEqual(HiveIdValueTypes.String, val.Type);
            Assert.AreEqual("my-string-id", val.Value);
            Assert.AreEqual("my-string-id", (string)val);
        }
Ejemplo n.º 22
0
        public void Constructed_As_Guid_Sets_Type()
        {
            // Arrange
            var guid = Guid.NewGuid();
            var val = new HiveIdValue(guid);

            // Act

            // Assert
            Assert.AreEqual(HiveIdValueTypes.Guid, val.Type);
            Assert.AreEqual(guid, val.Value);
            Assert.AreEqual(guid, (Guid)val);
        }
Ejemplo n.º 23
0
        public void Ctor_FromString_ToStringEqualsOriginal(string input)
        {
            // Arrange
            var val = new HiveIdValue(input);

            NUnit.Framework.Assert.AreEqual(val.ToString(), input);
        }
Ejemplo n.º 24
0
        public void Constructed_As_Int_Sets_Type()
        {
            // Arrange
            var val = new HiveIdValue(5);

            // Act

            // Assert
            Assert.AreEqual(HiveIdValueTypes.Int32, val.Type);
            Assert.AreEqual(5, val.Value);
            Assert.AreEqual(5, (int)val);
        }