예제 #1
0
        public void DataObjectRegistry_LoadsFromJson()
        {
            try
            {
                DataObjectRegistries.Reset();
                DataObjectRegistries.Register(GetType().Assembly);

                DataObjectRegistries.Get <TestDataObject>().SetSourceFiles(new[] { Path.Combine("Data", "DataObjectRegistryData.json") });
                DataObjectRegistries.Load();

                var dobj1 = DataObjectRegistries.Get <TestDataObject>().GetObjectByKey("TEST_OBJECT_1");
                TheResultingObject(dobj1)
                .ShouldSatisfyTheCondition(x => x.Key == "TEST_OBJECT_1")
                .ShouldSatisfyTheCondition(x => x.GlobalID == new Guid("3bd956ab-24cc-49e7-a178-99111c69d24f"))
                .ShouldSatisfyTheCondition(x => x.Foo == "Hello")
                .ShouldSatisfyTheCondition(x => x.Bar == "World");

                var dobj2 = DataObjectRegistries.Get <TestDataObject>().GetObjectByKey("TEST_OBJECT_2");
                TheResultingObject(dobj2)
                .ShouldSatisfyTheCondition(x => x.Key == "TEST_OBJECT_2")
                .ShouldSatisfyTheCondition(x => x.GlobalID == new Guid("285c472e-a184-49a6-9639-d5b127ebc74a"))
                .ShouldSatisfyTheCondition(x => x.Foo == "Goodbye")
                .ShouldSatisfyTheCondition(x => x.Bar == "Universe");
            }
            finally
            {
                DataObjectRegistries.Reset();
            }
        }
예제 #2
0
        public void ResolvedDataObjectReference_DeserializesFromJson_Guid_WhenNullable()
        {
            try
            {
                DataObjectRegistries.Reset();
                DataObjectRegistries.Register(GetType().Assembly);

                DataObjectRegistries.Get <TestDataObject>().SetSourceFiles(new[] { Path.Combine("Data", "DataObjectRegistryData.xml") });
                DataObjectRegistries.Load();

                const String json1 = @"""3bd956ab-24cc-49e7-a178-99111c69d24f""";
                const String json2 = @"null";

                var reference1 = JsonConvert.DeserializeObject <ResolvedDataObjectReference?>(json1);

                TheResultingValue(reference1.Value)
                .ShouldSatisfyTheCondition(x => x.Value.Equals(Guid.Parse("3bd956ab-24cc-49e7-a178-99111c69d24f")));

                var reference2 = JsonConvert.DeserializeObject <ResolvedDataObjectReference?>(json2);

                TheResultingValue(reference2.HasValue)
                .ShouldBe(false);
            }
            finally
            {
                DataObjectRegistries.Reset();
            }
        }
        /// <summary>
        /// Gets a <see cref="System.ComponentModel.TypeConverter.StandardValuesCollection"/> containing the object references defined by the specified data object registry.
        /// </summary>
        /// <returns>The <see cref="System.ComponentModel.TypeConverter.StandardValuesCollection"/> which was created.</returns>
        private static StandardValuesCollection GetStandardValuesForRegistry()
        {
            var registry   = DataObjectRegistries.Get <T>();
            var keys       = registry.Select(x => String.Format("@{0}:{1}", registry.ReferenceResolutionName, x.Key));
            var references = (from k in keys
                              select(ResolvedDataObjectReference) ObjectResolver.FromString(k, typeof(ResolvedDataObjectReference))).ToList();

            references.Insert(0, ResolvedDataObjectReference.Invalid);

            return(new StandardValuesCollection(references));
        }
예제 #4
0
        public void ResolvedDataObjectReference_SerializesToJson_WhenNullable()
        {
            try
            {
                DataObjectRegistries.Reset();
                DataObjectRegistries.Register(GetType().Assembly);

                DataObjectRegistries.Get <TestDataObject>().SetSourceFiles(new[] { Path.Combine("Data", "DataObjectRegistryData.xml") });
                DataObjectRegistries.Load();

                var reference = DataObjectRegistries.ResolveReference("@test:TEST_OBJECT_1");
                var json1     = JsonConvert.SerializeObject((ResolvedDataObjectReference?)reference);

                TheResultingString(json1)
                .ShouldBe(@"""@test:TEST_OBJECT_1""");
            }
            finally
            {
                DataObjectRegistries.Reset();
            }
        }
