示例#1
0
            static Exception AssertException(Action <Mock <IMemcachedClientOptions> > extraSetup)
            {
                var defaultOptions = new MemcachedClientOptions();
                var mockCluster    = new Mock <IMemcachedCluster>();

                mockCluster.SetupGet(c => c.IsStarted).Returns(true);
                mockCluster.SetupGet(c => c.Allocator).Returns(MemoryPool <byte> .Shared);

                var mockOptions = new Mock <IMemcachedClientOptions>(MockBehavior.Strict);

                mockOptions.SetupGet(o => o.KeyFormatter).Returns(defaultOptions.KeyFormatter);
                mockOptions.SetupGet(o => o.ItemFormatter).Returns(defaultOptions.ItemFormatter);

                extraSetup?.Invoke(mockOptions);

                return(Assert.Throws <ArgumentNullException>(() => new MemcachedClient(mockCluster.Object, mockOptions.Object)));
            }
示例#2
0
        public MemcachedClient(IMemcachedCluster cluster, IMemcachedClientOptions?options = null)
        {
            this.cluster = cluster ?? throw new ArgumentNullException(nameof(cluster));
            if (!cluster.IsStarted)
            {
                throw new ArgumentException("Cluster must be started before creating client instances", nameof(cluster));
            }

            this.allocator = cluster.Allocator;

            if (options == null)
            {
                options = new MemcachedClientOptions();
            }
            keyFormatter  = options.KeyFormatter ?? throw PropertyCannotBeNull(nameof(options.KeyFormatter));
            itemFormatter = options.ItemFormatter ?? throw PropertyCannotBeNull(nameof(options.ItemFormatter));
        }