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"); } }
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(); } }
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); }
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")); }
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)); }