public void ReturnsNullWhenObjectDoesNotExist()
        {
            IExpiryProvider expiryProvider = Substitute.For <IExpiryProvider>();
            IStorage        storage        = new InMemoryStorage(expiryProvider);

            byte[] objFromBytes;
            bool   success = storage.TryGet("lorem ipsum", out objFromBytes);

            Assert.Null(objFromBytes);
            Assert.False(success);
        }
        public void CanInsertAndGetObject()
        {
            string          key            = "key";
            string          objectWord     = "lorem ipsum";
            IExpiryProvider expiryProvider = Substitute.For <IExpiryProvider>();
            IStorage        storage        = new InMemoryStorage(expiryProvider); storage.AddOrUpdate(key, DateTime.MaxValue, Encoding.UTF8.GetBytes(objectWord));

            byte[] objFromBytes;
            bool   success         = storage.TryGet(key, out objFromBytes);
            string stringFromBytes = Encoding.UTF8.GetString(objFromBytes);

            Assert.True(success);
            Assert.Equal(objectWord, stringFromBytes);
        }
        public void CanUpdateExistingObject()
        {
            string          key            = "key";
            string          first          = "first";
            string          second         = "second";
            IExpiryProvider expiryProvider = Substitute.For <IExpiryProvider>();
            IStorage        storage        = new InMemoryStorage(expiryProvider);

            byte[] firstObject  = Encoding.UTF8.GetBytes(first);
            byte[] secondObject = Encoding.UTF8.GetBytes(second);

            storage.AddOrUpdate(key, DateTime.MaxValue, firstObject);
            storage.AddOrUpdate(key, DateTime.MaxValue, secondObject);

            byte[] objFromBytes;
            bool   success         = storage.TryGet(key, out objFromBytes);
            string stringFromBytes = Encoding.UTF8.GetString(objFromBytes);

            Assert.True(success);
            Assert.Equal(stringFromBytes, second);
        }