Exemplo n.º 1
0
        public async Task SingleAsync_HasValue()
        {
            var tenantId   = TestConfiguration.GetTenantId();
            var connection = TestConfiguration.GetConnection();
            var context    = new MongoDbTenantContext(connection, tenantId);
            var dbSet      = new MongoDbTenantSet <QueryableAsyncModel>(context);

            dbSet.AddRange(GetModels());
            context.SaveChanges();

            var context2 = new MongoDbTenantContext(connection, tenantId + "-2");
            var dbSet2   = new MongoDbTenantSet <QueryableAsyncModel>(context2);

            dbSet2.Add(new QueryableAsyncModel {
                Title = "SingleAsync_HasValue.1"
            });
            context2.SaveChanges();

            var result = await dbSet2.SingleAsync();

            Assert.AreEqual("SingleAsync_HasValue.1", result.Title);
        }
Exemplo n.º 2
0
        public async Task SingleAsync_NoValue()
        {
            var tenantId   = TestConfiguration.GetTenantId();
            var connection = TestConfiguration.GetConnection();
            var context    = new MongoDbTenantContext(connection, tenantId);
            var dbSet      = new MongoDbTenantSet <QueryableAsyncModel>(context);

            dbSet.AddRange(GetModels());
            context.SaveChanges();

            var context2 = new MongoDbTenantContext(connection, tenantId + "-2");
            var dbSet2   = new MongoDbTenantSet <QueryableAsyncModel>(context2);

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await dbSet2.SingleAsync());
        }