private LinkedService ConvertAndTestJson(string json, bool customTest = false, HashSet <string> propertyBagKeys = null)
        {
            LinkedService linkedService = this.ConvertToWrapper(json);

            CoreModel.LinkedService actual = this.Operations.Converter.ToCoreType(linkedService);

            // after converting to intermediate object, ensure that ServiceExtraProperties is still set
            if (customTest)
            {
                IGenericTypeProperties typeProperties =
                    linkedService.Properties.TypeProperties as IGenericTypeProperties;

                Assert.NotNull(typeProperties);
            }

            string actualJson = Core.DataFactoryManagementClient.SerializeInternalLinkedServiceToJson(actual);

            JsonComparer.ValidateAreSame(json, actualJson, ignoreDefaultValues: true);
            Assert.DoesNotContain("ServiceExtraProperties", actualJson);

            JObject actualJObject = JObject.Parse(actualJson);

            JsonComparer.ValidatePropertyNameCasing(actualJObject, true, string.Empty, propertyBagKeys);

            return(linkedService);
        }
        private LinkedService ConvertToWrapper(string json)
        {
            CoreModel.LinkedService internalLinkedService =
                Core.DataFactoryManagementClient.DeserializeInternalLinkedServiceJson(json);

            return(this.Operations.Converter.ToWrapperType(internalLinkedService));
        }
Exemple #3
0
        private Core.Models.LinkedServiceCreateOrUpdateParameters ValidateAndConvert(LinkedServiceCreateOrUpdateParameters parameters)
        {
            // Validate
            Ensure.IsNotNull(parameters, "parameters");
            Ensure.IsNotNull(parameters.LinkedService, "parameters.LinkedService");
            this.ValidateObject(parameters.LinkedService);

            // Convert
            Core.Models.LinkedService internalLinkedService = this.Converter.ToCoreType(parameters.LinkedService);

            return(new Core.Models.LinkedServiceCreateOrUpdateParameters()
            {
                LinkedService = internalLinkedService
            });
        }
        /// <summary>
        /// Serializes the given InternalLinkedService into JSON, by mocking a create request to
        /// exercise the client's serialization logic.
        /// </summary>
        /// <param name="item">The object to serialize.</param>
        /// <returns></returns>
        internal static string SerializeInternalLinkedServiceToJson(Models.LinkedService item)
        {
            var createParams = new Models.LinkedServiceCreateOrUpdateParameters()
            {
                LinkedService = item
            };

            var    handler           = new MockResourceProviderDelegatingHandler();
            var    client            = GetFakeClient(handler);
            string resourceGroupName = Guid.NewGuid().ToString("D");
            string dataFactoryName   = Guid.NewGuid().ToString("D");

            client.LinkedServices.BeginCreateOrUpdate(resourceGroupName, dataFactoryName, createParams);
            return(handler.Json);
        }
        public LinkedService ADFLinkedServiceFromJson(JObject jsonObject)
        {
            Type       dynClass;
            MethodInfo dynMethod;

            string objectType = "LinkedService";

            MapConfigElements(ref jsonObject);
            MapSlices(ref jsonObject);

            dynClass  = new Core.DataFactoryManagementClient().GetType();
            dynMethod = dynClass.GetMethod("DeserializeInternal" + objectType + "Json", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            CoreModels.LinkedService internalObject = (CoreModels.LinkedService)dynMethod.Invoke(this, new object[] { jsonObject.ToString() });

            dynClass = Type.GetType(dynClass.AssemblyQualifiedName.Replace("Core.DataFactoryManagementClient", "Conversion." + objectType + "Converter"));
            ConstructorInfo constructor = dynClass.GetConstructor(Type.EmptyTypes);
            object          classObject = constructor.Invoke(new object[] { });

            dynMethod = dynClass.GetMethod("ToWrapperType", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            LinkedService ret = (LinkedService)dynMethod.Invoke(classObject, new object[] { internalObject });

            return(ret);
        }