public void GetLiveOfferAttributesTest() { var IOffersManager = new Mock<IOffersManager>(); OkNegotiatedContentResult<OfferAttributesResponse> response; OfferAttributesDataObject OfferAttributesData = new OfferAttributesDataObject() { Errors = new List<ErrorObject>(), Attributes = new List<OfferAttributeApiObject>() { new OfferAttributeApiObject() } }; IOffersManager.Setup(i => i.GetOfferAttributes(It.IsAny<HttpRequestMessage>(), It.IsAny<string>(), new Guid().ToString())).Returns(OfferAttributesData); controller = new InitController("Liveoffers").initLiveOffersController(IOffersManager.Object); response = controller.GetAttributes(new Guid().ToString()) as OkNegotiatedContentResult<OfferAttributesResponse>; Assert.NotNull(response.Content.Data.Attributes); Assert.NotEmpty(response.Content.Data.Attributes); Assert.Null(response.Content.Data.Errors); }
public void GetLiveOfferAttributesFailureTest() { var IOffersManager = new Mock<IOffersManager>(); OkNegotiatedContentResult<OfferAttributesResponse> response; OfferAttributesDataObject OfferAttributesData = new OfferAttributesDataObject() { Errors = new List<ErrorObject>() { new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL) }, Attributes = null }; IOffersManager.Setup(i => i.GetOfferAttributes(It.IsAny<HttpRequestMessage>(), It.IsAny<string>(), new Guid().ToString())).Returns(OfferAttributesData); controller = new InitController("Liveoffers").initLiveOffersController(IOffersManager.Object); response = controller.GetAttributes(new Guid().ToString()) as OkNegotiatedContentResult<OfferAttributesResponse>; Assert.Null(response.Content.Data.Attributes); Assert.NotNull(response.Content.Data.Errors); Assert.True(response.Content.Data.Errors.Exists(i => i.Code == 3000)); }
public OfferAttributesResponse(string RequestId, bool status = false) { this.Status = status; this.Data = new OfferAttributesDataObject(); this.Meta = new MetaDataObject(RequestId); }
/// <summary> /// Function that will return the attributes of a given offer based on the request (Liveoffer or Testoffer) /// </summary> /// <param name="Request"></param> /// <param name="ApiUser"></param> /// <param name="offerId"></param> /// <returns></returns> public OfferAttributesDataObject GetOfferAttributes(HttpRequestMessage Request, string ApiUser, string offerId) { LoggingUtility log = LoggerFactory.GetLogger(); OfferAttributesDataObject data = new OfferAttributesDataObject(); String requestId = Request.Properties["requestId"].ToString(); Dictionary<string, string> parameters = new Dictionary<string, string>(); OfferFilter OfferType = GetOfferType(Request.GetRouteData().Values["controller"].ToString()); OfferObject offerObj = null; List<OfferAttributeApiObject> offerAttributesList = null; string OperationName = operationName.GetOffersAttributes.ToString(); parameters.Add("OfferId", offerId); log.ProcessingDebug(requestId, "Received GET Offer attributes request."); try { var oid = new Guid(); Guid.TryParse(offerId, out oid); offerObj = OfferRepository().SelectByID(oid); if (offerObj == null || offerObj.Status != (int)OfferStatus.Active) { //Filling the error object in the response envelope with the Error object //Edit for R184 data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_INVALID_OFFER_ARGUMENT, parameters)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_INVALID_OFFER_ARGUMENT, parameters)); } else { log.ProcessingDebug(requestId, "Getting Offer attributes from database."); // Check if the request type and the offer type match if ((OfferType.Equals(OfferFilter.LiveOffer) && !(bool)offerObj.TestOffer) || (OfferType.Equals(OfferFilter.TestOffer) && (bool)offerObj.TestOffer)) { offerAttributesList = OfferAttributeRepository().GetOfferAttributes(offerObj.Id).ToList(); if (offerAttributesList != null && offerAttributesList.Count() > 0) { //Filling the data object in the response envelope with the list of respondent attributes data.Attributes = offerAttributesList; } else { //Filling the error object in the response envelope with the Error object //Edit for R184 data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_OFFER_HAS_NO_PUBLISHED_ATTRIBUTES, parameters)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_OFFER_HAS_NO_PUBLISHED_ATTRIBUTES, parameters)); } } else { // The request type and offer type don't match (provider is either asking testoffers api for a LIVE offer attributes or vice versa data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_INVALID_OFFER_ARGUMENT, parameters)); } //Check if there are respondent attribute appended to the offer } } catch (Exception e) { //Edit for R184 data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); log.InfoJson(new Methods().Exception_ToLogObject(requestId, ApiUser, OperationType, OperationName, e)); } finally { if (data.Errors.Count != 0) { log.InfoJson(new Methods().Error_ToLogObject(requestId, ApiUser, OperationType, OperationName, parameters, data.Errors)); log.ProcessingDebug(requestId, "GET Offer attributes request was unsuccessful."); } //The response has no errors, we insert a request successful message into the logs else { log.InfoJson(new Methods().Response_ToLogObject(requestId, ApiUser, OperationType, OperationName, parameters, data)); log.ProcessingDebug(requestId, "GET Offer attributes request was successful."); } } return data; }