コード例 #1
0
        public void StoredKey_IsStored()
        {
            // Arrange
            var sqliteConnection = CreateConnection();
            var sqliteStore      = new SqliteStore(sqliteConnection, Mock.Of <ILogger <SqliteStore> >(), new CurrentDateTimeProvider());

            sqliteStore.Store("encrypted", "key", TimeToLive.Day);

            // Act
            var wasStored = sqliteStore.Has("key");

            // Assert
            Assert.True(wasStored);
        }
コード例 #2
0
        public void StoredKey_CanBeRetrieved()
        {
            // Arrange
            var sqliteConnection = CreateConnection();
            var sqliteStore      = new SqliteStore(sqliteConnection, Mock.Of <ILogger <SqliteStore> >(), new CurrentDateTimeProvider());

            sqliteStore.Store("encrypted", "key", TimeToLive.Day);

            // Act
            var    hasAfterStoring = sqliteStore.Has("key");
            string result          = sqliteStore.Retrieve("key");

            // Assert
            Assert.Equal("encrypted", result);
        }
コード例 #3
0
        public void StoredKeyExpired_DoesNotRetrieveSecret()
        {
            // Arrange
            var sqliteConnection     = CreateConnection();
            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var inTheFuture          = DateTime.Now.AddHours(2);

            dateTimeProviderMock.Setup(x => x.Now).Returns(inTheFuture);
            var sqliteStore = new SqliteStore(sqliteConnection, Mock.Of <ILogger <SqliteStore> >(), dateTimeProviderMock.Object);

            sqliteStore.Store("encrypted", "key", TimeToLive.Hour);

            // Act
            bool   wasStored = sqliteStore.Has("key");
            string result    = sqliteStore.Retrieve("key");
            bool   wasStoredAfterTryRetrieve = sqliteStore.Has("key");

            // Assert
            Assert.Null(result);
            Assert.False(wasStoredAfterTryRetrieve);
        }