예제 #5
0
        public void ResolvedDataObjectReference_SerializesToJson_Guid_WhenNullable()
        {
            try
            {
                DataObjectRegistries.Reset();
                DataObjectRegistries.Register(GetType().Assembly);

                DataObjectRegistries.Get <TestDataObject>().SetSourceFiles(new[] { Path.Combine("Data", "DataObjectRegistryData.xml") });
                DataObjectRegistries.Load();

                var reference = new ResolvedDataObjectReference(Guid.Parse("3bd956ab-24cc-49e7-a178-99111c69d24f"));
                var json      = JsonConvert.SerializeObject((ResolvedDataObjectReference?)reference);

                TheResultingString(json)
                .ShouldBe(@"""3bd956ab-24cc-49e7-a178-99111c69d24f""");
            }
            finally
            {
                DataObjectRegistries.Reset();
            }
        }
예제 #6
0
        public void ResolvedDataObjectReference_DeserializesFromJson()
        {
            try
            {
                DataObjectRegistries.Reset();
                DataObjectRegistries.Register(GetType().Assembly);

                DataObjectRegistries.Get <TestDataObject>().SetSourceFiles(new[] { Path.Combine("Data", "DataObjectRegistryData.xml") });
                DataObjectRegistries.Load();

                const String json = @"""@test:TEST_OBJECT_1""";

                var reference = JsonConvert.DeserializeObject <ResolvedDataObjectReference>(json);

                TheResultingValue(reference)
                .ShouldSatisfyTheCondition(x => x.Value.Equals(Guid.Parse("3bd956ab-24cc-49e7-a178-99111c69d24f")));
            }
            finally
            {
                DataObjectRegistries.Reset();
            }
        }
        public void ResolvedDataObjectReference_SerializesToJson()
        {
            try
            {
                DataObjectRegistries.Reset();
                DataObjectRegistries.Register(GetType().Assembly);

                DataObjectRegistries.Get <TestDataObject>().SetSourceFiles(new[] { Path.Combine("Resources", "DataObjectRegistryData.xml") });
                DataObjectRegistries.Load();

                var reference = DataObjectRegistries.ResolveReference("@test:TEST_OBJECT_1");
                var json      = JsonConvert.SerializeObject(reference,
                                                            CoreJsonSerializerSettings.Instance);

                TheResultingString(json)
                .ShouldBe(@"""@test:TEST_OBJECT_1""");
            }
            finally
            {
                DataObjectRegistries.Reset();
            }
        }
 /// <summary>
 /// Resolves an object reference. If the reference cannot be resolved, an exception is thrown.
 /// </summary>
 /// <param name="reference">The object reference to resolve.</param>
 /// <returns>The resolved object reference.</returns>
 public static ResolvedDataObjectReference ResolveReference(String reference) =>
 DataObjectRegistries.ResolveReference(reference);
 /// <summary>
 /// Loads objects for all of the application's registered data object registries.
 /// </summary>
 public static void LoadObjects() =>
 DataObjectRegistries.LoadObjects();
 /// <summary>
 /// Removes all objects from all of the application's data object registries
 /// and returns them to their default states.
 /// </summary>
 public static void Clear() =>
 DataObjectRegistries.Clear();
 /// <summary>
 /// Unregisters all object registries and completely resets the registry manager.
 /// </summary>
 public static void Reset() =>
 DataObjectRegistries.Reset();
 /// <summary>
 /// Removes the data object registry for the specified type from the collection of registries.
 /// </summary>
 /// <typeparam name="T">The type of data object for which to unregister a registry.</typeparam>
 public static void Unregister <T>() where T : UltravioletDataObject =>
 DataObjectRegistries.Unregister <T>();
 /// <summary>
 /// Registers the data object registries in the specified assembly.
 /// </summary>
 /// <param name="asm">The assembly that contains the registries to register.</param>
 public static void Register(Assembly asm) =>
 DataObjectRegistries.Register(asm);
 /// <summary>
 /// Gets the data object registry for the specified object type.
 /// </summary>
 /// <typeparam name="T">The type of object for which to retrieve a registry.</typeparam>
 /// <returns>The <see cref="UltravioletDataObjectRegistry{T}"/> which contains objects of type <typeparamref name="T"/>.</returns>
 public static UltravioletDataObjectRegistry <T> Get <T>() where T : UltravioletDataObject =>
 (UltravioletDataObjectRegistry <T>)DataObjectRegistries.Get <T>();
예제 #15
0
        /// <summary>
        /// Reads a <see cref="ResolvedDataObjectReference"/> value.
        /// </summary>
        private static Object ReadJson_ResolvedDataObjectReference(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            var reference = (String)serializer.Deserialize(reader, typeof(String));

            return(DataObjectRegistries.ResolveReference(reference));
        }