コード例 #1
0
        public Alignment Generate(string creatureName)
        {
            var weightedAlignments = collectionSelector.ExplodeAndPreserveDuplicates(TableNameConstants.Collection.AlignmentGroups, creatureName);
            var randomAlignment    = collectionSelector.SelectRandomFrom(weightedAlignments);

            return(new Alignment(randomAlignment));
        }
コード例 #2
0
        public IEnumerable <string> ExplodeAndPreserveDuplicates(string tableName, string collectionName)
        {
            var assembly = assemblyLoader.GetRunningAssembly();
            var key      = assembly.FullName + tableName + collectionName;

            lock (myLock)
            {
                if (!cachedExplodedWithDuplicatesCollections.ContainsKey(key))
                {
                    var explodedCollection = innerSelector.ExplodeAndPreserveDuplicates(tableName, collectionName);
                    cachedExplodedWithDuplicatesCollections.Add(key, explodedCollection);
                }
            }

            return(cachedExplodedWithDuplicatesCollections[key]);
        }
コード例 #3
0
        public void Explode_CacheResults_WithoutDuplicates()
        {
            mockInnerSelector
            .Setup(s => s.Explode("table name", "my entry"))
            .Returns(new[] { "entry 1", "entry 2" });
            mockInnerSelector
            .Setup(s => s.ExplodeAndPreserveDuplicates("table name", "my entry"))
            .Returns(new[] { "entry 1", "entry 2", "entry 2" });

            proxy.ExplodeAndPreserveDuplicates("table name", "my entry");
            proxy.Explode("table name", "my entry");
            var result = proxy.Explode("table name", "my entry");

            Assert.That(result, Is.EqualTo(new[] { "entry 1", "entry 2" }));

            mockInnerSelector.Verify(p => p.Explode(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            mockInnerSelector.Verify(p => p.ExplodeAndPreserveDuplicates(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }