Exemplo n.º 1
0
        public async Task CacheAsyncShouldDownloadAndAddPackageWhenDoesNotExist()
        {
            localPackages.Setup(p => p.ExistsAsync(It.IsAny <PackageIdentity>())).ReturnsAsync(false);
            await mirrorService.CacheAsync(log4net, CancellationToken.None);

            downloader.Verify(d => d.DownloadOrNullAsync(It.IsAny <Uri>(), It.IsAny <CancellationToken>()), Times.Once());
            localPackages.Verify(p => p.AddPackageAsync(It.IsAny <Stream>()), Times.Once());
        }
Exemplo n.º 2
0
        public async Task CacheAsync_SpecificCacheImplementation_UsesSpecificCache()
        {
            var specificCacheImplementationMock = new Mock <ICacheImplementation>();
            var cacheOptions = new CacheOptions
            {
                CacheImplementation = specificCacheImplementationMock.Object
            };
            var configurationItemMock = new Mock <ICacheConfigurationItem <User> >();

            configurationItemMock
            .SetupGet(i => i.Options)
            .Returns(cacheOptions);
            var propertyTrackerMock = new Mock <IPropertyTracker <User> >();

            propertyTrackerMock
            .Setup(p => p.GetStoreKey(It.Is <User>(u => u.Name == "Test name")))
            .Returns("User_Key");
            configurationItemMock
            .SetupGet(i => i.Tracker)
            .Returns(propertyTrackerMock.Object);
            _cacheConfigurationMock
            .Setup(c => c.GetItem <User>())
            .Returns(configurationItemMock.Object);
            var genericCacheImplementationMock = new Mock <ICacheImplementation>();

            _cacheConfigurationMock
            .SetupGet(c => c.Current)
            .Returns(genericCacheImplementationMock.Object);

            var user = new User {
                Name = "Test name"
            };
            await _sut.CacheAsync(user);

            genericCacheImplementationMock
            .Verify(c => c.CacheAsync(
                        It.IsAny <string>(),
                        It.IsAny <User>(),
                        It.IsAny <CacheOptions>()),
                    Times.Never);
            specificCacheImplementationMock
            .Verify(c => c.CacheAsync(
                        "User_Key",
                        It.Is <User>(u => u.Name == "Test name"),
                        It.IsAny <CacheOptions>()),
                    Times.Once);
            configurationItemMock
            .VerifyGet(i => i.Options, Times.AtLeastOnce);
            propertyTrackerMock
            .Verify(p => p.GetStoreKey(It.Is <User>(u => u.Name == "Test name")), Times.Once);
            configurationItemMock
            .VerifyGet(i => i.Tracker, Times.AtLeastOnce);
            _cacheConfigurationMock
            .Verify(c => c.GetItem <User>(), Times.Once);
        }
Exemplo n.º 3
0
        public async Task CacheAsync()
        {
            await mirrorService.CacheAsync(new PackageIdentity("log4net", NuGetVersion.Parse("2.0.8")), CancellationToken.None);

            Assert.True(await mirrorService.ExistsAsync(log4netId));
        }