コード例 #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 GivenObjectContainedInDatabaseIsEdited_ItShouldBePersistedAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                var seedData      = options.EnsureSeeded();
                var changedObject = seedData[0];

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    changedObject.Name = "EditedObject";
                    await repository.EditAsync(changedObject);
                }

                using (var context = new TestContext(options))
                {
                    var foundObject = context.Find <TestObject>(changedObject.Id);
                    foundObject.Should().BeEquivalentTo(changedObject);
                }
            }