Exemplo n.º 1
0
        public void Set(string key, object val)
        {
            var dictionary  = new Dictionary <string, string>();
            var watcherMock = new Mock <IWatcher>();

            watcherMock.Setup(m => m.Properties)
            .Returns(dictionary);
            //watcherMock.Setup(r => r.Properties.Add(It.Is<string>(r => r == "key"), It.Is<string>(r => r == key)));

            //watcher?.Properties?.Add("key", k);


            var timeWatcherMock = new Mock <ITimeWatcher>();


            timeWatcherMock.Setup(r => r.StartWatcher(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(() => watcherMock.Object);

            var obj = new RepositoryCache();

            Assert.IsNotNull(obj);
            obj.Set(timeWatcherMock.Object, key, val);
            timeWatcherMock.Verify(foo => foo.StartWatcher("RepositoryCache.Set", It.IsAny <bool>()), Times.Once());
            //watcherMock.Verify(r => r.Properties.Add(It.Is<string>(r => r == "key"), It.Is<string>(r => r == key)), Times.Once());
            watcherMock.VerifyGet(r => r.Properties, Times.Once());
            var b = dictionary.ContainsValue(key);

            Assert.IsTrue(b);
            //Assert.AreEqual(val,dictionary[key]);
        }
Exemplo n.º 2
0
 private void AddRepositoryContentsToCache(RepositoryReference repoSpec, IEnumerable <RepositoryContent> contentList)
 {
     foreach (var repoContent in contentList)
     {
         var subKey = new RepositoryPathReference
         {
             RepositoryOwner = repoSpec.RepositoryOwner,
             RepositoryName  = repoSpec.RepositoryName,
             TreeReference   = repoSpec.TreeReference,
             Path            = repoContent.Path
         };
         if (RepositoryCache.TryGetValue(subKey, out RepositoryContentEntry subEntry))
         {
             subEntry.Leaf = repoContent;
         }
         else
         {
             subEntry = new RepositoryContentEntry {
                 Leaf = repoContent
             }
         };
         var subOptions = new MemoryCacheEntryOptions {
             Size = repoContent.Size
         };
         RepositoryCache.Set(subKey, subEntry, subOptions);
         if (repoContent.Type.TryParse(out var repoContentType) && repoContentType == ContentType.File)
         {
             subEntry.Contents = new List <RepositoryContent>(capacity: 1)
             {
                 repoContent
             }
         }
         ;
     }
 }
Exemplo n.º 3
0
        public void Get(string key, object val)
        {
            var dictionary  = new Dictionary <string, string>();
            var watcherMock = new Mock <IWatcher>();

            watcherMock.Setup(m => m.Properties)
            .Returns(dictionary);
            var timeWatcherMock = new Mock <ITimeWatcher>();


            timeWatcherMock.Setup(r => r.StartWatcher(It.IsAny <string>(), It.IsAny <bool>()))
            .Callback(() => dictionary.Clear())
            .Returns(() => watcherMock.Object);

            var obj = new RepositoryCache();

            Assert.IsNotNull(obj);
            obj.Set(timeWatcherMock.Object, key, val);

            var result = obj.Get <object>(timeWatcherMock.Object, key);

            timeWatcherMock.Verify(foo => foo.StartWatcher("RepositoryCache.Get", It.IsAny <bool>()), Times.Once());
            Assert.AreEqual(val, result);
        }