Exemple #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetAttachmentResponse response = new GetAttachmentResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Url", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Url = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("UrlExpiry", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.UrlExpiry = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public void MSASCMD_S06_TC01_GetAttachment_Success()
        {
            Site.Assume.AreNotEqual <string>("14.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual <string>("14.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual <string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 16.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Send a mail with normal attachment
            string subject = Common.GenerateResourceName(Site, "NormalAttachment_Subject");
            string body    = Common.GenerateResourceName(Site, "NormalAttachment_Body");
            this.SendEmailWithAttachment(subject, body);
            #endregion

            this.SwitchUser(this.User2Information);
            SyncResponse syncResponse = this.GetMailItem(this.User2Information.InboxCollectionId, subject);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, subject);

            Response.AttachmentsAttachment[] attachments = this.GetEmailAttachments(syncResponse, subject);
            Site.Assert.IsTrue(attachments != null && attachments.Length == 1, "The email should contain a single attachment.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5501");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5501
            // The attachment name in the sent email is "number1.jpg", so if there is only one attachment in the email and the attachment name is matched, this requirement can be covered.
            Site.CaptureRequirementIfAreEqual <string>(
                "number1.jpg",
                attachments[0].DisplayName,
                5501,
                @"[In GetAttachment] Instead, an Attachment element ([MS-ASAIRS] section 2.2.2.2) is included for each attachment.");

            #region Call GetAttachment command to fetch attachment
            string attachmentFileReference = attachments[0].FileReference;
            IDictionary <CmdParameterName, object> parameters = new Dictionary <CmdParameterName, object>();
            parameters.Add(CmdParameterName.AttachmentName, attachmentFileReference);

            GetAttachmentRequest request = new GetAttachmentRequest();
            request.SetCommandParameters(parameters);
            GetAttachmentResponse response = this.CMDAdapter.GetAttachment(request);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R157");

            // Verify MS-ASCMD requirement: MS-ASCMD_R157
            // The GetAttachment command response data xml only contains the size information of the attachment, if it is not null and includes the size information, this requirement can be covered.
            bool isVerifyR157 = !string.IsNullOrEmpty(response.ResponseDataXML) && Convert.ToInt32(response.ResponseDataXML) > 0;
            Site.CaptureRequirementIfIsTrue(
                isVerifyR157,
                157,
                @"[In GetAttachment] The GetAttachment command retrieves an email attachment from the server.<2>");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R160");

            // Verify MS-ASCMD requirement: MS-ASCMD_R160
            // In ExchangeCommonConfiguration.deployment.ptfconfig, HTTP/HTTPS has been specified, so GetAttachment command is issued within the HTTP POST command.
            Site.CaptureRequirement(
                160,
                @"[In GetAttachment] This command [GetAttachment] is issued within the HTTP POST command.");
            #endregion
        }
        /// <summary>
        /// Retrieves an e-mail attachment from the server.
        /// </summary>
        /// <param name="request">A GetAttachmentRequest object that contains the request information.</param>
        /// <returns>GetAttachment command response</returns>
        public GetAttachmentResponse GetAttachment(GetAttachmentRequest request)
        {
            GetAttachmentResponse response = this.activeSyncClient.GetAttachment(request);

            this.VerifyTransportRequirements();
            this.VerifyWBXMLCapture(CommandName.GetAttachment, response);
            return(response);
        }
        private Dictionary <Guid, Attachment> ParseDoucmentApiResponse(GetAttachmentResponse response)
        {
            var documentIds = new Dictionary <Guid, Attachment>();

            foreach (var attachment in response.SuccessResponse)
            {
                documentIds.Add(EncompassHelper.GetGuid(attachment.AttachmentId), attachment);
            }
            return(documentIds);
        }
        public Attachment CreateTicketAttachment(Ticket ParentTicket, Resource ImpersonateResource, string Title, byte[] Data, string Publish)
        {
            Attachment _result = null;

            if (string.IsNullOrWhiteSpace(Title))
            {
                Title = "No Name";
            }
            if (ParentTicket == null || (Data == null || Data.Length <= 0 || Data.Length > 6000000) || string.IsNullOrWhiteSpace(Publish))
            {
                throw new ArgumentNullException();
            }

            try
            {
                _result = new Attachment()
                {
                    //ParentTypes = /Account(1), Ticket(3), or Project(4).
                    Info = new AttachmentInfo()
                    {
                        Type       = "FILE_ATTACHMENT",
                        ParentType = 4,
                        ParentID   = ParentTicket.id,
                        FullPath   = Title.Substring(0, Title.Length > 255 ? 255 : Title.Length),
                        Title      = Title.Substring(0, Title.Length > 255 ? 255 : Title.Length),
                        Publish    = Convert.ToInt32(PickListValueFromField(attachmentInfo_fieldInfo.GetFieldInfoResult, "Publish", Publish)),
                    },
                    Data = Data
                };
            }
            catch (Exception _ex)
            {
                _result = null;
                throw new ArgumentException("Unable to build ticket attachment request. Please review InnerException.", _ex);
            }
            try
            {
                if (_result != null)
                {
                    _atwsIntegrations.ImpersonateAsResourceID          = ImpersonateResource != null ? (int)ImpersonateResource.id : 0;
                    _atwsIntegrations.ImpersonateAsResourceIDSpecified = _atwsIntegrations.ImpersonateAsResourceID == 0 ? false : true;
                    CreateAttachmentResponse _createResponse = _atwsServicesClient.CreateAttachment(new CreateAttachmentRequest(_atwsIntegrations, _result));
                    _atwsIntegrations.ImpersonateAsResourceID          = 0;
                    _atwsIntegrations.ImpersonateAsResourceIDSpecified = false;
                    if (_createResponse.CreateAttachmentResult > 0)
                    {
                        GetAttachmentResponse _getResponse = _atwsServicesClient.GetAttachment(new GetAttachmentRequest(_atwsIntegrations, _createResponse.CreateAttachmentResult));
                        if (_getResponse.GetAttachmentResult != null)
                        {
                            _result = _getResponse.GetAttachmentResult;
                        }
                        else
                        {
                            throw new CommunicationException("AutotaskAPIClient.CreateTickeAttachment() UNKNOWN ERROR");
                        }
                    }
                }
            }
            catch (Exception _ex)
            {
                _result = null;
                throw new CommunicationException("Unable to create ticket attachment. Please review InnerException.", _ex);
            }
            return(_result);
        }
        public void MSASCMD_S06_TC02_GetAttachment_Status500()
        {
            Site.Assume.AreNotEqual <string>("14.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual <string>("14.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual <string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 16.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            // Send a mail with normal attachment
            string subject = Common.GenerateResourceName(Site, "NormalAttachment_Subject");
            string body    = Common.GenerateResourceName(Site, "NormalAttachment_Body");

            this.SendEmailWithAttachment(subject, body);

            this.SwitchUser(this.User2Information);
            SyncResponse syncResponse = this.CheckEmail(this.User2Information.InboxCollectionId, subject, null);

            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, subject);

            Response.AttachmentsAttachment[] attachments = this.GetEmailAttachments(syncResponse, subject);
            Site.Assert.IsTrue(attachments != null && attachments.Length == 1, "The email should contain a single attachment.");

            GetAttachmentRequest getAttachmentRequest = new GetAttachmentRequest();

            getAttachmentRequest.SetCommandParameters(new Dictionary <CmdParameterName, object>
            {
                {
                    CmdParameterName.AttachmentName, attachments[0].FileReference
                }
            });

            GetAttachmentResponse getAttachmentResponse = this.CMDAdapter.GetAttachment(getAttachmentRequest);

            Site.Assert.AreEqual <string>("OK", getAttachmentResponse.StatusDescription, "The attachment should be retrieved successfully.");

            // Delete the email in the Inbox folder.
            syncResponse = this.SyncChanges(this.User2Information.InboxCollectionId);

            string      serverId    = TestSuiteBase.FindServerId(syncResponse, "Subject", subject);
            SyncRequest syncRequest = TestSuiteBase.CreateSyncDeleteRequest(this.LastSyncKey, this.User2Information.InboxCollectionId, serverId);

            this.Sync(syncRequest);

            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", subject), "The email should be deleted.");
            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, subject);

            syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNotNull(TestSuiteBase.FindServerId(syncResponse, "Subject", subject), "The deleted email should be in the DeletedItems folder.");
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.DeletedItemsCollectionId, subject);

            try
            {
                // Call GetAttachment command again to fetch the deleted attachment.
                this.CMDAdapter.GetAttachment(getAttachmentRequest);
                Site.Assert.Fail("If the GetAttachment command is used to retrieve an attachment that has been deleted on the server, a 500 status code should be returned in the HTTP POST response.");
            }
            catch (System.Net.WebException exception)
            {
                int statusCode = ((System.Net.HttpWebResponse)exception.Response).StatusCode.GetHashCode();

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R166");

                // Verify MS-ASCMD requirement: MS-ASCMD_R166
                Site.CaptureRequirementIfAreEqual <int>(
                    500,
                    statusCode,
                    166,
                    @"[In GetAttachment] If the GetAttachment command is used to retrieve an attachment that has been deleted on the server, a 500 status code is returned in the HTTP POST response.");
            }
        }