public void Delete() { int customerID = 16; // Creating an unit of word cause to use one dbcontext. CustomerUnitOfWork unitOfWork = new CustomerUnitOfWork(); GenericRepository <Customer.DataLayer.Customer> repCustomer = unitOfWork.GetRepoInstance <Customer.DataLayer.Customer>(); int expctedCount = repCustomer.Count(); Customer.DataLayer.Customer customer = unitOfWork.GetRepoInstance <Customer.DataLayer.Customer>().GetAll().Where(c => c.CustomerID == customerID).Single(); unitOfWork.GetRepoInstance <Customer.DataLayer.Customer>().Delete(customer); unitOfWork.SaveChanges(); Assert.AreEqual(--expctedCount, repCustomer.Count()); }
public void Insert() { // Arrange: // Web API posts CustomerViewModel via json format and will be deserialized into CustomerViewModel CustomerViewModel customer = new CustomerViewModel(); customer.FirstName = "nameTest"; customer.LastName = "familyTest"; customer.CityName = "Hamedan"; customer.ProvinceName = "Hamedan"; // Creating an unit of work. CustomerUnitOfWork unitOfWork = new CustomerUnitOfWork(); // Mapping ViewModel to Model to provide database format model Customer.DataLayer.Customer entityCustomer = Mapper.Map <CustomerViewModel, Customer.DataLayer.Customer>(customer); // Find city and province entity City city = unitOfWork.GetRepoInstance <City>().GetAll().Where(s => s.CityName == customer.CityName).Single(); Province province = unitOfWork.GetRepoInstance <Province>().GetAll().Where(s => s.ProvinceName == customer.ProvinceName).Single(); city.Province = province; // change city becuase city is a new city in mapping and we don't want to create new city. entityCustomer.City = city; // Creating a customer item. //Customer.DataLayer.Customer c = new Customer.DataLayer.Customer() //{ // FirstName = "test", // LastName = "test", // City = city, //}; GenericRepository <Customer.DataLayer.Customer> repCustomer = unitOfWork.GetRepoInstance <Customer.DataLayer.Customer>(); int expctedCount = repCustomer.Count(); repCustomer.Insert(entityCustomer); repCustomer.Save(); Assert.AreEqual(++expctedCount, repCustomer.Count()); }
public void Test08_Count() { int result = 0; var filter = new SampleEntity() { Name = "roberto" }; using (var repos = new GenericRepository <SampleEntity>(DatabaseEngine.SQLite, connString)) { result = repos.Count(filter); } Assert.True(result > 0); }
private bool AddNewDays() { bool b = false; var now = DateTime.Now; int cnt = weatherRepository.Count(i => i.Date > now); if (cnt < ndays) { var days = weatherRepository.FindAllAsQueryable(i => i.Date > now).ToList(); days = Enumerable.Range(1, ndays).Select(i => new DbWeatherInfo(now.AddDays(i))).Where(i => !days.Any(j => j.Date == i.Date)).ToList(); weatherRepository.Insert(days); b = true; } return(b); }
public TableauMetadataFactory(GenericRepository <TableauBlob> blobsRepo) { _blobs = blobsRepo.All(); _xmls = new List <TableauXml>(); double count = blobsRepo.Count(); double i = 1; foreach (var b in _blobs) { _xmls.Add(new TableauXml() { Id = b.Id, RepositoryId = b.RepositoryId, SiteId = b.SiteId, Xml = TableauFileReader.GetXML(b), SourceType = b.SourceType }); var per_complete = Math.Round((i / count) * 100, 0); Console.Write("\r{0}% Parsing is Completed", per_complete); i++; } Console.WriteLine(""); }
protected override async Task <IEnumerable <Transaction> > Paginate() { if (coudSyncSetting != null && coudSyncSetting.Enabled) { var skip = (page.CurrentPage - 1) * page.PageCount; if (transactionRepository.Count(x => x.AccountId.Equals(page.AccountId)) > skip) { var c = GetCachedFilteredTransactions(skip); return(await Task.FromResult(c)); } } page.Transactions.Clear(); await Task.Delay(500); page = await transactionServiceClient.Page(page); var transasctionsResult = MapPageToEntity(page); return(transasctionsResult); }
public int Count() { return(_repository.Count()); }
public int Count() { return(_repository.Count().Result); }