public void TestWriteScopeResourcesWithRegistedFullScope(Enums.ResourceType resourceType, ApplicationType appType) { InitFullScopeAdapter(appType); XmlResource resource = CreateResourceInstance(resourceType); string id = adapter.WriteSuccess(resource, cleaner.Delete); Assert.That(id, Is.Not.Null.And.Not.Empty, string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, resourceType)); }
public void TestReadAttachmentFieldTypeImageFailure() { ////////////////////////////////////////////////////////////////////////////////////////////// // HRBC Custom Field: Manual Setup (REQUIRED) // + Login to HRBC using the same account that is going to be used for Executing this Test // + Click on "Preferences" button at the right/up section of HRBC UI // + Click on submenu "Customize" // + Click on Screens - Client - Detailed View & Items // + On the right section, press the "new" button // + Create new Item type "Image" // + Use "Preview" as the "Name" field // + Use "This is a Image type" as the "Annotation" field // + Press the "Save" button // + Press the edit button of the new Item "Preview" // + Use the value associated to "Alias" field for variable "string customFieldName" // E.G. Client.U_90C7A8052BD83DC1427A361B120007 (This is the alias for the new Image Type Item) // + Enable new Item by dragging it into the "Basic Information" section // + Press the "Save Layout" button // Generating Image Index int imgIndex = Util.GetRandomNumber(); // Formatting Attachment & Image Type Files Name string imgAttachmentName = string.Format("imageAttachment_{0}.jpeg", imgIndex); string imgPreviewName = string.Format("imagePreview_{0}.jpeg", imgIndex); // Create Image for Field //Image imgPreview = Util.CreateImage(10, 5, Color.Orange); //string str64Preview = Util.ImageToBase64String(imgPreview); string str64Preview = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAFAAoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDraKKK/KD7Q//Z"; string customFieldName = TestConfig.GetValueFromConfig("Client_ImageType"); Client client = new Client(); client.Id = "-1"; client.Name = string.Format("Client_With_Image_Type_Field_{0}", imgIndex); client.Owner = "1"; Attachment customField = new Attachment(); customField.FileName = imgPreviewName; customField.ContentType = Enums.ContentType.Jpeg; customField.Content = str64Preview; client.DictionaryValues[customFieldName] = customField; string clientId = PublicApiAdapter.CreateAdapterForDefaultConnection().WriteSuccess(client, null); Assume.That(!string.IsNullOrEmpty(clientId), "Unable to created New Client using custom field (Image Type)"); string sublistFlagField = "sublist_flg"; string queryTemplate = "SELECT {0} FROM files WHERE file_name = '{1}'"; //if (!PublicAPIConfig.ServerURL.Contains("porterscloud.com")) //{ // // Database Verification (MySQL) // MySQLHandler mySqlHandler = new MySQLHandler() // { // User = TestConfig.GetValueFromConfig("MySQL_User"), // Password = TestConfig.GetValueFromConfig("MySQL_Password"), // Server = TestConfig.GetValueFromConfig("MySQL_Server"), // Port = TestConfig.GetValueFromConfig("MySQL_Port"), // Database = "PRC" + TestConfig.GetValueFromConfig("Partition") // }; // string query = string.Format(queryTemplate, sublistFlagField, imgPreviewName); // List<Dictionary<string, object>> rows = mySqlHandler.ExecuteReaderQuery(query); // Assume.That(rows.Count > 0, string.Format("Unable to retrieve Image Type Field from MySQL Database, Query: {0}{1}", System.Environment.NewLine, query)); // Assume.That(rows[0].ContainsKey(sublistFlagField), string.Format("Unable to retrieve field {0}", sublistFlagField)); // Assert.AreEqual(0, rows[0][sublistFlagField], string.Format("Sublist Flag for Image Type {0} does not matches the expected value.", imgPreviewName)); //} ////////////////////////////////////////////////////////////////////////////////////////////// // ATTACHMENT CREATION // Create Image for Attachment //Image imgAttachment = Util.CreateImage(10, 5, Color.Pink); //string str64Attachment = Util.ImageToBase64String(imgAttachment); string str64Attachment = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAFAAoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD1Siiisz3D/9k="; // Setup Parameters for Attachment Create Request int clientResource = (int)Enums.ResourceType.Client; Attachment attachment = new Attachment(); attachment.Id = "-1"; attachment.Resource = clientResource.ToString(); attachment.ResourceId = clientId; attachment.FileName = imgAttachmentName; attachment.ContentType = Enums.ContentType.Jpeg; attachment.Content = str64Attachment; // Create New Attachment string attachmentId = publicApiAdapter.WriteSuccess(attachment, null); Assume.That(!string.IsNullOrEmpty(attachmentId), string.Format("Unable to create New Attachment for Client Id: {0}", clientId)); //if (!PublicAPIConfig.ServerURL.Contains("porterscloud.com")) //{ // // Database Verification (MySQL) // string query = string.Format(queryTemplate, sublistFlagField, imgAttachmentName); // MySQLHandler mySqlHandler = new MySQLHandler() // { // User = TestConfig.GetValueFromConfig("MySQL_User"), // Password = TestConfig.GetValueFromConfig("MySQL_Password"), // Server = TestConfig.GetValueFromConfig("MySQL_Server"), // Port = TestConfig.GetValueFromConfig("MySQL_Port"), // Database = "PRC" + TestConfig.GetValueFromConfig("Partition") // }; // List<Dictionary<string, object>> rows = mySqlHandler.ExecuteReaderQuery(query); // Assume.That(rows.Count > 0); // Assume.That(rows[0].ContainsKey(sublistFlagField)); // Assume.That((int)rows[0][sublistFlagField] == 1); //} ////////////////////////////////////////////////////////////////////////////////////////////// // ATTACHMENT READ Dictionary <string, object> parameters = new Dictionary <string, object>() { { Parttion, AuthenticationInfoProvider.Current.DefaultPartition }, { "requestType", "1" }, { "resource", clientResource.ToString() }, { "resourceId", clientId } }; ReadResponseData <Attachment> list = publicApiAdapter.ReadSuccess <Attachment>(parameters); Assume.That(null != list, string.Format("Unable to retrieve Attachment Id: {0} associated to Client Id: {1} using Attachment API", attachmentId, clientId)); Assert.AreEqual(1, list.Count, string.Format("Only Attachment Id: {0} associated to Client Id: {1} should be retrieved (Attachments found: {2})", attachmentId, clientId, list.Count)); Attachment attachmentRead = list.Items[0]; // Getting Attachment information Assert.NotNull(attachmentRead.Id, "Unable to retrieve <Id>"); Assert.NotNull(attachmentRead.Resource, "Unable to retrieve node <Resource>"); Assert.NotNull(attachmentRead.ResourceId, "Unable to retrieve node <ResourceId>"); Assert.NotNull(attachmentRead.ContentType, "Unable to retrieve node <ContentType>"); Assert.NotNull(attachmentRead.FileName, "Unable to retrieve node <FileName>"); // Verify Attachment retrieved from Read Request matches the correct Attachment file Assert.AreEqual(attachmentId, attachmentRead.Id.ToString(), "Retrieved Attachment file does not match expected Attachment Id"); Assert.AreEqual(clientResource.ToString(), attachmentRead.Resource.ToString(), "Retrieved Attachment file does not match expected Resource"); Assert.AreEqual(clientId, attachmentRead.ResourceId.ToString(), "Retrieved Attachment file does not match expected Resource Id"); Assert.AreEqual(Enums.ContentType.Jpeg, attachmentRead.ContentType.ToString(), "Retrieved Attachment file does not match expected Content Type"); Assert.AreEqual(imgAttachmentName, attachmentRead.FileName.ToString(), "Retrieved Attachment file does not match expected Name"); }