Ejemplo n.º 1
0
    public async Task BasicTest()
    {
        var cacheDir = GetCacheDir();

        if (Directory.Exists(cacheDir))
        {
            Directory.Delete(cacheDir, true);
        }
        var cache = new FileSystemCache <int, int>(cacheDir);

        (await cache.TryGet(1)).Should().Be(Option.None <int>());
        (await cache.Get(1)).Should().Be(0);

        await cache.Set(1, 1);

        (await cache.TryGet(1)).Should().Be(Option.Some <int>(1));
        (await cache.Get(1)).Should().Be(1);

        (await cache.TryGet(2)).Should().Be(Option.None <int>());
        (await cache.Get(2)).Should().Be(0);

        await cache.Remove(1);

        (await cache.TryGet(1)).Should().Be(Option.None <int>());
        (await cache.Get(1)).Should().Be(0);
    }
Ejemplo n.º 2
0
        public void WhenAnItemIsAddedToTheCache_ThenTheSameItemCanBeRetrieved()
        {
            var data = new TestData {
                String1 = "testString", Double1 = 5.7, Int1 = 45
            };

            _cache.Add(data, "testKey", Cache.NoAbsoluteExpiration);

            var returnedData = _cache.Get <TestData>("testKey");

            Assert.IsNotNull(returnedData);
            Assert.AreEqual(data.String1, returnedData.String1);
            Assert.AreEqual(data.Double1, returnedData.Double1);
            Assert.AreEqual(data.Int1, returnedData.Int1);
        }
        public void AddGetRemove_Success()
        {
            // Arrange
            Customer customer = TestData.CreateCustomer();
            ICache   cache    = new FileSystemCache();

            // Add, Get and Assert
            cache.Add(customer.Id.ToString(), customer);
            object customerObject = cache.Get(customer.Id.ToString());

            // Assert
            Assert.IsNotNull(customerObject);
            Assert.IsInstanceOfType(customerObject, typeof(Customer));


            // Remove and Assert
            cache.Remove(customer.Id.ToString());
            customerObject = cache.Get(customer.Id.ToString());
            Assert.IsNull(customerObject);
        }