Example #1
0
        public void InitilizeCacheWithEmptyDictionary()
        {
            // Act & Arrange

            var cachingService = new CachingServiceMock(TimeSpan.FromSeconds(It.IsAny <double>()));

            // Assert
            Assert.IsInstanceOf(typeof(Dictionary <string, object>), cachingService.CacheStorage);
            Assert.AreEqual(0, cachingService.CacheStorage.Count);
        }
Example #2
0
        public void ClearTheCache_WhenInvoked()
        {
            // Arrange
            var cachingService = new CachingServiceMock(TimeSpan.FromSeconds(20));

            // Act
            cachingService.ResetCache();

            // Assert
            Assert.IsInstanceOf <Dictionary <string, object> >(cachingService.CacheStorage);
            Assert.AreEqual(0, cachingService.CacheStorage.Count);
        }
Example #3
0
        public void CreateNewDictionaryWhenInvoked()
        {
            // Arrange
            var cachingService = new CachingServiceMock(It.IsAny <TimeSpan>());

            // Act
            cachingService.ResetCache();

            // Assert
            Assert.IsInstanceOf(typeof(Dictionary <string, object>), cachingService.CacheStorage);
            Assert.AreEqual(0, cachingService.CacheStorage.Count);
        }
Example #4
0
        public void SetProperInitialDateTimeForExpiring()
        {
            // Arrange
            var returnDate = new DateTime(2017, 6, 15, 15, 00, 00);

            var dateTimeMock = new Mock <DateTimeProvider>();

            dateTimeMock.SetupGet(x => x.UtcNow).Returns(returnDate);

            DateTimeProvider.Current = dateTimeMock.Object;

            // Act
            var cachingService = new CachingServiceMock(TimeSpan.FromSeconds(It.IsAny <double>()));

            // Assert
            Assert.AreEqual(returnDate, cachingService.DateTimeExpiring);
        }
Example #5
0
        public void AddProperValueToTheTimeExpiring_WhenInvoked()
        {
            // Arrange
            DateTime returnDate = new DateTime(2018, 4, 17, 12, 0, 0);

            var dateTimeMock = new Mock <DateTimeProvider>();

            dateTimeMock.Setup(d => d.UtcNow).Returns(returnDate);
            DateTimeProvider.Current = dateTimeMock.Object;

            var cachingService = new CachingServiceMock(TimeSpan.FromSeconds(20));

            // Act
            cachingService.ResetCache();

            // Assert
            Assert.AreEqual(returnDate.AddSeconds(20), cachingService.DateTimeExpiring);
        }
        public void SetTheCacheDictionaryAndTimeExpiringCorrectly()
        {
            // Arrange
            DateTime returnDate = new DateTime(2018, 4, 17, 12, 0, 0);

            var dateTimeMock = new Mock <DateTimeProvider>();

            dateTimeMock.Setup(d => d.UtcNow).Returns(returnDate);

            DateTimeProvider.Current = dateTimeMock.Object;

            // Act
            var cachingService = new CachingServiceMock(TimeSpan.FromSeconds(It.IsAny <double>()));

            // Assert
            Assert.AreEqual(returnDate, cachingService.DateTimeExpiring);
            Assert.IsInstanceOf <Dictionary <string, object> >(cachingService.CacheStorage);
            Assert.AreEqual(0, cachingService.CacheStorage.Count);
        }
        public void ReturnFakse_IfCurrentDateIsNotBiggerThanTheTimeExpiring()
        {
            // Arrange
            DateTime returnDate        = new DateTime(2018, 4, 17, 12, 0, 0);
            DateTime anotherReturnDate = new DateTime(2018, 4, 17, 11, 50, 0);

            var dateTimeMock = new Mock <DateTimeProvider>();

            dateTimeMock.Setup(d => d.UtcNow).Returns(returnDate);
            DateTimeProvider.Current = dateTimeMock.Object;

            var cachingService = new CachingServiceMock(TimeSpan.FromSeconds(20));

            dateTimeMock.Setup(d => d.UtcNow).Returns(anotherReturnDate);
            DateTimeProvider.Current = dateTimeMock.Object;

            // Act
            bool result = cachingService.IsExpired;

            // Assert
            Assert.IsFalse(result);
        }