public void GetCloseoutReasonsForLangauge()
            {
                var reasons = new List<CloseoutReason>
                {
                    new CloseoutReason() {Id = 12345, Name = "test1"},
                    new CloseoutReason() {Id = 67890, Name = "test2"}
                };
                var checkItem = new DictionaryDataItem { Id = (int) reasons[0].Id };
               
                var closeoutReasonDaoStub = new Mock<ICloseoutReasonDao>();
                closeoutReasonDaoStub.Setup(y => y.GetAllActive(It.IsAny<CloseoutReasonType>()))
                    .Returns(reasons);
                var dictionaryStub = new Mock<IDictionaryManager>();
                dictionaryStub.Setup(
                    x => x.GetDictionaryItemByKeysAndCultures(new List<string> { reasons[0].Name }, It.IsAny<List<string>>()))
                    .Returns(new List<DictionaryDataItem>
                    {
                       checkItem
                    });
                dictionaryStub.Setup(
                    x => x.DictionaryInstanceToContentByCulture(It.IsAny<List<DictionaryInstance>>(), It.IsAny<string>()))
                    .Returns(reasons[0].Name);


                var manager = new DiaryDataRetrievalManager
                {
                    CloseoutReasonDao = closeoutReasonDaoStub.Object
                    ,
                    DictionaryManager = dictionaryStub.Object
                };

                var closeoutReasons = manager.GetCloseoutReasons(new CloseoutReasonType(), "En-GB");

                Assert.AreEqual(closeoutReasons[0].Id, checkItem.Id, "Check that the items id is correct.");
            }
示例#2
0
            public void MultiKeyNullCultureReturnsAllDictionaryItems()
            {
                // Arrange
                DictionaryDataItem mockDictItem1 = new DictionaryDataItem
                {
                    ItemKey = VALID_KEY,
                    RootCultureCode = ENGLISH_CULTURE,
                    DictionaryInstances = new List<DictionaryInstance>
                                                      {
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = ROOT_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = GERMAN_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = FRENCH_CULTURE,
                                                              Content = VALID_CONTENT
                                                          }
                                                      }
                };

                DictionaryDataItem mockDictItem2 = new DictionaryDataItem
                {
                    ItemKey = SECOND_VALID_KEY,
                    RootCultureCode = ENGLISH_CULTURE,
                    DictionaryInstances = new List<DictionaryInstance>
                                                      {
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = ROOT_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = GERMAN_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = FRENCH_CULTURE,
                                                              Content = VALID_CONTENT
                                                          }
                                                      }
                };

                CacheHelper.StubDictionaryCacheWithDictionaryItems(new List<DictionaryDataItem>{mockDictItem1, mockDictItem2});

                DictionaryManager manager = new DictionaryManager();

                // Act
                List<DictionaryDataItem> resultDictionaryDataItems = manager.GetDictionaryItemByKeysAndCultures(new List<string> { VALID_KEY, SECOND_VALID_KEY }, null);

                // Assert
                Assert.AreEqual(2, resultDictionaryDataItems.Count, "Number of dictionaries returned was incorrect");
                DictionaryDataItem resultDictionaryDataItem1 = resultDictionaryDataItems.First(di => di.ItemKey == VALID_KEY);
                DictionaryDataItem resultDictionaryDataItem2 = resultDictionaryDataItems.First(di => di.ItemKey == SECOND_VALID_KEY);

                Assert.AreEqual(mockDictItem1.ItemKey, resultDictionaryDataItem1.ItemKey, "Item key 1 was incorrect");
                Assert.AreEqual(mockDictItem1.RootCultureCode, resultDictionaryDataItem1.RootCultureCode,
                                "Root culture 1 was incorrect");
                Assert.AreEqual(mockDictItem1.DictionaryInstances.Count,
                                resultDictionaryDataItem1.DictionaryInstances.Count,
                                "Number of instances returned for 1 was not equal to what expected");

                Assert.AreEqual(mockDictItem2.ItemKey, resultDictionaryDataItem2.ItemKey, "Item key 2 was incorrect");
                Assert.AreEqual(mockDictItem2.RootCultureCode, resultDictionaryDataItem2.RootCultureCode,
                                "Root culture 2 was incorrect");
                Assert.AreEqual(mockDictItem2.DictionaryInstances.Count,
                                resultDictionaryDataItem2.DictionaryInstances.Count,
                                "Number of instances returned for 2 was not equal to what expected");

                CacheHelper.ReAssignDictionaryDaoToDictionaryCache();
            }
