Exemplo n.º 1
0
        public void ReadCallNotes_NotNullPathAndName_ReadCorrect()
        {
            // write the json file before do the reading
            WriteJsonToFile();

            var readCallNotes = CallNoteFileHelper.ReadCallNotes(_filePath, _fileName);

            Assert.IsTrue(Utilities.EqualsAll(_callNotes, readCallNotes));
        }
Exemplo n.º 2
0
        public void WriteCallNotes_NotNullPathAndName_WriteCorrectly()
        {
            CallNoteFileHelper.WriteCallNotes(_filePath, _fileName, _callNotes);

            // read the json file after write, in order to do comparison
            var fullFileName = Path.Combine(_filePath, _fileName);
            var jObject      = ReadJObjectFromFile(fullFileName);
            var callNotes    = jObject["CallNotes"].Select(JTokenToCallNote).ToList();

            Assert.IsTrue(Utilities.EqualsAll(_callNotes, callNotes));
        }
        public void WriteCallNote(string userName, CallNote callNote)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("[CallNotesService::WriteCallNote] Starting writing CallNote. UserName: {}, CallNote: {}",
                              userName, callNote);
            }

            try
            {
                if (userName == null)
                {
                    throw new ArgumentNullException(nameof(userName), "User Name can not be null");
                }

                if (callNote == null)
                {
                    throw new ArgumentNullException(nameof(callNote), "callNote can not be null");
                }

                var customerEntity = _customersRepository.SelectByUserName(userName);
                if (customerEntity == null)
                {
                    throw new BusinessLogicException(
                              $"[CallNotesService::GetAllCallNotes] Can not find this User by userName. UserName: {userName}");
                }

                var fileName  = customerEntity.CallNoteName;
                var callNotes = CallNoteFileHelper.ReadCallNotes(_callNotesFilePath, fileName);
                callNotes.Add(callNote);
                CallNoteFileHelper.WriteCallNotes(_callNotesFilePath, fileName, callNotes);

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug(
                        "[CallNotesService::WriteCallNote] Writing CallNote successfully. UserName: {}, CallNote: {}",
                        userName, callNote);
                }
            }
            catch (FileNotFoundException e)
            {
                _logger.Error(e, "[CallNotesService::WriteCallNote] Can not find file. UserName: {}",
                              userName);
                throw new FileNotFoundException("[CallNotesService::WriteCallNote] Can not find file. UserName: {}", e);
            }
            catch (Exception e)
            {
                _logger.Error(e,
                              "[CallNotesService::WriteCallNote] Writing CallNote failed. UserName: {}, CallNote: {}", userName,
                              callNote);
                throw new BusinessLogicException("[CallNotesService::WriteCallNote] Writing CallNote  failed.", e);
            }
        }
        public IList <CallNote> GetAllCallNotes(string userName)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("[CallNotesService::GetAllCallNotes] Starting getting all CallNotes. UserName: {}",
                              userName);
            }

            try
            {
                if (userName == null)
                {
                    throw new ArgumentNullException(nameof(userName), "User Name can not be null");
                }

                var customerEntity = _customersRepository.SelectByUserName(userName);
                if (customerEntity == null)
                {
                    throw new BusinessLogicException(
                              $"[CallNotesService::GetAllCallNotes] Can not find this User by userName. UserName: {userName}");
                }

                var callNotes = CallNoteFileHelper.ReadCallNotes(_callNotesFilePath, customerEntity.CallNoteName);

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug(
                        "[CallNotesService::GetAllCallNotes] Getting all CallNotes successfully. CallNotes: {}",
                        callNotes);
                }

                return(callNotes);
            }
            catch (FileNotFoundException e)
            {
                _logger.Error(e, "[CallNotesService::GetAllCallNotes] Can not find file. UserName: {}",
                              userName);
                return(new List <CallNote>());
            }
            catch (Exception e)
            {
                _logger.Error(e, "[CallNotesService::GetAllCallNotes] Getting all CallNotes failed. UserName: {}",
                              userName);
                throw new BusinessLogicException("[CallNotesService::GetAllCallNotes] Getting all CallNotes failed.",
                                                 e);
            }
        }
        public void DeleteCallNotes(string userName)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("[CallNotesService::DeleteCallNotes] Deleting a single CallNotes file. UserName: {}",
                              userName);
            }

            try
            {
                if (userName == null)
                {
                    throw new ArgumentNullException(nameof(userName), "User Name can not be null");
                }

                var customerEntity = _customersRepository.SelectByUserName(userName);
                if (customerEntity == null)
                {
                    throw new BusinessLogicException(
                              $"[CallNotesService::GetAllCallNotes] Can not find this User by userName. UserName: {userName}");
                }

                var fileName = customerEntity.CallNoteName;
                CallNoteFileHelper.DeleteCallNotes(_callNotesFilePath, fileName);

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug(
                        "[CallNotesService::DeleteCallNotes] Delete a single CallNotes file successfully. UserName: {}",
                        userName);
                }
            }
            catch (Exception e) when(e is FileNotFoundException || e is DirectoryNotFoundException)
            {
                _logger.Error(e, "[CallNotesService::DeleteCallNotes] Can not find file. UserName: {}",
                              userName);
            }
            catch (Exception e)
            {
                _logger.Error(e,
                              "[CallNotesService::DeleteCallNotes] Delete a single CallNotes file failed. UserName: {}",
                              userName);
                throw new BusinessLogicException(
                          "[CallNotesService::DeleteCallNotes] Delete a single CallNotes file failed.", e);
            }
        }
        public void CreateCallNotesFile(string userName)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("[CallNotesService::CreateCallNotesFile] Creating CallNote File. UserName: {}", userName);
            }

            try
            {
                if (userName == null)
                {
                    throw new ArgumentNullException(nameof(userName), "User Name can not be null");
                }

                var customerEntity = _customersRepository.SelectByUserName(userName);
                if (customerEntity == null)
                {
                    throw new BusinessLogicException(
                              $"[CallNotesService::CreateCallNotesFile] Can not find this User by userName. UserName: {userName}");
                }

                var fileName = customerEntity.CallNoteName;
                CallNoteFileHelper.WriteCallNotes(_callNotesFilePath, fileName, new List <CallNote>());

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug(
                        "[CallNotesService::CreateCallNotesFile] Creating CallNote File successfully. UserName: {}", userName);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e,
                              "[CallNotesService::CreateCallNotesFile] Creating CallNote File failed. UserName: {}", userName);
                throw new BusinessLogicException("[CallNotesService::CreateCallNotesFile] Creating CallNote File failed.", e);
            }
        }
Exemplo n.º 7
0
 public void WriteCallNotes_NullCallNotes_WriteCorrectly()
 {
     CallNoteFileHelper.WriteCallNotes(_filePath, _fileName, null);
 }
Exemplo n.º 8
0
 public void DeleteCallNotes_NullName_ThrowDataAccessException()
 {
     CallNoteFileHelper.DeleteCallNotes(_filePath, null);
 }
Exemplo n.º 9
0
 public void DeleteCallNotes_NullPath_ThrowDataAccessException()
 {
     CallNoteFileHelper.DeleteCallNotes(null, _fileName);
 }
Exemplo n.º 10
0
 public void DeleteCallNotes_NotNullPathAndName_FileDeleted()
 {
     CallNoteFileHelper.DeleteCallNotes(_filePath, _fileName);
     Assert.IsFalse(File.Exists(Path.Combine(_filePath, _fileName)));
 }
Exemplo n.º 11
0
 public void ReadCallNotes_CallNoteFileNotFound_ThrowFileNoteFoundException()
 {
     CallNoteFileHelper.ReadCallNotes(_filePath, _fileName);
 }