我正在编写一个集成测试,该测试将在数据库中插入许多对象,然后检查以确保我的方法是否检索到这些对象。 我与数据库的连接是通过NHibernate进行的,而创建此类测试的常用方法是执行以下操作: NHibernateSession.BeginTransaction(); //use nhibernate to insert objects into database //retrieve objects via my method //verify actual objects returned are the same as those inserted NHibernateSession.RollbackTransaction(); 但是,我最近发现了TransactionScope,显然可以用于此目的... 我发现的一些示例代码如下: public static int AddDepartmentWithEmployees(Department dept) { int res = 0; DepartmentAdapter deptAdapter = new DepartmentAdapter(); EmployeeAdapter empAdapter = new EmployeeAdapter(); using (TransactionScope …
我需要在WebApi中创建POST方法,以便可以将数据从应用程序发送到WebApi方法。我无法获取标头值。 在这里,我在应用程序中添加了标头值: using (var client = new WebClient()) { // Set the header so it knows we are sending JSON. client.Headers[HttpRequestHeader.ContentType] = "application/json"; client.Headers.Add("Custom", "sample"); // Make the request var response = client.UploadString(url, jsonObj); } 遵循WebApi post方法: public string Postsam([FromBody]object jsonData) { HttpRequestMessage re = new HttpRequestMessage(); var headers = …