示例#3
0
            public void SingleCultureSingleKeyReturnsSpecifiedCulture()
            {
                // Arrange
                DictionaryDataItem mockDictItem = new DictionaryDataItem
                {
                    ItemKey = VALID_KEY,
                    RootCultureCode = ENGLISH_CULTURE,
                    DictionaryInstances = new List<DictionaryInstance>
                                                      {
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = ROOT_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = GERMAN_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = FRENCH_CULTURE,
                                                              Content = VALID_CONTENT
                                                          }
                                                      }
                };

                CacheHelper.StubDictionaryCacheWithDictionaryItems(new List<DictionaryDataItem>{ mockDictItem});

                DictionaryManager manager = new DictionaryManager();
                // Act
                List<DictionaryDataItem> resultDictionaryDataItems = manager.GetDictionaryItemByKeysAndCultures(new List<string> { VALID_KEY }, new List<string> { GERMAN_CULTURE });

                // Assert
                Assert.AreEqual(1, resultDictionaryDataItems.Count, "Number of dictionaries returned was incorrect");
                DictionaryDataItem resultDictionaryDataItem = resultDictionaryDataItems[0];

                Assert.AreEqual(mockDictItem.ItemKey, resultDictionaryDataItem.ItemKey, "Item key was incorrect");
                Assert.AreEqual(mockDictItem.RootCultureCode, resultDictionaryDataItem.RootCultureCode,
                                "Root culture was incorrect");
                Assert.AreEqual(1, resultDictionaryDataItem.DictionaryInstances.Count,
                                "Number of instances returned was not equal to what expected");

                Assert.IsFalse(
                    resultDictionaryDataItem.DictionaryInstances.ToList().Exists(di => di.CultureCode == FRENCH_CULTURE),
                    "French culture was not filtered out");

                CacheHelper.ReAssignDictionaryDaoToDictionaryCache();
            }
        /// <summary>
        /// Get list of dictionary instances from model dictionary item
        /// </summary>
        /// <param name="dictionaryItem">model to convert</param>
        /// <returns>Dictionary instance</returns>
        public static List<DictionaryInstanceDto> ConvertDictionaryInstancesFromDictionaryItem(DictionaryDataItem dictionaryItem)
        {
            var instances = new List<DictionaryInstanceDto>();
            if (dictionaryItem != null)
            {
                instances.AddRange(dictionaryItem.DictionaryInstances.Select(instance => new DictionaryInstanceDto
                                                                                             {
                                                                                                 Content = instance.Content, 
                                                                                                 CultureCode = instance.CultureCode, 
                                                                                                 ItemKey = instance.Item.ItemKey
                                                                                             }));
            }

            return instances;
        }
示例#5
0
        /// <summary>
        /// Get dictionary items by the given key and set of cultures
        /// </summary>
        /// <param name="itemKeys">keys to filter by (at least one)</param>
        /// <param name="cultures">cultures to return, null to return all</param>
        /// <returns>dictionary item with translated cultures</returns>
        public List<DictionaryDataItem> GetDictionaryItemByKeysAndCultures(List<string> itemKeys, List<string> cultures)
        {
            var dictionaryItems = new List<DictionaryDataItem>();
            
            if (itemKeys == null ||
                itemKeys.Any() == false)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30114, "DictionaryManager.GetDictionaryItemByKeysAndCultures"));
                
            }

            foreach (string itemKey in itemKeys)
            {
                DictionaryDataItem dictionaryDataItem = Cache.Cache.DictionaryCache.TryGetValue(itemKey);
                if (dictionaryDataItem == null)
                {
                    continue;
                }

                var filteredDictionaryItem = new DictionaryDataItem
                {
                    ItemKey = dictionaryDataItem.ItemKey,
                    RootCultureCode =
                        dictionaryDataItem.RootCultureCode
                };

                var instances = new List<DictionaryInstance>();
                if (cultures == null || cultures.Any() == false)
                {
                    instances.AddRange(dictionaryDataItem.DictionaryInstances);
                }
                else
                {
                    var dictInstances = dictionaryDataItem.DictionaryInstances.ToList();
                    
                    // set root culture to what root culture is
                    dictInstances.ForEach(inst =>
                    {
                        if (inst.CultureCode.ToUpperInvariant() == ROOT)
                        {
                            inst.CultureCode = dictionaryDataItem.RootCultureCode;
                        }
                    });

                    instances.AddRange(dictInstances.Where(instance => cultures.Contains(instance.CultureCode, StringComparer.OrdinalIgnoreCase)));
                }

                filteredDictionaryItem.DictionaryInstances = instances;
                
                dictionaryItems.Add(filteredDictionaryItem);
            }

            return dictionaryItems;
        }
示例#6
0
        /// <summary>
        /// Get all cultures of a dictionary item by key
        /// </summary>
        /// <param name="itemKey">key for dictionary item</param>
        /// <returns>dictionary item with cultures listed if available</returns>
        public DictionaryDataItem GetDictionaryItemsByKey(string itemKey)
        {
            const string QUERY = @" SELECT 
                                    d.ItemKey, 
                                    d.RootCultureCode,
                                    di.CultureCode,
                                    di.Content
                                FROM Dictionary.item d
                                JOIN Dictionary.Instance di ON di.ItemId = d.Id
                                WHERE 
                                d.ItemKey = @ItemKey";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(DictionaryItemMapper.Parameters.ItemKey, itemKey)
            };

            var instances = DbHelper.CreateInstanceList(QUERY, DictionaryItemMapper.MapDictInstanceRecord, parameters: parameters);

            DictionaryDataItem resultDictionaryItem = null;
            if (instances != null && instances.Any())
            {
                resultDictionaryItem = new DictionaryDataItem
                                           {
                                               ItemKey = instances[0].Item.ItemKey,
                                               RootCultureCode = instances[0].Item.RootCultureCode,
                                               DictionaryInstances = instances
                                           };
            }

            return resultDictionaryItem;
        }