public void TestAsyncRequest() { var repo = new EfCoreRepository <Contact>(context); var contacts = repo.GetAll().ToAsyncEnumerable().ToList(); contacts.Result.Count.ShouldBe(0); }
public void EfCoreGetAllSateShouldBeUnchanged() { var repository = new EfCoreRepository <Contact, string>(dbContext); var firstContact = repository.GetAll().First(); dbContext.Entry(firstContact).State.ShouldBe(EntityState.Unchanged); }
public void EfCoreGetAllWithStrategySateShouldBeUnchanged() { var repository = new EfCoreRepository <Contact, string>(dbContext); var strat = new GenericFetchStrategy <Contact>(); var firstContact = repository.GetAll(strat).First(); dbContext.Entry(firstContact).State.ShouldBe(EntityState.Unchanged); }
public void EfCore_GetAll_Without_Includes_LazyLoads_Email() { var repository = new EfCoreRepository <Contact, string>(dbContext); var contact = repository.GetAll().First(); contact.Name.ShouldBe("Test User 1"); dbContext.QueryLog.Count(filterSelects).ShouldBe(1); contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**"); // dbContext.QueryLog.Count(filterSelects).ShouldBe(2); may be that dbcontext is disposed and the successive queries are not logged, quieries does not contains email so query was made in a lazy way but after. }
public void EfCore_GetAll_With_Text_Include_LazyLoads_Email() { var repository = new EfCoreRepository <Contact, string>(dbContext); var contact = repository.GetAll("EmailAddresses").First(); contact.Name.ShouldBe("Test User 1"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); }
public void EfCore_GetAll_With_Text_Include_And_Pagination_LazyLoads_Email() { var repository = new EfCoreRepository <Contact, string>(dbContext); var pagination = new PagingOptions <Contact>(1, 4, "ContactId"); var contact = repository.GetAll(pagination, "EmailAddresses").First(); contact.Name.ShouldBe("Test User 1"); dbContext.QueryLog.Count(filterSelects).ShouldBe(3); // first query is count for total records contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**"); dbContext.QueryLog.Count(filterSelects).ShouldBe(3); }
public void EfCore_GetAll_With_Includes_In_Strategy_LazyLoads_Email() { var repository = new EfCoreRepository <Contact, string>(dbContext); var strategy = new GenericFetchStrategy <Contact>(); strategy.Include(x => x.EmailAddresses); var contact = repository.GetAll(strategy).First(); contact.Name.ShouldBe("Test User 1"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); }
public void EfCore_GetAll_With_Selector_Selects_Only_Specified_Columns() { var repository = new EfCoreRepository <EmailAddress, int>(dbContext); var emailAddress = repository.GetAll(s => new { s.ContactId, s.EmailAddressId, s.Email }).First(); emailAddress.Email.ShouldStartWith("omar.piani."); dbContext.QueryLog.Count(filterSelects).ShouldBe(1, "A select was executed"); string queryLogElement = dbContext.QueryLog.Where(filterSelects).First(); Regex regex = new Regex("SELECT(.+)FROM.+", RegexOptions.IgnoreCase | RegexOptions.Singleline); var selectMatches = regex.Matches(queryLogElement); selectMatches.Count.ShouldBe(1, "A regex match was found for the select pattern"); var selectPart = selectMatches[0].Groups[1].Value; selectPart.ShouldContain(nameof(EmailAddress.ContactId), "ContactId was selected"); selectPart.ShouldContain(nameof(EmailAddress.EmailAddressId), "EmailAddressId was selected"); selectPart.ShouldContain(nameof(EmailAddress.Email), "Email was selected"); selectPart.ShouldNotContain(nameof(EmailAddress.Label), "Label was not selected"); }