public void CanAddListOfTags(string tag1, string tag2, string tag3, bool success) { string[] myString = { tag1, tag2, tag3 }; TResponse <List <Tags> > response = manager.AddListOfTags(myString); Assert.AreEqual(success, response.Success); }
public ActionResult AddUpdate(UserProfileModel objUserProfileModel) { if (objUserProfileModel.Type == "Customer") { objTResponse = new UserProfileBusiness().AddUpdate(objUserProfileModel); } return(RedirectToAction("List")); }
private void Awake() { //inisiating the variables perception_M = GameObject.FindGameObjectWithTag("GameController").GetComponent <PManager>(); response = TResponse.DoNothing; Target = null; envalopes = new List <Envalope>(); }
public void CanGetCategoryById(int id, bool success) { TResponse <Categories> response = manager.GetCategoryById(id); //TResponse<List<Categories>> allCategories = manager.GetAllCategories(); Assert.AreEqual(success, response.Success); //Assert.AreEqual(allCategories.Payload[0].CategoryName, response.Payload.CategoryName ); }
void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; try { HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); #region parse the content #endregion try { DataContractJsonSerializer ser = null; if (Type == SocialType.Tencent) { //{"data":{"id":"84291041886790","time":1337332120},"errcode":0,"imgurl":"http:\/\/t1.qpic.cn\/mblogpic\/c50c86e2a078ec4dfb9c","msg":"ok","ret":0} ser = new DataContractJsonSerializer(typeof(TResponse)); TResponse tr = ser.ReadObject(streamResponse) as TResponse; if (tr.errcode == 0) { UploadCompleted.Invoke("ok", null); } else { UploadCompleted.Invoke(new Exception(tr.msg), null); } } else if (Type == SocialType.Weibo) { UploadCompleted.Invoke("ok", null); } else if (Type == SocialType.Renren) { //{"uid":222808196,"src_small":"http://fmn.rrfmn.com/fmn058/20120521/1400/p_main_lHP2_25e400002c051261.jpg","caption":"12312312","pid":6036647931,"src":"http://fmn.rrfmn.com/fmn058/20120521/1400/p_head_W7RI_25e400002c051261.jpg","aid":629133235,"src_big":"http://fmn.rrfmn.com/fmn058/20120521/1400/p_large_6uUE_25e400002c051261.jpg"} UploadCompleted.Invoke("ok", null); } else if (Type == SocialType.Douban) { UploadCompleted.Invoke("ok", null); } } catch (Exception) { } streamResponse.Close(); streamRead.Close(); // Release the HttpWebResponse response.Close(); } catch (WebException ex) { UploadCompleted.Invoke(ex, null); return; } }
public void CanGetReviewById(int id, bool success) { TResponse <Reviews> response = manager.GetReviewById(id); //TResponse<List<Reviews>> allReviews = manager.GetAllReviews(); Assert.AreEqual(success, response.Success); //Assert.AreEqual(allReviews.Payload[1].ReviewTitle, "Massengil does it again!"); }
public void CanDeleteReview(int id, bool success) { TResponse <Reviews> review = manager.DeleteReview(id); TResponse <List <Reviews> > allReviews = manager.GetAllReviews(); Assert.AreEqual(success, review.Success); //Assert.AreEqual(3, allReviews.Payload.Count); //does this need to reflect the methods used above? }
//[TestCase(100, false)] //[TestCase(1, false)] //[TestCase(100, true)] public void CanGetTagByReviewId(int id, bool success) { TResponse <List <Tags> > response = manager.GetTagByReviewId(id); Assert.AreEqual(response.Success, success); //Assert.AreEqual(response.Success, success); //index out of range/does not exists //Assert.AreNotSame(response.Success, success); //should not return false //Assert.AreNotSame(response.Success, success); //should not return true }
/// <summary> /// Invoke "POST" request /// </summary> /// <typeparam name="TResponse">Type of API response object</typeparam> /// <returns>Typed response object</returns> public TResponse InvokePost <TResponse>() { //get response as JSON string String jsonString = InvokePost(); JavaScriptSerializer serializer = new JavaScriptSerializer(); TResponse deserializedObject = serializer.Deserialize <TResponse>(jsonString); return(deserializedObject); }
public TResponse <List <Tags> > EditTagsForReview(int reviewId, List <Tags> newTagsListForReview, List <Tags> currentTagsListForReview) { TResponse <List <Tags> > response = new TResponse <List <Tags> >(); //set up new list List <Tags> tagsListToBeAssociatedWithReview = new List <Tags>(); foreach (var tag in currentTagsListForReview) { tagsListToBeAssociatedWithReview.Add(tag); } foreach (var newTag in newTagsListForReview) { if (!currentTagsListForReview.Any(m => m.TagId == newTag.TagId)) { //add tags that are not in the current list tagsListToBeAssociatedWithReview.Add(newTag); } } foreach (var currentTag in currentTagsListForReview) { if (!newTagsListForReview.Any(m => m.TagId == currentTag.TagId)) { //remove tags that are not in the new list tagsListToBeAssociatedWithReview.Remove(currentTag); } } if (tagsListToBeAssociatedWithReview != null) { //delete tags for review Repo.DeleteTagsAssociatedWithReview(reviewId); //add the new list of tags response.Payload = Repo.EditTagsForReview(reviewId, tagsListToBeAssociatedWithReview); if (response.Payload == null) { response.Message = $"Tags added to Review Id {reviewId} unsuccessfully."; response.Success = false; } else { response.Success = true; } } else { response.Message = $"No list of tags sent with Review Id {reviewId}"; } return(response); }
/// <summary> /// Converts the json result in HttpResponseMessage to a TResponse object /// </summary> /// <typeparam name="TResponse">Entity type in the response</typeparam> /// <returns></returns> public static Func <HttpResponseMessage, Task <TResponse> > GetResponseJsonConverter <TResponse>() { return(new Func <HttpResponseMessage, Task <TResponse> >(async(response) => { string responseContent = await response.Content.ReadAsStringAsync(); TResponse entity = (string.IsNullOrEmpty(responseContent)) ? default(TResponse) : DeserializeJSon <TResponse>(responseContent); return await Task.FromResult(entity); })); }
public static ExecuteAttempt Successful(TResponse response) { if (response == null) { throw new ArgumentNullException(nameof(response)); } return(new ExecuteAttempt() { Status = ThirdPartyResponse.Successful, Response = response }); }
public static VerificationAttempt Successful(TResponse response) { if (response == null) { throw new ArgumentNullException(nameof(response)); } return(new VerificationAttempt { Response = response, Verification = ThirdPartyVerification.Successful }); }
public void CanAddCategory(string categoryName, bool success) { Categories category = new Categories() { // id does not need to be added CategoryName = categoryName }; TResponse <Categories> response = manager.AddCategory(category); Assert.AreEqual(success, response.Success); }
//[TestCase(1, "Funny", false)] //[TestCase(null, "Funny", false)] //[TestCase(1, "", false)] //[TestCase(100, "Scum bucket", false)] //[TestCase(1, "Funny", false)] public void CanEditTags(int tagId, string tagName, bool success) { Tags tag = new Tags() { TagId = tagId, TagName = tagName }; TResponse <Tags> tags = manager.EditTag(tag); Assert.AreEqual(tags.Success, success); // Cannot be the same?? }
/// <summary> /// Invokes Business Logic's method by name /// </summary> /// <typeparam name="TResponse">Method responese</typeparam> /// <param name="methodArgs">Parameters's method</param> /// <returns>Response's method</returns> public async Task <BaseServicesResult> Execute <TResponse>(params object[] methodArgs) where TResponse : BaseResponse, new() { // Init base request data BaseRequest request = ToRequest <BaseRequest>(); // Init business logic and action meta data BusinessLogic = StartupExtensions.Resolve <TBusiness>(); // Init Meta data MetaData = new BaseActionMetaData <TBusiness>(this); // TODO: Create context and using all system Context = Context; // Custom init from action Init(); // Init action utilities and logger var statusUtility = new ActionStatusUtility(request); var actionUtility = new ActionExecutionUtility(request); // TODO: Start to write log // Init default response object (equal NULL) TResponse response; if (Validate()) { response = await OnExecute <TResponse>(methodArgs); } else { response = new TResponse { Errors = actionUtility.GetErrors(ValidateResult), Success = false }; } // Build and return service message var serviceResult = new BaseServicesResult { ReturnCode = statusUtility.GetStatusCode(response), ReturnData = new BaseResponseHttpActionResult <TResponse>() { Result = response, InternalCode = (int)statusUtility.GetInternalCode(response) } }; return(serviceResult); }
public async Task <object> Transform(object context, TResponse self) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (self == null) { throw new ArgumentNullException(nameof(self)); } return(await transformDelegate.Invoke((ExecutionResponseTransformContext <TContext>) context, self) .ConfigureAwait(false)); }
private async Task <TResponse> OnExecute <TResponse>(params object[] methodArgs) where TResponse : BaseResponse, new() { TResponse response = default(TResponse); //get medthod name string methodName = string.Empty; string nameAction = this.GetType().Name; if (!string.IsNullOrEmpty(nameAction)) { methodName = nameAction.Substring(0, nameAction.Length - 6); } MethodBase method = _businessLogicType.GetMethod(methodName); try { dynamic awaitable = method.Invoke(_businessLogic, methodArgs); await awaitable; response = (TResponse)awaitable.GetAwaiter().GetResult(); } catch (Exception ex) { //Need to consider whether we need to throw the App_Err response = new TResponse() { Success = false, Errors = new ServiceErrors() { new ServiceError() { ErrorCode = HttpStatusCode.InternalServerError.ToString(), MessageId = "DFO", FieldName = "DFOF1", Message = ex.InnerException.ToString() } } }; //Log the ex.... } finally { //Do something } return(response); }
public TResponse Receive() { byte[] data; int len = Receive(out data); if (len == -1) { return(null); } TResponse response = new TResponse(); response.Process(data); return(response); }
public ActionResult AddReview() { //get manager _categoryManager = CategoryManagerFactory.Create(); //create model var model = new ReviewVM(); TResponse <List <Categories> > response = _categoryManager.GetCategoryList(); //set categories model.SetCategoryListItems(response.Payload); return(View(model)); }
public ActionResult AddReview(ReviewVM newReview) { _tagsManager = TagsManagerFactory.Create(); _reviewManager = ReviewManagerFactory.Create(); _categoryManager = CategoryManagerFactory.Create(); if (ModelState.IsValid) { try { if (User.IsInRole("Admin")) { newReview.Review.IsApproved = true; newReview.Review.UserId = User.Identity.GetUserId(); } //set dates newReview.Review.DateCreated = DateTime.Now; //send review to manager _reviewManager.AddReview(newReview.Review); if (newReview.NewTags != null) { //create array of tags from tags input string[] tags = newReview.NewTags.Split(','); //send tags to tag manager TResponse <List <Tags> > tagList = _tagsManager.AddListOfTags(tags); //add tags to review _reviewManager.AddTagsToReview(newReview.Review.ReviewId, tagList.Payload); } return(RedirectToAction("Reviews")); } catch (Exception ex) { throw new ApplicationException("Something wrong happened while adding a review:", ex); } } else { //reset view TResponse <List <Categories> > response = _categoryManager.GetCategoryList(); newReview.SetCategoryListItems(response.Payload); return(View(newReview)); } }
IMapper <TViewModel, TRequest, TResponse> IMapperFactory.CreateMapper <TViewModel, TRequest, TResponse>() { Type[] typeList = GetTypesInNamespace(Assembly.GetExecutingAssembly(), "WeatherApp.ServiceLayerInteractions.Mappers"); for (int i = 0; i < typeList.Length; i++) { if (typeof(IMapper <TViewModel, TRequest, TResponse>).IsAssignableFrom(typeList[i])) { return(CreateMapper <TViewModel, TRequest, TResponse>(typeList[i])); } } TRequest req = Activator.CreateInstance <TRequest>(); TResponse res = Activator.CreateInstance <TResponse>(); TViewModel vm = Activator.CreateInstance <TViewModel>(); throw new Exception("mapper not found by MapperFactory for request type: " + req.GetType()); }
public ActionResult EditReview(ReviewVM model) { _tagsManager = TagsManagerFactory.Create(); _reviewManager = ReviewManagerFactory.Create(); _categoryManager = CategoryManagerFactory.Create(); if (ModelState.IsValid) { try { //set dates model.Review.DateCreated = DateTime.Now; //send review to manager _reviewManager.EditReview(model.Review); if (model.NewTags != null) { //create array of tags from tags input string[] tags = model.NewTags.Split(','); //send tags to tag manager TResponse <List <Tags> > tagList = _tagsManager.AddListOfTags(tags); //add tags to review _reviewManager.AddTagsToReview(model.Review.ReviewId, tagList.Payload); } return(RedirectToAction("Index")); } catch (Exception ex) { //catch an exception and add throw new ApplicationException("Something wrong happened while adding a review:", ex); } } else { //reset view var tagsResponse = _tagsManager.GetTagByReviewId(model.Review.ReviewId); model.TagList = tagsResponse.Payload; TResponse <List <Categories> > response = _categoryManager.GetCategoryList(); model.SetCategoryListItems(response.Payload); return(View(model)); } }
//add public TResponse <List <Tags> > AddListOfTags(string[] tags) { TResponse <List <Tags> > response = new TResponse <List <Tags> >(); if (tags.Any()) { List <string> newTags = new List <string>(); for (int i = 0; i < tags.Length; i++) { if (!string.IsNullOrEmpty(tags[i])) { newTags.Add(tags[i]); } } if (newTags.Any()) { response.Payload = Repo.AddListOfTags(newTags); if (response.Payload == null) { response.Success = false; response.Message = "Failed to add tags"; } else if (response.Payload.Count() != newTags.Count()) { response.Success = false; response.Message = "Failed to add all tags"; } else { response.Success = true; } } else { response.Success = false; response.Message = "Tags submitted were invalid"; } } else { response.Success = true; response.Message = "No tags submitted"; } return(response); }
//edit public TResponse <Reviews> EditReview(Reviews review) { TResponse <Reviews> response = new TResponse <Reviews>(); if (review == null) { response.Success = false; response.Message = $"Review is null"; } else { //send review to be edited Repo.EditReview(review); //get the review that was just edited var verifyReview = Repo.GetReviewById(review.ReviewId); bool reviewEdited = false; //verify the review is edited if (review.CategoryId == verifyReview.CategoryId && review.DateCreated == verifyReview.DateCreated && review.DatePublished == verifyReview.DatePublished && review.DownVotes == verifyReview.DownVotes && review.Rating == verifyReview.Rating && review.ReviewBody == verifyReview.ReviewBody && review.ReviewId == verifyReview.ReviewId && review.ReviewTitle == verifyReview.ReviewTitle && review.UpVotes == verifyReview.UpVotes) { reviewEdited = true; } //editing was unsuccessful if (!reviewEdited) { response.Success = false; response.Message = $"Review edited unsuccessfully. Review Id: {review.ReviewId}"; } else { response.Success = true; } } return(response); }
public ActionResult Add(int id = 0) { objTResponse = new CustomerLocationBusiness().GetByID(id); TResponse objTResponse_ = new UserProfileBusiness().GetAllUserByType("Customer"); ViewBag.CustomerList = (objTResponse_.ResponsePacket as List <UserProfileModel>).Select(c => new SelectListItem { Text = c.FName + " " + c.LName, Value = c.UserId.ToString(), Selected = (c.UserId == (id == 0?0:(objTResponse.ResponsePacket as CustomerLocationModel).CustomerID)) }).ToList(); return(View(objTResponse.ResponsePacket)); }
//get by tag public TResponse <List <Reviews> > GetReviewByTagId(int id) { var response = new TResponse <List <Reviews> >(); response.Payload = Repo.GetReviewsByTag(id); if (!response.Payload.Any()) { response.Success = false; response.Message = $"Unable to load reviews for tag id:{id}"; } else { response.Success = true; } return(response); }
public TResponse <Special> SaveSpecial(Special special) { var response = new TResponse <Special>(); response.Payload = Repo.Save(special); if (response.Payload == null) { response.Success = false; response.Message = "Special unsuccessfully added"; } else { response.Success = true; } return(response); }
public TResponse <List <ExteriorColor> > GetAll() { var response = new TResponse <List <ExteriorColor> >(); response.Payload = Repo.GetAll(); if (!response.Payload.Any()) { response.Message = "Could not load any exterior colors"; response.Success = false; } else { response.Success = true; } return(response); }
public TResponse <List <Categories> > GetAllCategories() { var response = new TResponse <List <Categories> >(); response.Payload = Repo.GetAllCategories(); if (response.Payload == null) { response.Success = false; response.Message = "Could not retrieve categories."; } else { response.Success = true; } return(response); }