Exemplo n.º 1
0
        public void FeedbackReceived()
        {
            JsonServiceStub stub = new JsonServiceStub(@"{
					""Timestamp"":""2014-08-21T04:05:18.408Z"",
					""Ack"":""Success"",
					""Build"":""E847_CORE_APINOT_16496971_R1"",
					""Version"":""847"",
					""ClientAlerts"":
					{
						""ClientAlertEvent"":[
						{
							""EventType"":""FeedbackReceived"",
							""FeedbackReceived"":
							{
								""EventType"":""FeedbackReceived"",
								""Timestamp"":""2014-08-21T04:01:23.579Z"",
								""FeedbackDetail"":
								{
									""CommentingUser"":""cooch07"",
									""CommentText"":""Thank You"",
									""CommentType"":""Positive"",
									""ItemID"":""121272962371"",
									""Role"":""Buyer"",
									""ItemTitle"":""VON ZIPPER Boys HOWLING T Shirt Top (10 12) NEW *Billabong Co."",
									""ItemPrice"":
									{
										""Value"":19.95,
										""CurrencyID"":""AUD""
									},
									""FeedbackID"":""929232133022"",
									""TransactionID"":""1336041473002"",
									""FeedbackScore"":50540
								}
							}
						}]
					},
					""SessionData"":""AQAAAUf13OQAAA1TSUQ9NDA1MTI2M3xTVD0xfDF8TEFDVFY9MTQwODU5MzkxODM5M3xFSFdNPTE4MDUwNzc4NTMzfFRJRFg9MXxMSVVQPTE0MDg1OTMyNjE5MjJ8UExIUz1bXea4wEEeBR+lvVNEOtRmM9Gnk4Ei""
					}"                    );

            GetUserAlertsCall call = new GetUserAlertsCall(this.Logger, stub);

            call.Execute();

            Assert.IsNotNull(call.ApiResponse.ClientAlerts);
            Assert.IsNotNull(call.ApiResponse.ClientAlerts.ClientAlertEvent);
            Assert.AreEqual(ClientAlertsEventTypeCodeType.FeedbackReceived, call.ApiResponse.ClientAlerts.ClientAlertEvent[0].EventType);
            Assert.AreEqual(1, call.ApiResponse.ClientAlerts.ClientAlertEvent.Length);
            Assert.IsInstanceOfType(call.ApiResponse.ClientAlerts.ClientAlertEvent[0], typeof(FeedbackReceivedEventType));

            FeedbackReceivedEventType eventType = (FeedbackReceivedEventType)call.ApiResponse.ClientAlerts.ClientAlertEvent[0];

            Assert.AreEqual(ClientAlertsEventTypeCodeType.FeedbackReceived, eventType.EventType);
            Assert.AreEqual(new DateTime(2014, 08, 21, 4, 1, 23, 579, DateTimeKind.Utc), eventType.Timestamp);

            Assert.IsNotNull(eventType.FeedbackDetail);
            FeedbackDetailType feedbackDetail = eventType.FeedbackDetail;

            Assert.AreEqual("cooch07", feedbackDetail.CommentingUser);
            Assert.AreEqual("Thank You", feedbackDetail.CommentText);
            Assert.AreEqual(CommentTypeCodeType.Positive, feedbackDetail.CommentType);
            Assert.AreEqual("121272962371", feedbackDetail.ItemID);
            Assert.AreEqual(TradingRoleCodeType.Buyer, feedbackDetail.Role);
            Assert.AreEqual("VON ZIPPER Boys HOWLING T Shirt Top (10 12) NEW *Billabong Co.", feedbackDetail.ItemTitle);
            Assert.IsNotNull(feedbackDetail.ItemPrice);
            Assert.AreEqual(19.95, feedbackDetail.ItemPrice.Value);
            Assert.AreEqual("AUD", feedbackDetail.ItemPrice.CurrencyID);
            Assert.AreEqual("929232133022", feedbackDetail.FeedbackID);
            Assert.AreEqual("1336041473002", feedbackDetail.TransactionID);
            Assert.AreEqual(50540, feedbackDetail.FeedbackScore);
        }
