public BrashQueryResult <T> FindWhere(string where) { BrashQueryResult <T> result = new BrashQueryResult <T>() { Models = new List <T>() , Message = "init" , Status = BrashQueryStatus.INFORMATION }; IEnumerable <T> models = PerformFind(where); if (models.Count() > 1) { result.UpdateStatus(BrashQueryStatus.SUCCESS, $"{models.Count()} records found"); result.Models = models.ToList(); } else if (models.Count() > 0) { result.UpdateStatus(BrashQueryStatus.NO_RECORDS, $"{models.Count()} records found"); } return(result); }
public void RepoFindModel() { MethodBase methodBase = MethodBase.GetCurrentMethod(); string dbName = $"{methodBase.ReflectedType.Name}_{methodBase.Name}"; string path = "/shop/randomsilo/brash/BrashTest/sql/"; string databaseFile = $"{path}/{dbName}.sqlite"; System.IO.File.Delete(databaseFile); string logFile = $"{path}/{dbName}.log"; ILogger logger = GetLogger(logFile); var person = new BrashTest.Mock.Model.Person() { LastName = "Smith" , FirstName = "Jane" , MiddleName = "Francis" }; Assert.NotNull(person); IDatabaseContext databaseContext = new DatabaseContext( $"Data Source={databaseFile}" , $"{dbName}" , "MockSchema" , $"{path}/Person.sql" ); Assert.NotNull(databaseContext); var personRepoSql = new PersonRepositorySql(); Assert.NotNull(personRepoSql); IManageDatabase databaseManager = new DatabaseManager(databaseContext); Assert.NotNull(databaseManager); databaseManager.CreateDatabase(); var personRepo = new PersonRepository(databaseManager, personRepoSql, logger); Assert.NotNull(personRepo); BrashActionResult <BrashTest.Mock.Model.Person> result = null; List <Mock.Model.Person> people = new List <Mock.Model.Person>(); people.Add(new Mock.Model.Person() { PersonId = null , LastName = "Smith" , MiddleName = "Matt" , FirstName = "David" }); people.Add(new Mock.Model.Person() { PersonId = null , LastName = "Quincy" , MiddleName = "Kyle" , FirstName = "Rick" }); people.Add(new Mock.Model.Person() { PersonId = null , LastName = "Givens" , MiddleName = "Matt" , FirstName = "Robert" }); List <int?> personIds = new List <int?>(); foreach (var p in people) { result = personRepo.Create(p); Assert.True(result.Status == BrashActionStatus.SUCCESS); Assert.True(result.Model.PersonId >= 0); personIds.Add(result.Model.PersonId); } BrashQueryResult <Mock.Model.Person> findResult = null; findResult = personRepo.FindWhere("WHERE MiddleName = 'Matt'"); Assert.True(findResult.Status == BrashQueryStatus.SUCCESS); Assert.True(findResult.Models.Count() == 2); findResult = personRepo.FindWhere("WHERE MiddleName = 'Jamie'"); Assert.True(findResult.Status == BrashQueryStatus.NO_RECORDS); Assert.True(findResult.Models.Count() == 0); }