public HttpResponseMessage Post(AppUser model) { var connectionString = ConfigurationManager.ConnectionStrings["CraftingTable"].ConnectionString; using (IDbConnection sqlConnection = new SqlConnection(connectionString)) { sqlConnection.Execute( @"insert AppUsers(Id, Name, Email, Active, CreationTime) values (@Id, @Name, @Email, @Active, @CreationTime)", model); sqlConnection.Close(); } return Request.CreateResponse(); }
public void return_a_correct_data_from_database_for_a_default_get_request() { var aGuid = Guid.NewGuid(); dynamic entry = new ExpandoObject(); entry.id = aGuid; entry.name = "John Smith"; entry.email = "*****@*****.**"; entry.active = true; entry.creationTime = new DateTime(2016, 1, 1); var expected = ((object) entry).ToJObject(); var appUser = new AppUser { Id = aGuid, Name = "John Smith", Email = "*****@*****.**", Active = true, CreationTime = new DateTime(2016, 1, 1) }; var connectionString = ConfigurationManager.ConnectionStrings["CraftingTable"].ConnectionString; using (IDbConnection sqlConnection = new SqlConnection(connectionString)) { sqlConnection.Execute( @"insert AppUsers(Id, Name, Email, Active, CreationTime) values (@Id, @Name, @Email, @Active, @CreationTime)", appUser); sqlConnection.Close(); } using (var httpClient = new HttpClientFactory().Create()) { var response = httpClient.GetAsync("").Result; var actual = response.Content.ReadAsJsonAsync().Result; foreach (var user in actual.appUsers) { Console.WriteLine(user.ToString()); } Assert.Contains(expected, actual.appUsers); } }