public ActionResult Post([FromBody] Site value) { try { return(Ok(_repo.Create(value))); } catch (Exception e) { return(BadRequest(e)); } }
public void Create(int newId) { var newItem = new Site { Id = newId, Name = $"Site {newId}" }; var repository = new SiteRepository(_dbContext, _cache.Object, _logger.Object); var returnId = repository.Create(newItem); var item = _dbContext.Sites.Find(returnId); Assert.Equal(newId, returnId); Assert.NotNull(item); Assert.Equal(newItem.Name, item.Name); }
public void Should_save_new_site() { var newSite = SiteFactory.CreateNew(Guid.NewGuid(), "Name 3"); using (var context = new MSSQLDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); repository.Create(newSite); } using (var context = new MSSQLDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var language = repository.GetById(newSite.Id); Assert.NotNull(language); } }