Ejemplo n.º 1
0
        public void KnownTypes()
        {
            // cannot parse an unknown type, udi is null
            // this will scan
            Assert.IsFalse(UdiParser.TryParse("umb://whatever/1234", out Udi udi));
            Assert.IsNull(udi);

            UdiParser.ResetUdiTypes();

            // unless we want to know
            Assert.IsFalse(UdiParser.TryParse("umb://whatever/1234", true, out udi));
            Assert.AreEqual(Constants.UdiEntityType.Unknown, udi.EntityType);
            Assert.AreEqual("Umbraco.Cms.Core.UnknownTypeUdi", udi.GetType().FullName);

            UdiParser.ResetUdiTypes();

            // not known
            Assert.IsFalse(UdiParser.TryParse("umb://foo/A87F65C8D6B94E868F6949BA92C93045", true, out udi));
            Assert.AreEqual(Constants.UdiEntityType.Unknown, udi.EntityType);
            Assert.AreEqual("Umbraco.Cms.Core.UnknownTypeUdi", udi.GetType().FullName);

            // scanned
            UdiParserServiceConnectors.RegisterServiceConnector <FooConnector>(); // this is the equivalent of scanning but we'll just manually register this one
            Assert.IsTrue(UdiParser.TryParse("umb://foo/A87F65C8D6B94E868F6949BA92C93045", out udi));
            Assert.IsInstanceOf <GuidUdi>(udi);

            // known
            Assert.IsTrue(UdiParser.TryParse("umb://foo/A87F65C8D6B94E868F6949BA92C93045", true, out udi));
            Assert.IsInstanceOf <GuidUdi>(udi);

            // can get method for Deploy compatibility
            MethodInfo method = typeof(UdiParser).GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(string), typeof(bool) }, null);

            Assert.IsNotNull(method);
        }
Ejemplo n.º 2
0
        public static void Converting_Boxed_Udi_To_A_Udi_Returns_Original_Udi_Value()
        {
            // Arrange
            UdiParser.ResetUdiTypes();
            Udi sample = new GuidUdi(Constants.UdiEntityType.AnyGuid, Guid.NewGuid());

            // Act
            bool success = UmbracoHelper.ConvertIdObjectToUdi(
                sample,
                out Udi result
                );

            // Assert
            Assert.IsTrue(success);
            Assert.That(result, Is.EqualTo(sample));
        }
Ejemplo n.º 3
0
        public static void Converting_Unsupported_Object_To_A_Udi_Returns_False()
        {
            // Arrange
            UdiParser.ResetUdiTypes();

            var clearlyWillNotConvertToGuid = new StringBuilder(0);

            // Act
            bool success = UmbracoHelper.ConvertIdObjectToUdi(
                clearlyWillNotConvertToGuid,
                out Udi result
                );

            // Assert
            Assert.IsFalse(success);
            Assert.That(result, Is.Null);
        }
Ejemplo n.º 4
0
        public void Converting_Hello_To_A_Udi_Returns_False()
        {
            // Arrange
            SetUpDependencyContainer();
            UdiParser.ResetUdiTypes();
            const string sample = "Hello";

            // Act
            bool success = UmbracoHelper.ConvertIdObjectToUdi(
                sample,
                out Udi result
                );

            // Assert
            Assert.IsFalse(success);
            Assert.That(result, Is.Null);
        }
Ejemplo n.º 5
0
        public void Converting_String_Udi_To_A_Udi_Returns_Original_Udi_Value()
        {
            // Arrange
            SetUpDependencyContainer();
            UdiParser.ResetUdiTypes();
            Udi sample = new GuidUdi(Constants.UdiEntityType.AnyGuid, Guid.NewGuid());

            // Act
            bool success = UmbracoHelper.ConvertIdObjectToUdi(
                sample.ToString(),
                out Udi result
                );

            // Assert
            Assert.IsTrue(success, "Conversion of UDI failed.");
            Assert.That(result, Is.EqualTo(sample));
        }
Ejemplo n.º 6
0
 public void SetUp()
 {
     UdiParser.ResetUdiTypes();
 }