public async Task List() { var env = new UnitTestEnvironment(); await env.Run(async sp => { var databaseContext = sp.GetRequiredService <IDatabaseContext>(); await DataCommon.DataInitAsync(databaseContext); }); Guid id = Guid.Empty; string username = null; await env.Run(async sp => { MockController controller = new MockController(sp); var model = await controller.ExecuteAsync <EntityDomainService <User>, IEntityViewModel <User> >("List"); Assert.Equal(2, model.Items.Length); id = model.Items[0].Index; username = model.Items[0].Username; }); await env.Run(async sp => { MockController controller = new MockController(sp); var model = await controller.ExecuteAsync <EntityDomainService <User>, IEntityEditModel <User> >(context => { context.ValueProvider.SetAlias("id", "Index"); context.ValueProvider.SetValue("id", id); }, "Detail"); Assert.Equal(username, model.Item.Username); }); }
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); }
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); }); }
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); } }