Пример #1
0
            public async void GivenDatabaseHasNoObjects_ItShouldReturnNullByIdAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                TestObject foundObject;

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    foundObject = await repository.GetByIdAsync(0);
                }

                foundObject.Should().BeNull();
            }
Пример #2
0
            public async void GivenDatabaseHasObjects_ItShouldReturnOneByIdAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                var        seedData       = options.EnsureSeeded();
                var        expectedObject = seedData[0];
                TestObject foundObject;

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    foundObject = await repository.GetByIdAsync(expectedObject.Id);
                }

                foundObject.Should().BeEquivalentTo(expectedObject);
            }