コード例 #1
0
        public void SetupContext()
        {
            var connectionString = AppConfig.MongoDB;

            _client        = new MongoClient(connectionString);
            _databaseName  = "Test_" + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);
            _database      = _client.GetDatabase(_databaseName);
            _gridFsDataBus = new GridFsDataBus(_database);
        }
コード例 #2
0
        public void Should_handle_be_able_to_read_stored_values()
        {
            const string content = "Test";

            var key = Put(content, TimeSpan.MaxValue);

            using (var stream = GridFsDataBus.Get(key))
            {
                Assert.AreEqual(content, new StreamReader(stream).ReadToEnd());
            }
        }
        public async Task Should_handle_be_able_to_read_stored_values()
        {
            const string content = "Test";

            var key = await Put(content, TimeSpan.MaxValue).ConfigureAwait(false);

            using (var stream = await GridFsDataBus.Get(key).ConfigureAwait(false))
            {
                Assert.AreEqual(content, new StreamReader(stream).ReadToEnd());
            }
        }
        public async Task Should_handle_be_able_to_read_stored_values_concurrently()
        {
            const string content = "Test";

            var key = await Put(content, TimeSpan.MaxValue).ConfigureAwait(false);


            var tasks = Enumerable.Range(0, 10).Select(i =>
            {
                return(Task.Run(async() =>
                {
                    using (var stream = await GridFsDataBus.Get(key).ConfigureAwait(false))
                    {
                        Assert.AreEqual(content, new StreamReader(stream).ReadToEnd());
                    }
                }));
            });

            await Task.WhenAll(tasks).ConfigureAwait(false);
        }