public void DiaryUnitTest() { IService service = ServiceFactory.getInstance().getService(service_type.PUBLISH_TRAVEL_DIARY); PublishTravelDiaryRequest serviceRequest = new PublishTravelDiaryRequest(); TravelDiary td = new TravelDiary(); td.userId = 9; td.tags = "3452,532,df3"; td.content = "fajlsfjlkjl3kj4lk3j4l34lj343"; td.title = "zhangzhenrep9834"; Category c = new Category(); c.categoryId = 2; c.categoryName = "oversea"; td.belongCategory = c; td.addrs = new List<string>(); td.addrs.Add("fjladsfjkdsf"); td.addrs.Add("fjladsfjkdsfd"); td.addrs.Add("fjladsfjkdsfh"); serviceRequest.diary = td; ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(0, response.returnCode); }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } DeleteTravelDiaryRequest serviceRequest = (DeleteTravelDiaryRequest)request.requestObj; if (serviceRequest.userId < 0) { response.errMessage = ReportServiceMessage.USER_ID_ILLEGAL; response.returnCode = -1; return; } if (serviceRequest.diariesList != null) { String[] diaryIds = serviceRequest.diariesList.Split(','); if (diaryIds.Length > 0) { int len = diaryIds.Length; for (int index = 0; index < len; index++ ) { Diary.DeleteTraveDiary(int.Parse(diaryIds[index])); } } } DeleteTravelDiaryResponse serviceResponse = new DeleteTravelDiaryResponse(); response.responseObj = serviceResponse; response.returnCode = 0; }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } GetAssociatedProductsInfoRequest serviceRequest = (GetAssociatedProductsInfoRequest)request.requestObj; // if (serviceRequest.tags != null && serviceRequest.tags.Length > 0) { GetAssociatedProductsInfoResponse serviceResponse = new GetAssociatedProductsInfoResponse(); List<TravelProduct> products = new List<TravelProduct>(); //Mock Data List<TravelProduct> raw_products = new List<TravelProduct>(); MockData(raw_products); int seed = 10; Random rand = new Random(seed); int num = rand.Next(4, 7); for (int i = 0; i < num; i++) { int key = rand.Next(1, 10); products.Add(raw_products.ElementAt(key)); } serviceResponse.products = products; response.responseObj = serviceResponse; response.returnCode = 0; } }
public void process(ServiceRequest request, ServiceResponse response) { List<Category> list = new List<Category>(); string sqlStr = "select * from category"; MySqlConnection conn = ConnectionManager.getInstance().getConnection(); conn.Open(); MySqlDataAdapter mda = new MySqlDataAdapter(sqlStr, conn); DataSet ds = new DataSet(); mda.Fill(ds,"table1"); conn.Close(); int count = ds.Tables["table1"].Rows.Count; for (int i = 0; i < count; i++) { Category c = new Category(); c.categoryId = (int)ds.Tables["table1"].Rows[i][0]; c.categoryName = (string)ds.Tables["table1"].Rows[i][1]; list.Add(c); } GetCategoryResponse serviceResponse = new GetCategoryResponse(); serviceResponse.categories = list; response.responseObj = serviceResponse; response.returnCode = 0; }
public void GetAssociatedProductsInfoTestMethod() { IService service = ServiceFactory.getInstance().getService(service_type.GET_ASSOCIATED_PRODUCT); GetAssociatedProductsInfoRequest serviceRequest = new GetAssociatedProductsInfoRequest(); ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(0, response.returnCode); }
private void lazyinit() { repositoy = new MockDataRepository(); ServiceResponse response = null; response = new ServiceResponse(); response.responseObj = new GetUserInfoResponse(); repositoy.storeServiceEntity(service_type.GET_USER_INFO, response); response = new ServiceResponse(); response.responseObj = new RegistUserResponse(); repositoy.storeServiceEntity(service_type.REGIST_USER, response); response = new ServiceResponse(); response.responseObj = new UserLoginResponse(); repositoy.storeServiceEntity(service_type.USER_LOGIN, response); response = new ServiceResponse(); response.responseObj = new DeleteTravelDiaryResponse(); repositoy.storeServiceEntity(service_type.DELETE_TRAVEL_DIARY, response); response = new ServiceResponse(); response.responseObj = new UpdateTravelDiaryResponse(); repositoy.storeServiceEntity(service_type.UPDATE_TRAVEL_DIARY, response); response = new ServiceResponse(); response.responseObj = new PublishTravelDiaryResponse(); repositoy.storeServiceEntity(service_type.PUBLISH_TRAVEL_DIARY, response); response = new ServiceResponse(); response.responseObj = new GetTravelDiariesListResponse(); repositoy.storeServiceEntity(service_type.GET_TRAVEL_DIARYLIST, response); response = new ServiceResponse(); response.responseObj = new GetTravelDiaryDetailInfoResponse(); repositoy.storeServiceEntity(service_type.GET_TRAVEL_DIARY_DETAIL, response); response = new ServiceResponse(); response.responseObj = new GetTravelCommentsResponse(); repositoy.storeServiceEntity(service_type.GET_TRAVEL_COMMENT, response); response = new ServiceResponse(); response.responseObj = new GetAssociatedProductsInfoResponse(); repositoy.storeServiceEntity(service_type.GET_ASSOCIATED_PRODUCT, response); response = new ServiceResponse(); response.responseObj = new GetDisplayCategoriesResponse(); repositoy.storeServiceEntity(service_type.GET_DISPLAY_CATEGORY, response); return; }
public void GetTravelDiariesListTest() { IService service = ServiceFactory.getInstance().getService(service_type.GET_TRAVEL_DIARYLIST); GetTravelDiariesListRequest serviceRequest = new GetTravelDiariesListRequest(); serviceRequest.categoryIds = new System.Collections.Generic.List<long>(); serviceRequest.categoryIds.Add(2); ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(0, response.returnCode); }
public void ReserveProductTest() { IService service = ServiceFactory.getInstance().getService(service_type.RESERVE_PRODUCT); ReserveProductRequest serviceRequest = new ReserveProductRequest(); serviceRequest.diaryId = 5; serviceRequest.point = 5; ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(0, response.returnCode); }
public void CollectTravelDiaryTestMethod() { IService service = ServiceFactory.getInstance().getService(service_type.COLLECT_TRAVEL_DIARY); CollectTravelDiaryRequest serviceRequest = new CollectTravelDiaryRequest(); serviceRequest.userId = 45; serviceRequest.diaryId = 9; ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(0, response.returnCode); }
public void TestLoginFail() { IService service = ServiceFactory.getInstance().getService(service_type.USER_LOGIN); UserLoginRequest serviceRequest = new UserLoginRequest(); serviceRequest.username = "******"; serviceRequest.password = "******"; ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(-1, response.returnCode); }
public void TestLoginSuccess() { IService service = ServiceFactory.getInstance().getService(service_type.USER_LOGIN); UserLoginRequest serviceRequest = new UserLoginRequest(); serviceRequest.username = "******"; serviceRequest.password = "******"; ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(0, response.returnCode); Assert.IsTrue(7 == ((UserLoginResponse)response.responseObj).userId); }
public void ResgistUserTest() { IService service = ServiceFactory.getInstance().getService(service_type.REGIST_USER); RegistUserRequest serviceRequest = new RegistUserRequest(); UserInfo ui = new UserInfo(); ui.username = "******"; ui.password = "******"; ui.phone = "12344525"; ui.email = "*****@*****.**"; serviceRequest.userinfo = ui; ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(0, response.returnCode); }
public void ResgistUserTest1() { IService service = ServiceFactory.getInstance().getService(service_type.REGIST_USER); RegistUserRequest serviceRequest = new RegistUserRequest(); UserInfo ui = new UserInfo(); ui.username = "******"; ui.phone = "12344525"; ui.email = "*****@*****.**"; serviceRequest.userinfo = ui; ServiceRequest request = new ServiceRequest(serviceRequest); ServiceResponse response = new ServiceResponse(); service.process(request, response); Assert.AreEqual(-1, response.returnCode); Assert.AreEqual(ReportServiceMessage.USER_OR_PASSWORD_ILLEGAL, response.errMessage); }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } GetTravelCommentsRequest serviceRequest = (GetTravelCommentsRequest)request.requestObj; if (serviceRequest.userId < 0 || serviceRequest.diaryId < 0) { response.errMessage = ReportServiceMessage.USER_ID_OR_DIARY_ID_INVALID; response.returnCode = -1; return; } List<comment> list = Comment.getCommentsByDiaryID((int)serviceRequest.diaryId); int size = list.Count; List<TravelComment> comments = new List<TravelComment>(); for (int index = 0; index < size; index++) { TravelComment c = new TravelComment(); comment ct = list.ElementAt(index); // c.username = ct.diaryID; c.content = ct.content; c.username = "******"; comments.Add(c); } GetTravelCommentsResponse serviceResponse = new GetTravelCommentsResponse(); serviceResponse.comments = comments; response.responseObj = serviceResponse; response.returnCode = 0; return; }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } CollectTravelDiaryRequest serviceRequest = (CollectTravelDiaryRequest)request.requestObj; if (serviceRequest.diaryId < 0 || serviceRequest.userId < 0) { response.errMessage = ReportServiceMessage.USER_ID_OR_DIARY_ID_INVALID; response.returnCode = -1; return; } string sqlStr = String.Format("select * from diary_collect_info where userid={0} and diaryid={1}", serviceRequest.userId, serviceRequest.diaryId); MySqlConnection conn = ConnectionManager.getInstance().getConnection(); conn.Open(); MySqlDataAdapter mda = new MySqlDataAdapter(sqlStr, conn); DataSet ds = new DataSet(); mda.Fill(ds, "table1"); if (ds.Tables["table1"].Rows.Count == 0) { sqlStr = String.Format("insert into diary_collect_info values ({0}, {1})", serviceRequest.userId, serviceRequest.diaryId); MySqlCommand command = new MySqlCommand(); command.CommandText = sqlStr; command.Connection = conn; command.ExecuteNonQuery(); } conn.Close(); response.returnCode = 0; }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } GetUserInfoRequest serviceRequest = (GetUserInfoRequest)request.requestObj; if (serviceRequest.userId < 0) { response.errMessage = ReportServiceMessage.USER_ID_ILLEGAL; response.returnCode = -1; return; } GetUserInfoResponse serviceResponse = new GetUserInfoResponse(); response.responseObj = serviceResponse; response.returnCode = 0; }
public void storeServiceEntity(service_type type, ServiceResponse response_entity) { repositoy.Add(type, response_entity); }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } PublishTravelDiaryRequest serviceRequest = (PublishTravelDiaryRequest)request.requestObj; if (serviceRequest.diary.userId < 0) { response.errMessage = ReportServiceMessage.USER_ID_ILLEGAL; response.returnCode = -1; return; } diary d = new diary(); d.title = serviceRequest.diary.title; d.userID = (int)serviceRequest.diary.userId; d.tag = serviceRequest.diary.tags; d.content = serviceRequest.diary.content; d.publishTime = DateTime.Now; int diaryId = Diary.saveDiary(d); MySqlConnection conn = ConnectionManager.getInstance().getConnection(); conn.Open(); string addr1 = null; string addr2 = null; string addr3 = null; if(serviceRequest.diary.addrs.Count > 0) { addr1 = serviceRequest.diary.addrs.ElementAt(0); } if(serviceRequest.diary.addrs.Count > 1) { addr2 = serviceRequest.diary.addrs.ElementAt(1); } if(serviceRequest.diary.addrs.Count > 2) { addr3 = serviceRequest.diary.addrs.ElementAt(2); } string sqlStr = String.Format("insert into diary_pic_info values ({0}, '{1}', '{2}', '{3}')", diaryId, addr1, addr2, addr3); MySqlCommand command = new MySqlCommand(); command.CommandText = sqlStr; command.Connection = conn; command.ExecuteNonQuery(); sqlStr = String.Format("update diary set categoryID={0} where diaryId={1}", serviceRequest.diary.belongCategory.categoryId, diaryId); command = new MySqlCommand(); command.CommandText = sqlStr; command.Connection = conn; command.ExecuteNonQuery(); conn.Close(); PublishTravelDiaryResponse serviceResoponse = new PublishTravelDiaryResponse(); serviceResoponse.diaryId = diaryId; response.responseObj = serviceResoponse; response.returnCode = 0; return; }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } GetTravelDiariesListRequest serviceRequest = (GetTravelDiariesListRequest)request.requestObj; GetTravelDiariesListResponse serviceResponse = new GetTravelDiariesListResponse(); List<CategoryDiary> diarylist = new List<CategoryDiary>(); if (serviceRequest.diaryId > 0) { diary d = Diary.getDiaryByDiaryID((int)serviceRequest.diaryId); if (d != null) { TravelDiarySummary ds = new TravelDiarySummary(); ds.diaryId = d.diaryID; ds.diaryPicAddr = "default"; ds.diarySummary = "summary"; ds.publishTime = (DateTime)d.publishTime; ds.tags = d.tag; ds.title = d.title; CategoryDiary cd = new CategoryDiary(); string sqlStr = null; sqlStr = string.Format("select * from diary where diaryID={0}",ds.diaryId); MySqlConnection conn = ConnectionManager.getInstance().getConnection(); conn.Open(); MySqlDataAdapter mda = new MySqlDataAdapter(sqlStr, conn); DataSet ds1 = new DataSet(); mda.Fill(ds1, "table1"); conn.Close(); int count = ds1.Tables["table1"].Rows.Count; cd.categoryId = (int)ds1.Tables["table1"].Rows[0][10]; cd.diares = new List<TravelDiarySummary>(); cd.diares.Add(ds); diarylist.Add(cd); } } else { if (serviceRequest.categoryIds.Count > 0) { int count = serviceRequest.categoryIds.Count; List<CategoryDiary> flist = new List<CategoryDiary>(); for (int i = 0; i < count; i++) { long cid = serviceRequest.categoryIds.ElementAt(i); string sqlStr = string.Format("select * from diary where categoryID={0}", cid); MySqlConnection conn = ConnectionManager.getInstance().getConnection(); conn.Open(); MySqlDataAdapter mda = new MySqlDataAdapter(sqlStr, conn); DataSet ds1 = new DataSet(); mda.Fill(ds1, "table1"); conn.Close(); CategoryDiary cd = new CategoryDiary(); cd.categoryId = cid; cd.diares = new List<TravelDiarySummary>(); int sd = ds1.Tables["table1"].Rows.Count; if (sd > 0) { for (int j = 0; j < sd; j++) { TravelDiarySummary tds = new TravelDiarySummary(); tds.diaryId = (int)ds1.Tables["table1"].Rows[j][0]; tds.diarySummary = "fdsafsd"; tds.publishTime = (DateTime)ds1.Tables["table1"].Rows[j][5]; tds.tags = (string)ds1.Tables["table1"].Rows[j][4]; tds.title = (string)ds1.Tables["table1"].Rows[j][2]; tds.userId = (int)ds1.Tables["table1"].Rows[j][1]; cd.diares.Add(tds); } } //int size = ds1.Tables["table1"].Rows.Count; //List<string> strlist = new List<string>(); //if (count > 0) //{ // string str = null; // str = (string)ds1.Tables["table1"].Rows[0][1]; // if (str != null) // strlist.Add(str); // str = (string)ds1.Tables["table1"].Rows[0][2]; // if (str != null) // strlist.Add(str); // str = (string)ds1.Tables["table1"].Rows[0][3]; // if (str != null) // strlist.Add(str); //} flist.Add(cd); } serviceResponse.diaries = flist; } if (serviceRequest.userId > 0) { } //int userid = () } serviceResponse.diaries = diarylist; response.responseObj = serviceResponse; response.returnCode = 0; }
private string SubmitArticle() { JavaScriptSerializer jss = new JavaScriptSerializer(); var paramDes = jss.Deserialize<TravelDiary>(Request["queryParam"]); PublishTravelDiaryRequest registerReq = new PublishTravelDiaryRequest(); registerReq.diary = paramDes; ServiceRequest request = new ServiceRequest(registerReq); ServiceResponse response = new ServiceResponse(); IService service = ServiceFactory.getInstance().getService(service_type.PUBLISH_TRAVEL_DIARY); service.process(request, response); PublishTravelDiaryResponse responseU = (PublishTravelDiaryResponse)response.responseObj; return responseU.diaryId.ToString(); }
private string GetProducts() { JavaScriptSerializer jss = new JavaScriptSerializer(); GetAssociatedProductsInfoRequest registerReq = new GetAssociatedProductsInfoRequest(); ServiceRequest request = new ServiceRequest(registerReq); ServiceResponse response = new ServiceResponse(); IService service = ServiceFactory.getInstance().getService(service_type.GET_ASSOCIATED_PRODUCT); service.process(request, response); GetAssociatedProductsInfoResponse responseU = (GetAssociatedProductsInfoResponse)response.responseObj; return jss.Serialize(responseU.products); }
private string GetCategoryList() { JavaScriptSerializer jss = new JavaScriptSerializer(); GetCategoryRequest registerReq = new GetCategoryRequest(); ServiceRequest request = new ServiceRequest(registerReq); ServiceResponse response = new ServiceResponse(); IService service = ServiceFactory.getInstance().getService(service_type.GET_DISPLAY_CATEGORY); service.process(request, response); GetCategoryResponse responseU = (GetCategoryResponse)response.responseObj; return jss.Serialize(responseU.categories); }
private string GetArticleByID() { JavaScriptSerializer jss = new JavaScriptSerializer(); string articleId = Request["id"].ToString(); GetTravelDiaryDetailInfoRequest registerReq = new GetTravelDiaryDetailInfoRequest(); registerReq.diaryid = int.Parse(articleId); ServiceRequest request = new ServiceRequest(registerReq); ServiceResponse response = new ServiceResponse(); IService service = ServiceFactory.getInstance().getService(service_type.GET_TRAVEL_DIARY_DETAIL); service.process(request, response); GetTravelDiaryDetailInfoResponse responseU = (GetTravelDiaryDetailInfoResponse)response.responseObj; return jss.Serialize(responseU.diaryInfo); }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } GetTravelDiaryDetailInfoRequest serviceRequest = (GetTravelDiaryDetailInfoRequest)request.requestObj; if (serviceRequest.diaryid < 0 || serviceRequest.userId < 0) { response.errMessage = ReportServiceMessage.USER_ID_OR_DIARY_ID_INVALID; response.returnCode = -1; return; } GetTravelDiaryDetailInfoResponse serviceResponse = new GetTravelDiaryDetailInfoResponse(); if (serviceRequest.diaryid > 0) { diary d = Diary.getDiaryByDiaryID((int)serviceRequest.diaryid); if (d != null) { TravelDiary ds = new TravelDiary(); ds.diaryId = d.diaryID; ds.content = d.content; ds.userId = (long)d.userID; ds.publishTime = ((DateTime)d.publishTime).ToString(); ds.tags = d.tag; ds.title = d.title; serviceResponse.diaryInfo = ds; } string sqlStr = string.Format("select * from diary_pic_info where diaryId={0}", serviceRequest.diaryid); MySqlConnection conn = ConnectionManager.getInstance().getConnection(); conn.Open(); MySqlDataAdapter mda = new MySqlDataAdapter(sqlStr, conn); DataSet ds1 = new DataSet(); mda.Fill(ds1, "table1"); conn.Close(); int count = ds1.Tables["table1"].Rows.Count; List<string> strlist = new List<string>(); if(count > 0) { string str = null; str = (string)ds1.Tables["table1"].Rows[0][1]; if(str != null) strlist.Add(str); str = (string)ds1.Tables["table1"].Rows[0][2]; if (str != null) strlist.Add(str); str = (string)ds1.Tables["table1"].Rows[0][3]; if (str != null) strlist.Add(str); } serviceResponse.diaryInfo.addrs = strlist; } response.responseObj = serviceResponse; response.returnCode = 0; }