示例#1
0
            public async void GivenObjectIsNotSaved_ItShouldNotGetSavedByOtherSavesAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                var seedData   = options.EnsureSeeded();
                var seedObject = seedData.First();

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    var list       = await repository.ListAsync(o => o.Id.Equals(seedObject.Id));

                    var testObject = list.First();
                    testObject.Name = "ChangedName";
                    var otherList = await repository.ListAsync(o => !o.Id.Equals(seedObject.Id));

                    // Potentially saves all tracked objects
                    await repository.EditAsync(otherList.First());
                }

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    var list       = await repository.ListAsync(o => o.Id.Equals(seedObject.Id));

                    var testObject = list.First();
                    testObject.Name.Should().NotBe("ChangedName");
                }
            }
示例#2
0
            public async void GivenDatabaseIsEmpty_ItShouldReturnEmptyListAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    (await repository.ListAsync()).Should().BeEmpty();
                }
            }
示例#3
0
            public async void GivenDatabaseContainsObjects_ItShouldReturnAllBySpecificationAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                var seedData = options.EnsureSeeded();
                IList <TestObject> returnedList;

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    returnedList = await repository.ListAsync(new EmptySpecification <TestObject>(o => true));
                }

                returnedList.Should().BeEquivalentTo(seedData);
            }
示例#4
0
            public async void GivenDatabaseContainsObjects_ItShouldReturnOnlyObjectsWithAThreeInTheNameAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;

                options.EnsureSeeded();
                IList <TestObject> returnedList;

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    returnedList = await repository.ListAsync(o => o.Name.Contains("3"));
                }

                returnedList.Should()
                .OnlyContain(o => o.Name.Contains("3"));
            }
示例#5
0
            public async void GivenListByMultipleCriteria_ItShouldReturnObjectsMeetingCriteriaAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                var seedData        = options.EnsureSeeded();
                var searchingObject = seedData.First();
                IList <TestObject> returnedList;

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    returnedList = await repository.ListAsync(o =>
                                                              o.Id.Equals(searchingObject.Id) && o.Name.Equals(searchingObject.Name));
                }

                returnedList.Should()
                .ContainSingle(o => o.Id.Equals(searchingObject.Id) && o.Name.Equals(searchingObject.Name));
            }