コード例 #1
0
 public static void TestFunction3(
     [HttpTrigger("post")] TestPoco poco)
 {
     Assert.Equal("one", poco.Q1);
     Assert.Equal("bodyvalue1", poco.B1);
     Assert.Equal(123, poco.R1);
 }
コード例 #2
0
 public static void CloudBlockBlobBinding_WithUrlBinding(
     [QueueTrigger("testqueue")] TestPoco poco,
     [Blob("{A}")] string blob)
 {
     Assert.AreEqual(TestData, blob);
     _numBlobsRead = 1;
 }
コード例 #3
0
        public async Task BindToPoco_FromUri_Succeeds()
        {
            string              a        = Guid.NewGuid().ToString();
            string              b        = Guid.NewGuid().ToString();
            string              uri      = string.Format("WebHookTestFunctions/BindToPoco_FromUri?A={0}&B={1}&Foo=Bar", a, b);
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Post, uri);
            HttpResponseMessage response = await _fixture.Client.SendAsync(request);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            TestPoco resultPoco = (TestPoco)WebHookTestFunctions.InvokeData;

            Assert.Equal(a, resultPoco.A);
            Assert.Equal(b, resultPoco.B);

            // show that casing of property names doesn't matter
            uri      = string.Format("WebHookTestFunctions/BindToPoco_FromUri?a={0}&b={1}&Foo=Bar", a, b);
            request  = new HttpRequestMessage(HttpMethod.Post, uri);
            response = await _fixture.Client.SendAsync(request);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            resultPoco = (TestPoco)WebHookTestFunctions.InvokeData;
            Assert.Equal(a, resultPoco.A);
            Assert.Equal(b, resultPoco.B);
        }
コード例 #4
0
        public async Task BindAsync_Poco_WebHookData()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunction").GetParameters()[0];

            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true);

            HttpRequest request  = HttpTestHelpers.CreateHttpRequest("POST", "http://functions/myfunc?code=abc123");
            TestPoco    testPoco = new TestPoco
            {
                Name     = "Mathew Charles",
                Location = "Seattle"
            };

            request.HttpContext.Items.Add(HttpExtensionConstants.AzureWebJobsWebHookDataKey, testPoco);

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None);
            ValueBindingContext    context         = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData           triggerData     = await binding.BindAsync(request, context);

            Assert.Equal(5, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            TestPoco result = (TestPoco)(await triggerData.ValueProvider.GetValueAsync());

            Assert.Same(testPoco, result);
        }
コード例 #5
0
        public async Task BindAsync_Poco_FromRouteParameters()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunction").GetParameters()[0];

            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true);

            HttpRequest request = HttpTestHelpers.CreateHttpRequest("GET", "http://functions/myfunc");

            Dictionary <string, object> routeData = new Dictionary <string, object>
            {
                { "Name", "Mathew Charles" },
                { "Location", "Seattle" }
            };

            request.HttpContext.Items.Add(HttpExtensionConstants.AzureWebJobsHttpRouteDataKey, routeData);

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None);
            ValueBindingContext    context         = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData           triggerData     = await binding.BindAsync(request, context);

            Assert.Equal(5, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            TestPoco testPoco = (TestPoco)(await triggerData.ValueProvider.GetValueAsync());

            Assert.Equal("Mathew Charles", testPoco.Name);
            Assert.Equal("Seattle", testPoco.Location);
        }
コード例 #6
0
        public async Task BindAsync_Poco_FromRequestBody()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunction").GetParameters()[0];

            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://functions/myfunc?code=abc123");

            JObject requestBody = new JObject
            {
                { "Name", "Mathew Charles" },
                { "Location", "Seattle" }
            };

            request.Content = new StringContent(requestBody.ToString());
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext    context         = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData           triggerData     = await binding.BindAsync(request, context);

            Assert.Equal(4, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            TestPoco testPoco = (TestPoco)(await triggerData.ValueProvider.GetValueAsync());

            Assert.Equal("Mathew Charles", testPoco.Name);
            Assert.Equal("Seattle", testPoco.Location);
        }
