Ejemplo n.º 1
0
            private LoadShopCacheManager GetCacheManager()
            {
                var ucLogger = new Mock <ILogger <UserCacheManager> >();
                var appCache = new MockCachingService();

                return(new LoadShopCacheManager(new UserCacheManager(_db.Object, _mapper, ucLogger.Object, _dateTime.Object, appCache)));
            }
 public ProjectsControllerTests()
 {
     // Re-usable Arrange here via DI (from Arrange, Act, Assert)
     _mockManager = new Mock <IProjectManager>();
     _mockCache   = new MockCachingService();
     // sut = system under test
     _sut = new ProjectsController(_mockManager.Object, _mockCache);
 }
Ejemplo n.º 3
0
        public void GetOrAddCalledWithCacheKeyAndFunctionWithTimeSpan_FunctionResultReturned()
        {
            var sut = new MockCachingService();

            var result = sut.GetOrAdd(CacheKey, () => FunctionReturnValue, TimeSpan.FromMilliseconds(1000));

            result.Should().Be(FunctionReturnValue);
        }
Ejemplo n.º 4
0
        public void GetOrAddCalledWithCacheKeyAndFunctionWithMemoryCacheEntryOptions_FunctionResultReturned()
        {
            var sut = new MockCachingService();

            var result = sut.GetOrAdd(CacheKey, () => FunctionReturnValue, new MemoryCacheEntryOptions());

            result.Should().Be(FunctionReturnValue);
        }
Ejemplo n.º 5
0
        public void GetOrAddCalledWithCacheKeyAndFunctionWithDateTimeOffSet_FunctionResultReturned()
        {
            var sut = new MockCachingService();

            var result = sut.GetOrAdd(CacheKey, () => FunctionReturnValue, DateTimeOffset.MinValue);

            result.Should().Be(FunctionReturnValue);
        }
Ejemplo n.º 6
0
        public void GetWithBuiltInFake_Guid_ReturnsNull()
        {
            var cacheKey       = "SomethingInTheCache";
            var expectedResult = Guid.NewGuid().ToString();

            var mockedCache = new MockCachingService();

            var actualResult = mockedCache.Get <string>(cacheKey);

            Assert.Multiple(() => {
                Assert.IsNotNull(expectedResult);
                Assert.IsNull(actualResult);
            });
        }
        private void Initialize()
        {
            var loggerFactory = Substitute.For <ILoggerFactory>();

            _logger = Substitute.For <ILogger>();
            loggerFactory.CreateLogger(typeof(NewsService)).Returns(_logger);

            var mockedCache = new MockCachingService();

            var httpClientFactory = Substitute.For <IHttpClientFactory>();

            _messageHandler = new MockHttpMessageHandler();
            var client = new HttpClient(_messageHandler);

            httpClientFactory.CreateClient().Returns(client);

            _newsService = new NewsService(httpClientFactory, Options.Create(new AppSettings {
                HackerNewsApiUrl = "http://localhost"
            }), mockedCache, loggerFactory);
        }