Exemplo n.º 1
0
        public async Task OnGetAsyncPopulatesPageModel()
        {
            // Arrange: seed database with test data
            await PrepareTestContext(async(context) =>
            {
                var expectedClients = SeedTestData.GetSeedingClients();

                // Act: retrieve clients
                var pageModel = new IndexModel(context);
                await pageModel.OnGetAsync();

                // Assert: seeded and retrieved clients match
                var actualMessages = Assert.IsAssignableFrom <List <Client> >(pageModel.Client);
                Assert.Equal(
                    expectedClients.OrderBy(a => a.Name).Select(a => a.Name),
                    actualMessages.OrderBy(a => a.Name).Select(a => a.Name));
            });
        }
Exemplo n.º 2
0
        public async Task ClientsAreRetrievedTest()
        {
            using (var db = new IdentityContext(Utilities.TestDbContextOptions()))
            {
                // Arrange: seed database with clients
                var expectedClients = SeedTestData.GetSeedingClients();
                await db.AddRangeAsync(expectedClients);

                await db.SaveChangesAsync();

                // Act: retrieve seeded clients from database
                var result = await db.Client.AsNoTracking().ToListAsync();

                // Assert: seeded and retrieved clients match
                var actualClients = Assert.IsAssignableFrom <List <Client> >(result);
                Assert.Equal(
                    expectedClients.OrderBy(a => a.Id).Select(a => a.Name),
                    actualClients.OrderBy(a => a.Id).Select(a => a.Name));
            }
        }