コード例 #7
0
        public static IEnumerable <TestCaseData> MemberTestCasesSimpleInvoke_VoidMethods()
        {
            var          i = 10;
            var          s = "payload";
            var          o = new TestPoco();
            EventHandler e = (sender, args) => { };

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti.VoidMethod()), "VoidMethod")
                         .SetName("VoidMethod"));

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti.VoidMethodArgs(i, s, o)), "VoidMethodArgs")
                         .SetName("VoidMethodArgs"));

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti.Event += e), "add_Event")
                         .SetName("Add_Event"));

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti.Event -= e), "remove_Event")
                         .SetName("Remove_Event"));

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti.Integer = 1), "set_Integer")
                         .SetName("Set property"));

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti.IntegerSetOnly = 1), "set_IntegerSetOnly")
                         .SetName("SetOnly property"));

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti[1] = 10), "set_Item")
                         .SetName("Set int index"));

            yield return(new TestCaseData((Action <ITestInterface>)(ti => ti["hello"] = "world"), "set_Item")
                         .SetName("Set string index"));
        }
コード例 #8
0
        public void Call_IsWithCorrectType_Expect_AssignedResult()
        {
            object tmp = new TestPoco();

            var result = Ensure.Is <TestPoco>(tmp, nameof(tmp));

            result.Should().BeOfType <TestPoco>();
        }
コード例 #9
0
        public void Test_WhenPocoWithInvalidPropertyValueIsPiped_ThenParameterBindingExceptionIsThrown()
        {
            const string InvalidValue = "Four";

            var poco = new TestPoco(InvalidValue);

            Action action = () => TestCmdletHost.RunTestHost(TestCases.ValidateSetFromPipelineByPropertyName, poco);

            action.Should().Throw <ParameterBindingException>();
        }
コード例 #10
0
        public void ShouldEncodeUnixTimestamps()
        {
            var obj = new TestPoco
            {
                When = new DateTime(2018, 1, 11, 4, 57, 54, DateTimeKind.Utc)
            };
            var serialized = JsonConvert.SerializeObject(obj);

            Assert.AreEqual("{\"when\":1515646674}", serialized);
        }
コード例 #11
0
            public void WhenPublish_ThenSinksEvent()
            {
                var poco = new TestPoco();

                webhooks.Publish("aneventname", poco);

                eventSink.Verify(es => es.Write(It.Is <WebhookEvent>(we =>
                                                                     we.EventName == "aneventname" &&
                                                                     we.Data == poco)));
            }
コード例 #12
0
        public async Task BindToPoco_EmptyBody_Succeeds()
        {
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Post, "WebHookTestFunctions/BindToPoco");
            HttpResponseMessage response = await _fixture.Client.SendAsync(request);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            TestPoco resultPoco = (TestPoco)WebHookTestFunctions.InvokeData;

            Assert.Null(resultPoco);
        }
コード例 #13
0
        public void WriteJsonWorksCorrectly(KspVersion version, string expected)
        {
            // Arrange
            var poco = new TestPoco { KspVersion = version };

            // Act
            dynamic result = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(poco));

            // Assert
            Assert.That((string)result.KspVersion, Is.EqualTo(expected));
        }
コード例 #14
0
 public void SetUp()
 {
     dataMapper = new DataMapper<TestPoco>();
     pocoInstance = new TestPoco
     {
         ComplexType = new PocoPoint { X = 1, Y = 2 },
         DifferentName = "Another",
         TestProperty = "Property",
         TestField = "Field"
     };
 }
コード例 #15
0
        public void Test_WhenPocoIsPassedWithValueFromPipelineByPropertyName_ThePropertyValueIsReturned()
        {
            var expected = new TestPoco();
            var result   = TestCmdletHost.RunTestHost(TestCases.ValueFromPipelineByPropertyName, expected);

            result.Count.Should().Be(1, "a single value was passed to the dynamic parameter");
            var actual = result.First().BaseObject;

            actual.GetType().Should().Be <string>();
            actual.ToString().Should().Be(Constants.TestPocoPropertyValue);
        }
