示例#1
0
        /// <summary>
        /// Handle the main logic for cloning json file and creating the core funcionality
        /// </summary>
        /// <param name="args">Arguments passed through command line</param>
        /// <returns>Json string when the whole process is done</returns>
        public string DoCloning(string[] args)
        {
            // Create concrete objects for arguments so they can be used further down the code
            string filePath = args[0];
            long   entityId = long.Parse(args[1]);

            // Deserialize from file into our InputObject
            InputObject inputObject = _jsonProcessor.DeserializeFromPath <InputObject>(args[0]);

            // Sort all entities by its ID, this will be used for generating new IDs
            _inputObjectProcessor.SortEntities(inputObject);

            // Get initial Entity
            Entity initialEntity = GetInitialEntity(inputObject, entityId);

            // Clone InitialEntity and add to the list
            Entity initialClone = CreateCloneAndAssignId(inputObject, initialEntity);

            HandleAllTo(inputObject, initialEntity, initialClone);
            HandleAllFrom(inputObject, initialEntity, initialClone);

            // Serialize object to json string with indents and null handling
            string result = _jsonProcessor.SerialzeWithIndent(inputObject);

            return(result);
        }
示例#2
0
        public void Test_Construct_File_Filename()
        {
            #region Prepare
            // Path for existing file
            string path        = Environment.CurrentDirectory + "\\file.json";
            var    inputObject = _jsonProcessor.DeserializeFromPath <InputObject>(path);
            #endregion

            #region Act
            var json = _jsonProcessor.SerialzeWithIndent(inputObject);
            #endregion

            #region Assert
            Assert.NotEmpty(json);
            #endregion
        }