public void Saveobject_FileIsEmptySaveInNewObj()
        {
            _stubRemoteFile.Expect(x => x
                                   .ReadFileData(Path))
            .Return(FILE_EMPTY_LIST_STRING);

            var modelList = new List <IModel> {
                _stubModel
            };

            _stubSerializer.Stub(x => x
                                 .DeSerialize <List <IModel> >(FILE_EMPTY_LIST_STRING))
            .Return(modelList);

            _stubRemoteFile.WriteFileData(Path, FILE_EMPTY_LIST_STRING);
            _target.Saveobject(_stubModel, Path);

            _stubRemoteFile.VerifyAllExpectations();
        }
Esempio n. 2
0
        /// <summary>
        /// Add obj in existing objList or create new objList and Add obj
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="path"></param>
        public void Saveobject(IModel obj, string path)
        {
            var           str = _remoteFile.ReadFileData(path);
            List <IModel> objList;

            if (str == "[]")
            {
                objList = new List <IModel> {
                    obj
                };
            }
            else
            {
                objList = _serializer.DeSerialize <List <IModel> >(str);
                objList.Add(obj);
            }

            var objStr = _serializer.Serialize(objList);

            _remoteFile.WriteFileData(path, objStr);
        }