コード例 #16
0
        public static async Task IEnumerableCloudBlockBlobBinding_WithModelBinding(
            [QueueTrigger("testqueue")] TestPoco poco,
            [Blob("{A}/{B}ob")] IEnumerable <BlockBlobClient> blobs)
        {
            foreach (var blob in blobs)
            {
                string content = await blob.DownloadTextAsync();

                Assert.AreEqual(TestData, content);
            }
            _numBlobsRead = blobs.Count();
        }
コード例 #17
0
        public void Test_WhenPocoWithValidPropertyValueIsPiped_TheValueIsReturned(string value)
        {
            var poco = new TestPoco(value);

            var result = TestCmdletHost.RunTestHost(TestCases.ValidateSetFromPipelineByPropertyName, poco);

            result.Count.Should().Be(1, "a single value was passed to the dynamic parameter");

            var actual = result.First().BaseObject;

            actual.Should().Be(value);
        }
コード例 #18
0
        public void Test_WhenPocoIsGivenWithTypeInfomation_ItIsReturned()
        {
            var expected = new TestPoco();
            var result   = TestCmdletHost.RunTestHost(TestCases.PocoArgument, expected);

            result.Count.Should().Be(1, "a single value was passed to the dynamic parameter");
            var actual = result.First().BaseObject;

            actual.GetType().Should().Be <TestPoco>();
            ReferenceEquals(expected, actual).Should().BeTrue(
                "the actual instance should pass through the PowerShell pipeline unfettered");
        }
コード例 #19
0
        public async Task BindToCloudBlobContainer_WithModelBinding()
        {
            TestPoco poco = new TestPoco
            {
                A = _fixture.NameResolver.ResolveWholeString(ContainerName)
            };
            string json      = JsonConvert.SerializeObject(poco);
            var    arguments = new { poco = json };

            await _fixture.JobHost.CallAsync(typeof(BlobBindingEndToEndTests).GetMethod("CloudBlobContainerBinding_WithModelBinding"), arguments);

            Assert.AreEqual(6, _numBlobsRead);
        }
コード例 #20
0
 public void SetUp()
 {
     dataMapper   = new DataMapper <TestPoco>();
     pocoInstance = new TestPoco
     {
         ComplexType = new PocoPoint {
             X = 1, Y = 2
         },
         DifferentName = "Another",
         TestProperty  = "Property",
         TestField     = "Field"
     };
 }
コード例 #21
0
        public void GetHttpScriptInvocationContextValueTest_POCO()
        {
            TestPoco inputValue = new TestPoco()
            {
                Name = "TestName",
                Id   = 1234
            };
            object result          = Script.Workers.ScriptInvocationContextExtensions.GetHttpScriptInvocationContextValue(inputValue);
            var    resultAsJObject = (JObject)result;

            Assert.Equal("TestName", resultAsJObject["Name"]);
            Assert.Equal(1234, resultAsJObject["Id"]);
        }
コード例 #22
0
        public void WriteJsonWorksCorrectly(GameVersion version, string expected)
        {
            // Arrange
            var poco = new TestPoco {
                GameVersion = version
            };

            // Act
            dynamic result = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(poco));

            // Assert
            Assert.That((string)result.GameVersion, Is.EqualTo(expected));
        }
コード例 #23
0
 public void SetUp()
 {
     classMap     = new ClassMap <TestPoco>();
     pocoInstance = new TestPoco
     {
         ComplexType = new PocoPoint {
             X = 1, Y = 2
         },
         DifferentName   = "Another",
         IgnoredProperty = 123,
         TestProperty    = "Property",
         TestField       = "Field"
     };
 }
