Exemple #1
0
        public void TableRecord_CreateByDictionaryAndDelete_Success()
        {
            var title   = "Table Record by Dict - " + DateTime.Now.ToShortDateString();
            var dueDate = DateTime.Now.AddDays(10).Date;

            // Create

            var dict       = testConfig.GetDefaultActivityArguments();
            var dictValues = customFieldsTable.GenerateRandomRecordDictionary();

            dict["TableID"]          = customFieldsTable.Id;
            dict["Title"]            = title;
            dict["DueDate"]          = dueDate;
            dict["DictionaryFields"] = dictValues;

            var act = new CreateTableRecord();

            var result = WorkflowInvoker.Invoke(act, dict);

            Assert.IsTrue((bool)result["Success"]);
            var recordId = (long)result["TableRecordID"];

            Assert.IsTrue(recordId > 0);

            // Get

            dict = testConfig.GetDefaultActivityArguments();
            dict["TableRecordID"] = recordId;

            var act2 = new GetTableRecord();

            result = WorkflowInvoker.Invoke(act2, dict);
            Assert.IsTrue((bool)result["Success"]);
            var tableRecord = (JObject)result["TableRecord"];

            Assert.AreEqual(title, tableRecord.Value <string>("title"));
            Assert.AreEqual(dueDate, tableRecord.Value <DateTime>("due_date"));
            var fieldsDict = (Dictionary <string, object>)result["TableRecordFieldsDictionary"];

            var valuesJArray = tableRecord["record_fields"] as JArray;
            var valuesDict   = Helper.TableRecord.FieldsJArrayToJObjectDictionary(valuesJArray);

            Assert.AreEqual(dictValues["code"].ToString(), valuesDict["code"].Value <string>("value"));
            Assert.AreEqual(dictValues["description"], valuesDict["description"].Value <string>("value"));
            Assert.AreEqual(dictValues["code"].ToString(), fieldsDict["code"]);
            Assert.AreEqual(dictValues["description"], fieldsDict["description"]);

            // Delete

            dict = testConfig.GetDefaultActivityArguments();
            dict["TableRecordID"] = recordId;

            var act3 = new DeleteTableRecord();

            result = WorkflowInvoker.Invoke(act3, dict);
            Assert.IsTrue((bool)result["Success"]);
            Assert.AreEqual(act3.SuccessMessage, result["Status"].ToString());
        }
Exemple #2
0
        public void TableRecord_AvoidDictionaryAndDataRow_Exception()
        {
            var testConfig = TestConfiguration.Instance;
            var dict       = testConfig.GetDefaultActivityArguments();

            dict["TableID"]          = customFieldsTable.Id;
            dict["DictionaryFields"] = customFieldsTable.GenerateRandomRecordDictionary();
            dict["DataRowFields"]    = customFieldsTable.GenerateRandomRecordDataRow();
            var act = new CreateTableRecord();

            WorkflowInvoker.Invoke(act, dict);
        }
        public void UploadFile_TableRecordFileInfo_Success()
        {
            // Create

            var dict = testConfig.GetDefaultActivityArguments();

            dict["TableID"] = attachmentTable.Id;
            dict["Title"]   = "Upload TextFile Test Record";

            var act = new CreateTableRecord();

            var result = WorkflowInvoker.Invoke(act, dict);

            Assert.IsTrue((bool)result["Success"]);
            var recordId = (long)result["TableRecordID"];

            Assert.IsTrue(recordId > 0);

            // Upload file

            var fileInfo = new FileInfo("TestFiles/simple-text.txt");

            dict = testConfig.GetDefaultActivityArguments();
            dict["OrganizationID"] = testConfig.GetCustomConfig("OrganizationID");
            dict["FileInfo"]       = fileInfo;

            var act2 = new UploadAttachment();

            result = WorkflowInvoker.Invoke(act2, dict);
            var uploadedUrl = (string)result["FileUrl"];

            Assert.IsTrue((bool)result["Success"]);
            Assert.IsFalse(string.IsNullOrWhiteSpace(uploadedUrl));

            // Update TableRecord field

            dict = testConfig.GetDefaultActivityArguments();
            dict["TableRecordID"] = recordId;
            dict["FieldID"]       = "file";
            dict["Value"]         = new string[] { uploadedUrl };

            var act3 = new SetTableRecordFieldValue();

            result = WorkflowInvoker.Invoke(act3, dict);
            Assert.IsTrue((bool)result["Success"]);

            // Get

            dict = testConfig.GetDefaultActivityArguments();
            dict["TableRecordID"] = recordId;

            var act4 = new GetTableRecord();

            result = WorkflowInvoker.Invoke(act4, dict);
            Assert.IsTrue((bool)result["Success"]);

            var tableRecord  = (JObject)result["TableRecord"];
            var valuesJArray = tableRecord["record_fields"] as JArray;
            var valuesDict   = Helper.TableRecord.FieldsJArrayToJObjectDictionary(valuesJArray);

            Assert.AreEqual(uploadedUrl, valuesDict["file"]["array_value"].First.Value <string>());

            // Delete

            dict = testConfig.GetDefaultActivityArguments();
            dict["TableRecordID"] = recordId;

            var act5 = new DeleteTableRecord();

            result = WorkflowInvoker.Invoke(act5, dict);
            Assert.IsTrue((bool)result["Success"]);
            Assert.AreEqual(act5.SuccessMessage, result["Status"].ToString());
        }