예제 #1
0
        public async Task Contains_WorksCorrectly()
        {
            const int    port = 9995;
            const string key  = "key";

            bool            containsFromClientApi;
            bool            containsFromStorage;
            IExpiryProvider expiryProvider = new StorageExpiryProvider();

            using (IStorage storage = new InMemoryStorage(expiryProvider))
            {
                var processor        = new SocketProcessor();
                var requestProcessor = new RequestProcessor(storage);
                using (IListener server = new Listener(IPAddress.Any, port, processor, requestProcessor))
                {
                    server.Start();
                    IKronosClient client = KronosClientFactory.CreateClient(localHost, port);

                    containsFromClientApi = await client.ContainsAsync(key);

                    containsFromStorage = storage.Contains(key);
                }
            }

            Assert.False(containsFromClientApi);
            Assert.Equal(containsFromClientApi, containsFromStorage);
        }
예제 #2
0
        public async Task Insert_And_Contains_WorksCorrectly()
        {
            const int    port = 9996;
            const string key  = "key";

            byte[]   data   = Encoding.UTF8.GetBytes("lorem ipsum");
            DateTime expiry = DateTime.MaxValue;

            bool            containsFromClientApi;
            bool            containsFromStorage;
            IExpiryProvider expiryProvider = new StorageExpiryProvider();

            using (IStorage storage = new InMemoryStorage(expiryProvider))
            {
                var processor        = new SocketProcessor();
                var requestProcessor = new RequestProcessor(storage);
                using (IListener server = new Listener(IPAddress.Any, port, processor, requestProcessor))
                {
                    server.Start();
                    IKronosClient client = KronosClientFactory.CreateClient(localHost, port);
                    await client.InsertAsync(key, data, expiry);

                    containsFromClientApi = await client.ContainsAsync(key);

                    containsFromStorage = storage.Contains(key);
                }
            }

            Assert.True(containsFromClientApi);
            Assert.Equal(containsFromClientApi, containsFromStorage);
        }
예제 #3
0
        public void Contains_ReturnsTrueWhenDataDoesNotExist()
        {
            IExpiryProvider expiryProvider = Substitute.For <IExpiryProvider>();
            IStorage        storage        = new InMemoryStorage(expiryProvider);

            string key = "lorem ipsum";

            bool result = storage.Contains(key);

            Assert.False(result);
        }
예제 #4
0
        public void Contains_ReturnsTrueWhenDataExists()
        {
            IExpiryProvider expiryProvider = Substitute.For <IExpiryProvider>();
            IStorage        storage        = new InMemoryStorage(expiryProvider);

            string key = "lorem ipsum";

            storage.AddOrUpdate(key, DateTime.MaxValue, new byte[0]);
            storage.AddOrUpdate("second", DateTime.MaxValue, new byte[0]);

            bool result = storage.Contains(key);

            Assert.True(result);
        }