コード例 #24
0
        public TestQueryBuilderExtensions()
        {
            var driver = new MySqlDriver();
            var mapper = new Mapper();

            connection  = FolkeConnection.Create(driver, mapper, TestHelpers.ConnectionString);
            transaction = connection.BeginTransaction();
            connection.CreateOrUpdateTable <TestPoco>();
            connection.CreateOrUpdateTable <TestManyPoco>();
            testPoco = new TestPoco {
                Name = "FakeName"
            };
            connection.Save(testPoco);
        }
コード例 #25
0
        public async Task BindToCloudBlockBlob_WithUrlBinding()
        {
            // get url for the test blob
            BlockBlobClient blob = _fixture.BlobContainer.GetBlockBlobClient("blob1");
            TestPoco        poco = new TestPoco
            {
                A = blob.Uri.ToString()
            };
            string json      = JsonConvert.SerializeObject(poco);
            var    arguments = new { poco = json };
            await _fixture.JobHost.CallAsync(typeof(BlobBindingEndToEndTests).GetMethod("CloudBlockBlobBinding_WithUrlBinding"), arguments);

            Assert.AreEqual(1, _numBlobsRead);
        }
コード例 #26
0
        public void BindToCloudBlob_WithModelBinding_Fail()
        {
            TestPoco poco = new TestPoco
            {
                A = _fixture.NameResolver.ResolveWholeString(ContainerName)
            };
            string json      = JsonConvert.SerializeObject(poco);
            var    arguments = new { poco = json };
            var    ex        = Assert.ThrowsAsync <FunctionInvocationException>(() =>
                                                                                _fixture.JobHost.CallAsync(typeof(BlobBindingEndToEndTests).GetMethod("CloudBlockBlobBinding_WithUrlBinding"), arguments));

            // CloudBlockBlobBinding_WithUrlBinding is suppose to bind to a blob
            Assert.AreEqual($"Invalid blob path specified : '{poco.A}'. Blob identifiers must be in the format 'container/blob'.", ex.InnerException.InnerException.Message);
        }
コード例 #27
0
        public void ShouldDecodeSameObjectAsEncoded()
        {
            var person = new TestPoco();

            person.Age  = 5;
            person.Name = "Bill";

            var encoder = new JsonNetJsonEncoder();

            var encoded       = encoder.EncodeObject(person);
            var decodedObject = encoder.DecodeObject <TestPoco>(encoded);

            Assert.AreEqual(person.Age, decodedObject.Age);
            Assert.AreEqual(person.Name, decodedObject.Name);
        }
コード例 #28
0
        public async Task BindAsync_Poco_FromRequestBody(bool isChunked)
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunction").GetParameters()[0];
            var           httpOptions   = Options.Create <HttpOptions>(new HttpOptions()
            {
                EnableChunkedRequestBinding = isChunked
            });

            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true, httpOptions);

            JObject requestBody = new JObject
            {
                { "Name", "Mathew Charles" },
                { "Location", "Seattle" }
            };

            var headers = new HeaderDictionary();

            headers.Add("Content-Type", "application/json");
            HttpRequest request = HttpTestHelpers.CreateHttpRequest("POST", "http://functions/myfunc?code=abc123", headers, requestBody.ToString());

            if (isChunked)
            {
                request.ContentLength = null;
                request.Headers.Add(HeaderNames.TransferEncoding, "chunked");
            }

            IServiceCollection services = new ServiceCollection();

            services.AddMvc();
            services.AddSingleton <ObjectPoolProvider, DefaultObjectPoolProvider>();
            services.AddSingleton <ILoggerFactory, NullLoggerFactory>();

            request.HttpContext.RequestServices = services.BuildServiceProvider();

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None);
            ValueBindingContext    context         = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData           triggerData     = await binding.BindAsync(request, context);

            Assert.Equal(5, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            TestPoco testPoco = (TestPoco)(await triggerData.ValueProvider.GetValueAsync());

            Assert.Equal("Mathew Charles", testPoco.Name);
            Assert.Equal("Seattle", testPoco.Location);
        }
