public async Task StoreAsync(ServiceApiDescription apiDescription) { var existing = _context.Apis.SingleOrDefault(x => x.ServiceId == apiDescription.ServiceId); if (existing == null) { _logger.LogDebug("Api for {serviceId} not found in database", apiDescription.ServiceId); var entity = apiDescription.ToEntity(); _context.Apis.Add(entity); } else { _logger.LogDebug("Api for {serviceId} found in database", apiDescription.ServiceId); apiDescription.UpdateEntity(existing); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { _logger.LogWarning("exception updating Api for {serviceId} in database: {error}", apiDescription.ServiceId, ex.Message); } }
public void Can_Convert_To_And_From_Entity() { var model = new ServiceApiDescription(); var entity = model.ToEntity(); model = entity.ToModel(); entity.Should().NotBeNull(); model.Should().NotBeNull(); }
public async Task Returns_Item_When_Api_Exists() { var model = new ServiceApiDescription { ServiceId = "Returns_Item_When_Api_Exists" }; using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { context.Apis.Add(model.ToEntity()); context.SaveChanges(); } using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { var store = new ApiStore(context, new Mock <ILogger <ApiStore> >().Object); var item = await store.FindByServiceIdAsync(model.ServiceId); item.Should().NotBeNull(); } }