protected override void Given()
        {
            resourceFileHelper = MockRepository.GenerateMock<IResourceFileHelper>();
            resourceFileHelper.Stub(m => m.GetNameValuesFromSource("active"))
                              .Return(new Dictionary<string, string> { { "Key_Inactive", "Inactive" } });
            resourceFileHelper.Stub(m => m.GetNameValuesFromSource("inactive"))
                              .Return(new Dictionary<string, string> { { "Key_Inactive", "Inactive" } });
            resourceFileHelper.Stub(m => m.GetNameValuesFromSource("agent type"))
                              .Return(new Dictionary<string, string> { { "Key_AgentType", "Agent Type" }, { "Key_Agent_Type", "Agent Type" }, { "Key_TypeOfAgent", "Agent Type" } });

            var dispatchService = MockRepository.GenerateMock<IDispatchService>();
            dispatchService.Stub(m => m.Invoke<MessageBoxResult>(null)).IgnoreArguments().Return(MessageBoxResult.Yes);

            excelFilePath = (Environment.CurrentDirectory + "\\SampleResourceFiles\\ExcelSample.xlsx");

            testOutput = new List<TranslatedItem>();

            sut = new ExcelTranslateEngine(dispatchService, item => SutToolOutput(this, new TranslatedItemEventArgs{ Item = item}));
        }
 private void WriteTranslationAndNotify(IResourceFileHelper fileHelper, string translatedValue, KeyValuePair<string, string> sourceValue)
 {
     fileHelper.WriteNameValuePairToTarget(sourceValue.Key, translatedValue, true);
     translationNotification(new TranslatedItem { DataKey = sourceValue.Key, EnglishValue = sourceValue.Value, Translation = translatedValue });
 }
        private void AskOverwriteIndividualKeys(IResourceFileHelper fileHelper, string translatedValue, KeyValuePair<string, string> sourceValue)
        {
            MessageBoxResult keyResult;
            KeyValuePair<string, string> value = sourceValue;
            keyResult = dispatchService.Invoke<MessageBoxResult>(new Func<MessageBoxResult>(() =>
                                            MessageBox.Show(String.Format("Use translation \"{0}\" for key \"{1}\"?", translatedValue, value.Key),
                                                            "Use Translation For Key?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes)));

            if (keyResult == MessageBoxResult.Yes)
                WriteTranslationAndNotify(fileHelper, translatedValue, sourceValue);
        }
        private bool TranslateMultipleKeyValues(IResourceFileHelper fileHelper, Dictionary<string, string> sourceValues, string englishValue, string translatedValue)
        {
            var cancelOperation = false;

            var writeToAllKeysAnswer = GetWriteToAllKeysAnswer(sourceValues, englishValue, translatedValue);
            switch (writeToAllKeysAnswer)
            {
                case MessageBoxResult.Yes:
                    foreach (var sourceValue in sourceValues)
                        WriteTranslationAndNotify(fileHelper, translatedValue, sourceValue);
                    break;
                case MessageBoxResult.No:
                    var keyResult = MessageBoxResult.No;
                    foreach (var sourceValue in sourceValues)
                        AskOverwriteIndividualKeys(fileHelper, translatedValue, sourceValue);
                    break;
                case MessageBoxResult.Cancel:
                    cancelOperation = true;
                    break;
            }

            return cancelOperation;
        }
        public void TranslateWorkbook(IResourceFileHelper resourceFileHelper, string excelFile, int selectedWorksheet)
        {
            var excelTranslations = GetAllValues(excelFile, selectedWorksheet);
            foreach (var translationResult in excelTranslations)
            {
                var keyValue = translationResult.Key;
                var englishValue = translationResult.EnglishValue;
                var translatedValue = translationResult.Translation;
                if (String.IsNullOrWhiteSpace(translatedValue))
                    continue;

                if (String.IsNullOrWhiteSpace(keyValue) == false)
                {
                    resourceFileHelper.WriteNameValuePairToTarget(keyValue, translatedValue, true);
                    translationNotification(new TranslatedItem { DataKey = keyValue, EnglishValue = englishValue, Translation = translatedValue });
                    continue;
                }

                Dictionary<String, String> sourceValues = resourceFileHelper.GetNameValuesFromSource(englishValue);
                if (sourceValues == null || sourceValues.Any() == false)
                {
                    translationNotification(new TranslatedItem { DataKey = "WARNING", EnglishValue = englishValue,
                                                                 Translation = "No translation can be made.", Comment = "No Source Key could be found!" });
                    continue;
                }

                if (sourceValues.Count() == 1)
                {
                    var uniqueValue = sourceValues.Single();
                    resourceFileHelper.WriteNameValuePairToTarget(uniqueValue.Key, translatedValue, true);
                    translationNotification(new TranslatedItem { DataKey = uniqueValue.Key, EnglishValue = uniqueValue.Value, Translation = translatedValue });
                    continue;
                }

                if (sourceValues.Count() > 1)
                {
                    var cancelOperation = TranslateMultipleKeyValues(resourceFileHelper, sourceValues, englishValue, translatedValue);
                    if (cancelOperation)
                        break;
                }
            }
        }