コード例 #29
0
        public static IEnumerable <TestCaseData> MemberTestCasesSimpleInvoke()
        {
            var i       = 1;
            var s       = "payload";
            var o       = new TestPoco();
            var empty   = new object[0];
            var allArgs = new object[] { i, s, o };

            object[] ia = new object[] { i };
            object[] sa = new object[] { s };
            object[] oa = new object[] { o };

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.IntMethod()), empty, "IntMethod", 0)
                         .SetName("IntMethod"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.IntMethodArgs(i, s, o)), allArgs, "IntMethodArgs", 0)
                         .SetName("IntMethodArgs"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.ObjectMethod()), empty, "ObjectMethod", o)
                         .SetName("ObjectMethod"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.ObjectMethodArgs(i, s, o)), allArgs, "ObjectMethodArgs", o)
                         .SetName("ObjectMethodArgs"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.IntMethodOverride()), empty, "IntMethodOverride", 0)
                         .SetName("IntMethodOverride()"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.IntMethodOverride(i)), ia, "IntMethodOverride", 0)
                         .SetName("IntMethodOverride(int)"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.IntMethodOverride(s)), sa, "IntMethodOverride", 0)
                         .SetName("IntMethodOverride(string)"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.IntMethodOverride(o)), oa, "IntMethodOverride", 0)
                         .SetName("IntMethodOverride(object)"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.Integer), empty, "get_Integer", 0)
                         .SetName("Get property"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti.IntegerGetOnly), empty, "get_IntegerGetOnly", 0)
                         .SetName("GetOnly property"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti[1]), ia, "get_Item", 99)
                         .SetName("Get int index"));

            yield return(new TestCaseData((Func <ITestInterface, object>)(ti => ti["payload"]), sa, "get_Item", "moon")
                         .SetName("Get string index"));
        }
コード例 #30
0
        public void Should_compute_equivalent_hash_values_for_equivalent_POCOs()
        {
            var poco1 = new TestPoco()
            {
                Name = "Aaron", Value = 1337
            };
            var poco2 = new TestPoco()
            {
                Name = "Aaron", Value = 1337
            };

            var hash1 = Murmur3.Hash(poco1);
            var hash2 = Murmur3.Hash(poco2);

            Assert.AreEqual(hash1, hash2);
        }
コード例 #31
0
        public void BindToCloudBlobContainer_WithUrlBinding_Fail()
        {
            // get url for the test blob
            var      blob = _fixture.BlobContainer.GetBlockBlobClient("blob1");
            TestPoco poco = new TestPoco
            {
                A = blob.Uri.ToString()
            };
            string json      = JsonConvert.SerializeObject(poco);
            var    arguments = new { poco = json };
            var    ex        = Assert.ThrowsAsync <FunctionInvocationException>(() =>
                                                                                _fixture.JobHost.CallAsync(typeof(BlobBindingEndToEndTests).GetMethod("CloudBlobContainerBinding_WithModelBinding"), arguments));

            // CloudBlobContainerBinding_WithModelBinding is suppose to bind to a container
            Assert.IsInstanceOf <FormatException>(ex.InnerException.InnerException);
        }
コード例 #32
0
            public void WhenPublishAndPublishEventFilter_ThenAugmentsPublishedEvent()
            {
                var poco  = new TestPoco();
                var poco2 = new TestPoco();

                webhooks.PublishFilter = @event =>
                {
                    @event.Id   = "anewid";
                    @event.Data = poco2;
                };
                webhooks.Publish("aneventname", poco);

                eventSink.Verify(es => es.Write(It.Is <WebhookEvent>(we =>
                                                                     we.Id == "anewid" &&
                                                                     we.EventName == "aneventname" &&
                                                                     we.Data == poco2)));
            }
コード例 #33
0
 public static Task QueueTrigger(TestPoco message, TraceWriter traceWriter)
 {
     return Task.FromResult(0);
 }