public void TestAdd() { var requests = new Contents() { { "dn", new List <string> { "dn0" } }, { "msgid", new List <string> { "1" } }, { "suffix", new List <string> { "suffix" } }, { "a", new List <string> { "a0" } }, { "b", new List <string> { "b0", "b1" } }, }; var result = db.Add(requests); Assert.IsTrue(result); stream.Position = 0; var buffer = new byte[stream.Length]; stream.Read(buffer); var actual = Encoding.UTF8.GetString(buffer); var expected = "{\"dn0\":{\"dn\":[\"dn0\"],\"a\":[\"a0\"],\"b\":[\"b0\",\"b1\"]}}"; Assert.AreEqual(expected, actual); stream.Position = 0; requests = new Contents() { { "dn", new List <string> { "dn1" } }, { "c", new List <string> { "c0", "c1", "c2" } }, }; result = db.Add(requests); Assert.IsTrue(result); stream.Position = 0; buffer = new byte[stream.Length]; stream.Read(buffer); actual = Encoding.UTF8.GetString(buffer); expected = "{\"dn0\":{\"dn\":[\"dn0\"],\"a\":[\"a0\"],\"b\":[\"b0\",\"b1\"]},\"dn1\":{\"dn\":[\"dn1\"],\"c\":[\"c0\",\"c1\",\"c2\"]}}"; Assert.AreEqual(expected, actual); }
public IActionResult Post([FromBody] Num num) { _db.Add(new Num { Id = Guid.NewGuid(), Name = num.Name }); return(Ok()); }
public Book AddBook(string title) { EnsureArgumentNotNull(title); var m = new Book { Title = title, CreateTime = DateTime.Now }; var id = m_db.Add(m); if (id >= 0) { m.Id = id; return(m); } return(null); }
public void Enqueue(BackgroundTask task) { if (task == null) return; if (task.UserId == null) { task.UserId = _userContext.UserId; } var queueItem = new QueueItem { Created = _clock.Now(), Name = task.Name, Type = task.GetType().Name, Data = JsonConvert.SerializeObject(task), }; _db.Add(queueItem); EnqueueItemInHangfire(queueItem); }
public async Task <IActionResult> Add([FromBody] CommentJson com) { try { if (!ModelState.IsValid) { return(BadRequest("Wrong model")); } if (await _service.Add(com)) { return(Ok()); } else { return(BadRequest()); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public static int Add(string query, Action <IDbCommand> parameterizer) { return(db.Add(query, parameterizer)); }
public async Task <IActionResult> Post([FromBody] Num num) { await _db.Add(new Num { Id = Guid.NewGuid().ToString(), Name = num.Name }); return(Ok()); }