Exemplo n.º 2
0
        public AlertBase PopulateAlert(Account account, ClientAlertEventType item)
        {
            if (item is FeedbackLeftEventType)
            {
                return(null);                // Feedback received alerts are kind of worthless
            }
            if (item is ItemMarkedPaidEventType && ((ItemMarkedPaidEventType)item).SellerUserID == account.UserId)
            {
                return(null);                // Not interested in alerts informing us we have marked the item as paid.
            }
            // Feedback Received
            if (item is FeedbackReceivedEventType)
            {
                FeedbackReceivedEventType eventType = (FeedbackReceivedEventType)item;
                FeedbackReceivedAlert     alert     = new FeedbackReceivedAlert();

                alert.Account        = account;
                alert.CommentingUser = new User(account.Site, eventType.FeedbackDetail.CommentingUser, eventType.FeedbackDetail.FeedbackScore);
                alert.Item           = new Item(account.Site, eventType.FeedbackDetail.ItemID, eventType.FeedbackDetail.ItemTitle, eventType.FeedbackDetail.ItemPrice);
                alert.CommentText    = eventType.FeedbackDetail.CommentText;
                alert.CommentType    = eventType.FeedbackDetail.CommentType;

                return(alert);
            }             // AskSellerQuestion
            else if (item is AskSellerQuestionEventType)
            {
                AskSellerQuestionEventType eventType = (AskSellerQuestionEventType)item;
                MessageAlert alert = new MessageAlert();

                // Extract some more details from eBay
                {
                    EbayContext       context         = new EbayContext(account.EbayToken);
                    GetMemberMessages getMessagesCall = new GetMemberMessages(context);
                    getMessagesCall.MessageId = eventType.MessageID;

                    getMessagesCall.Execute();
                    MemberMessageExchangeType messageType = getMessagesCall.Message;

                    alert.Account = account;
                    alert.Sender  = new User(account.Site, messageType.Question.SenderID);
                    alert.Subject = messageType.Question.Subject;
                    alert.Body    = messageType.Question.Body.Replace("'", "'");
                    alert.Item    = new Item(account.Site, messageType.Item.ItemID, messageType.Item.Title);

                    foreach (MessageMediaType mediaType in messageType.MessageMedia)
                    {
                        PictureDownloader downloader = new PictureDownloader();
                        Bitmap            bitmap     = downloader.DownloadImage(mediaType.MediaURL);
                        Media             media      = new Media(bitmap, mediaType.MediaURL);
                        alert.MediaList.Add(media);
                    }
                }

                return(alert);
            }
            else if (item is EndOfTransactionEventType && item.EventType == ClientAlertsEventTypeCodeType.FixedPriceTransaction)
            {
                EndOfTransactionEventType eventType = (EndOfTransactionEventType)item;
                ItemSoldAlert             alert     = new ItemSoldAlert();

                alert.TransactionId = eventType.Transaction.TransactionID;
                alert.Account       = account;
                alert.Item          = new Item(account.Site, eventType.ItemID, eventType.Title, eventType.CurrentPrice);
                alert.Buyer         = new User(account.Site, eventType.Transaction.BuyerUserID);
                alert.AmountPaid    = eventType.Transaction.AmountPaid;
                alert.QuantitySold  = eventType.Transaction.QuantitySold;

                if (!String.IsNullOrEmpty(eventType.GalleryURL))
                {
                    PictureDownloader downloader = new PictureDownloader();
                    Bitmap            bitmap     = downloader.DownloadImage(eventType.GalleryURL);
                    Media             media      = new Media(bitmap, eventType.GalleryURL);
                    alert.Item.Media = media;
                }

                return(alert);
            }

            return(null);
        }