public void TestWebService_Execute_FormDataParameters_Null_ExpectSuccess()
        {
            var serializer = new Dev2JsonSerializer();

            var mockWebServices = new Mock <IWebServices>();
            var sut             = new TestWebService
            {
                WebServices       = mockWebServices.Object,
                ResourceCatalogue = new Mock <IResourceCatalog>().Object
            };

            var mockWebClientWrapper = new Mock <IWebClientWrapper>();

            var mockWebSource = new Mock <IWebSource>();

            mockWebSource.Setup(o => o.Address)
            .Returns("http://address.co.za/examples");
            mockWebSource.Setup(o => o.Client)
            .Returns(mockWebClientWrapper.Object);     //Ensure this is not instantiated here
            mockWebSource.Setup(o => o.AuthenticationType)
            .Returns(AuthenticationType.Anonymous);

            var webService = new Warewolf.Core.WebServiceDefinition()
            {
                Source  = new WebServiceSourceDefinition(mockWebSource.Object),
                Headers = new List <INameValue> {
                    new NameValue("Content-Type", "multipart/form-data")
                },
                FormDataParameters = null
            };

            var values = new Dictionary <string, StringBuilder>
            {
                { "WebService", webService.SerializeToJsonStringBuilder() }
            };

            var result = sut.Execute(values, null);

            var executeMessage = serializer.Deserialize <ExecuteMessage>(result);

            Assert.IsNotNull(result);
            Assert.IsFalse(executeMessage.HasError, "FormDataParameters can be null");
            Assert.IsFalse(executeMessage.Message.ToString().Contains("Value cannot be null.\r\nParameter name: source"));

            mockWebServices.Verify(o => o.TestWebService(It.IsAny <WebService>()), Times.Once, "Some request do not set FormDataParameters and hence it is not required field");
            mockWebSource.Verify(o => o.Client, Times.Never);
        }
Esempio n. 2
0
 /// <summary>
 ///     Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 ///     true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(WebServiceDefinition other)
 {
     return(Equals((Object)other));
 }
        public void TestWebService_Execute_FormDataParameters_NotNull_ExpectSuccess()
        {
            var testFileKey           = "testFileKey";
            var testFileName          = "testFileName";
            var testFileContent       = "this can be any file type parsed into base64 string";
            var testFileContentBytes  = testFileContent.ToBytesArray();
            var testFileContentBase64 = testFileContentBytes.ToBase64String();

            var serializer = new Dev2.Communication.Dev2JsonSerializer();

            var mockWebServices = new Mock <IWebServices>();

            var sut = new TestWebService
            {
                WebServices       = mockWebServices.Object,
                ResourceCatalogue = new Mock <IResourceCatalog>().Object
            };

            var mockWebClientWrapper = new Mock <IWebClientWrapper>();

            var mockWebSource = new Mock <IWebSource>();

            mockWebSource.Setup(o => o.Address)
            .Returns("http://address.co.za/examples");
            mockWebSource.Setup(o => o.Client)
            .Returns(mockWebClientWrapper.Object);     //Ensure this is not instanciated here
            mockWebSource.Setup(o => o.AuthenticationType)
            .Returns(AuthenticationType.Anonymous);

            var webService = new Warewolf.Core.WebServiceDefinition()
            {
                Source  = new WebServiceSourceDefinition(mockWebSource.Object),
                Headers = new List <INameValue> {
                    new NameValue("Content-Type", "multipart/form-data")
                },
                IsManualChecked    = false,
                IsFormDataChecked  = true,
                FormDataParameters = new List <IFormDataParameters>
                {
                    new FormDataConditionExpression
                    {
                        Key  = testFileKey,
                        Cond = new FormDataConditionFile
                        {
                            FileBase64 = testFileContentBase64,
                            FileName   = testFileName
                        }
                    }.ToFormDataParameter()
                }
            };

            var values = new Dictionary <string, StringBuilder>
            {
                { "WebService", serializer.SerializeToBuilder(webService) }
            };

            var result = sut.Execute(values, null);

            var executeMessage = serializer.Deserialize <ExecuteMessage>(result);

            Assert.IsNotNull(result);
            Assert.IsFalse(executeMessage.HasError);
            var message = executeMessage.Message.ToString();

            Assert.IsTrue(message.Contains("\"Headers\":[{\"$id\":\"2\",\"$type\":\"Dev2.Common.Interfaces.NameValue, Dev2.Common.Interfaces\",\"Name\":\"Content-Type\",\"Value\":\"multipart/form-data\"}]"));
            Assert.IsTrue(message.Contains("\"FileName\":\"testFileName\",\"ContentType\":null,\"FileBase64\":\"dGhpcyBjYW4gYmUgYW55IGZpbGUgdHlwZSBwYXJzZWQgaW50byBiYXNlNjQgc3RyaW5n\",\"Key\":\"testFileKey\""));
            Assert.IsTrue(message.Contains("\"IsFormDataChecked\":true,\"IsUrlEncodedChecked\":false,\"IsManualChecked\":false,"));
            mockWebServices.Verify(o => o.TestWebService(It.IsAny <WebService>()), Times.Once);
            mockWebSource.Verify(o => o.Client, Times.Never);
        }