Пример #1
0
        public async Task OrderTest()
        {
            var serviceProvider = DataCommon.GetServiceProvider();
            var database        = serviceProvider.GetService <IDatabaseContext>();
            await DataCommon.DataInitAsync(database);

            var userContext = database.GetContext <User>();
            var user        = await userContext.FirstOrDefaultAsync(userContext.Order());

            Assert.Equal("TestUser1", user.Username);
        }
Пример #2
0
 public async Task OrderTest()
 {
     UnitTestEnvironment env = new UnitTestEnvironment();
     await env.Run(async sp =>
     {
         var database = sp.GetService <IDatabaseContext>();
         await DataCommon.DataInitAsync(database);
         var userContext = database.GetContext <User>();
         var user        = await userContext.FirstOrDefaultAsync(userContext.Order());
         Assert.Equal("TestUser1", user.Username);
     });
 }
Пример #3
0
        public async Task OrderTest()
        {
            UnitTestEnvironment env = new UnitTestEnvironment();

            using (var scope = env.GetServiceScope())
            {
                var serviceProvider = scope.ServiceProvider;
                var database        = serviceProvider.GetService <IDatabaseContext>();
                await DataCommon.DataInitAsync(database);

                var userContext = database.GetContext <User>();
                var user        = await userContext.FirstOrDefaultAsync(userContext.Order());

                Assert.Equal("TestUser1", user.Username);
            }
        }
Пример #4
0
        public async Task AddAndRemoveTest()
        {
            var serviceProvider = DataCommon.GetServiceProvider();
            var database        = serviceProvider.GetService <IDatabaseContext>();
            var categoryContext = database.GetContext <Category>();

            Assert.Equal(0, await categoryContext.CountAsync(categoryContext.Query()));
            var category = categoryContext.Create();

            category.Name = "Test";
            categoryContext.Add(category);
            Assert.Equal(0, await categoryContext.CountAsync(categoryContext.Query()));
            await database.SaveAsync();

            Assert.Equal(1, await categoryContext.CountAsync(categoryContext.Query()));
            categoryContext.Remove(category);
            Assert.Equal(1, await categoryContext.CountAsync(categoryContext.Query()));
            await database.SaveAsync();

            Assert.Equal(0, await categoryContext.CountAsync(categoryContext.Query()));
        }