public NewResourceResultContract CreateImageResource(CreateImageContract data, Stream dataStream) { try { var formData = FormDataBuilder.Create() .AddParameter(nameof(CreateImageContract.ImageId), data.ImageId) .AddParameter(nameof(CreateImageContract.OriginalVersionId), data.OriginalVersionId) .AddParameter(nameof(CreateImageContract.ResourcePageId), data.ResourcePageId) .AddParameter(nameof(CreateImageContract.Comment), data.Comment) .AddParameter(nameof(CreateImageContract.FileName), data.FileName) .ToResult(); var result = m_client.PostStreamAsForm <NewResourceResultContract>("project/image", dataStream, data.FileName, formData); return(result); } catch (HttpRequestException e) { if (m_logger.IsErrorEnabled()) { m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e); } throw; } }
public void FormDataBuilder_uses_CONTEXT_for_repeat_key_when_transaction_type_is_upsert() { var builder1 = new FormDataBuilder("FORMOID").WithTransactionType(Schema.TransactionType.Upsert); var builder2 = new FormDataBuilder("FORMOID", 5).WithTransactionType(Schema.TransactionType.Upsert); Assert.AreEqual("@CONTEXT", builder1.Build().FormRepeatKey); Assert.AreEqual("@CONTEXT", builder2.Build().FormRepeatKey); }
public void TestFormDataBuilderWithNullData() { Dictionary <string, string> outputDict = new Dictionary <string, string>(); FormDataBuilder.CreateFormData(null, ref outputDict, ""); Assert.Empty(outputDict); }
public void TestFormDataBuilder() { NestedClass nestedClass = new NestedClass(); nestedClass.NestedClass2 = new NestedClass2(); nestedClass.NestedClass2.Count = 123; TestClass @class = new TestClass( new Address("123 Xenost Street", "", "Moyun", "AZ", "USA", "85203"), "SomeoneName", "$35000", new Dictionary <string, string>() { { "key1", "value1" }, { "key2", "value2" } }, nestedClass ); Dictionary <string, string> outputDict = new Dictionary <string, string>(); FormDataBuilder.CreateFormData(@class, ref outputDict, ""); Assert.Equal(11, outputDict.Count); Assert.True(outputDict.ContainsKey("address[line1]")); Assert.True(outputDict.ContainsKey("address[line2]")); Assert.True(outputDict.ContainsKey("address[city]")); Assert.True(outputDict.ContainsKey("address[state]")); Assert.True(outputDict.ContainsKey("address[country]")); Assert.True(outputDict.ContainsKey("address[zip]")); Assert.True(outputDict.ContainsKey("name")); Assert.True(outputDict.ContainsKey("balance")); Assert.True(outputDict.ContainsKey("metadata[key1]")); Assert.True(outputDict.ContainsKey("metadata[key2]")); Assert.True(outputDict.ContainsKey("nested[nestedclass2[count]]")); Assert.Equal("123 Xenost Street", outputDict["address[line1]"]); Assert.Equal("", outputDict["address[line2]"]); Assert.Equal("Moyun", outputDict["address[city]"]); Assert.Equal("AZ", outputDict["address[state]"]); Assert.Equal("USA", outputDict["address[country]"]); Assert.Equal("85203", outputDict["address[zip]"]); Assert.Equal("SomeoneName", outputDict["name"]); Assert.Equal("$35000", outputDict["balance"]); Assert.Equal("value1", outputDict["metadata[key1]"]); Assert.Equal("value2", outputDict["metadata[key2]"]); Assert.Equal("123", outputDict["nested[nestedclass2[count]]"]); }
public void TestFormDataBuilderWithNullRequiredProperty() { SomeClass @class = new SomeClass(); @class.Name = null; @class.Age = 21; @class.BigNumber = null; Dictionary <string, string> outputDict = new Dictionary <string, string>(); Assert.Throws <Exception>(() => FormDataBuilder.CreateFormData(@class, ref outputDict, "")); }
public static IHttpRequest FormUrlEncodedBody(this IHttpRequest builder, Action <IFormDataBuilder> configurator) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var formDataBuilder = new FormDataBuilder(); configurator(formDataBuilder); return(builder.TextBody(formDataBuilder.BuildBody())); }
public void TestFormDataBuilderWithNullProperty() { SomeClass @class = new SomeClass(); @class.Name = "TestName"; @class.Age = 21; @class.BigNumber = null; Dictionary <string, string> outputDict = new Dictionary <string, string>(); FormDataBuilder.CreateFormData(@class, ref outputDict, ""); Assert.Equal(2, outputDict.Count); Assert.True(outputDict.ContainsKey("name")); Assert.True(outputDict.ContainsKey("test_age")); Assert.False(outputDict.ContainsKey("bignumber")); Assert.Equal("TestName", outputDict["name"]); Assert.Equal("21", outputDict["test_age"]); }
public void FormDataBuilder_can_add_ItemGroupData_with_string_repeatkey() { var builder1 = new FormDataBuilder("STUDYOID").AddItemGroupData("TOXICITY_SOLICIT", "@CONTEXT", ig => ig.Build()); Assert.AreEqual("@CONTEXT", builder1.Build().ItemGroupData.First().ItemGroupRepeatKey); }
public void FormDataBuilder_uses_appropriate_repeat_key_when_supplied() { var builder1 = new FormDataBuilder("FORMOID", 2); Assert.AreEqual("2", builder1.Build().FormRepeatKey); }