public async Task <int> Insert(BreachedEmailApiModel model) { var id = _list.Min(i => i.Id); model.Id = id + 1; _list.Add(model); return(id); }
public async Task <int> Insert(BreachedEmailApiModel model) { var sql = "INSERT INTO BreachedEmail (Email) values (@email);SELECT CAST(SCOPE_IDENTITY() as int);"; return(await _conn.QuerySingleOrDefaultAsync <int>( sql, model)); }
public async void Post_Ok() { var model = new BreachedEmailApiModel { Email = "*****@*****.**" }; var response = await _controller.Post(model); Assert.IsType <CreatedResult>(response); }
public async void Post_EmailNull_BadRequest() { _controller.ModelState.AddModelError("Email", "Field is required"); var model = new BreachedEmailApiModel { Email = null }; var response = await _controller.Post(model); Assert.IsType <BadRequestObjectResult>(response); }
public async void Post_Email_Test() { var postRequest = new HttpRequestMessage(HttpMethod.Post, "/BreachedEmails"); var model = new BreachedEmailApiModel { Email = "*****@*****.**" }; postRequest.Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = await _client.SendAsync(postRequest); var responseString = await response.Content.ReadAsStringAsync(); Assert.Contains("email", responseString); Assert.Contains("*****@*****.**", responseString); }
public async Task <IActionResult> Post(BreachedEmailApiModel model) { if (ModelState.IsValid) { var existing = await _data.Get(model.Email); if (existing != null) { return(Conflict()); } model.Id = await _data.Insert(model); _cache.Set <BreachedEmailApiModel>(model.Email, model); return(Created($"{nameof(Post)}/{model.Email}", model)); } return(BadRequest(ModelState)); }