Example #1
0
        [InlineData("{ \"name\": \" \" }")] // Just a space for name value.
        public async void No_name_returns_BadRequestObjectResult_with_help_text(string jsonBody)
        {
            var fakeApiAuthorizationService = new FakeApiAuthorizationService()
            {
                // Setup to fake athuorization success.
                ApiAuthorizationResultForTests = new ApiAuthorizationResult()
            };

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpPostRequest(
                jsonBody);

            var listLogger = new ListLoggerFixture();

            var func = new HelloFunction(fakeApiAuthorizationService);

            IActionResult actionResult = await func.Run(httpRequest, listLogger);

            Assert.NotNull(actionResult);

            Assert.IsType <BadRequestObjectResult>(actionResult);

            Assert.Equal("Please pass a name the request body.", ((BadRequestObjectResult)actionResult).Value);

            Assert.NotEmpty(listLogger.LogEntries);
        }
Example #2
0
        public async void Happy_path_returns_OkObjectResult_with_hello_text()
        {
            const string ExpecetedName = "Some Name";

            var fakeApiAuthorization = new FakeApiAuthorizationService()
            {
                // Setup to fake athuorization success.
                ApiAuthorizationResultForTests = new ApiAuthorizationResult()
            };

            string jsonBody = $"{{ \"name\": \"{ExpecetedName}\" }}";

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpPostRequest(
                jsonBody);

            var listLogger = new ListLoggerFixture();

            var func = new HelloFunction(fakeApiAuthorization);

            IActionResult actionResult = await func.Run(httpRequest, listLogger);

            Assert.NotNull(actionResult);

            Assert.IsType <OkObjectResult>(actionResult);

            Assert.Equal($"Hello, {ExpecetedName}", ((OkObjectResult)actionResult).Value);

            Assert.NotEmpty(listLogger.LogEntries);

            Assert.True(listLogger.HasLogEntryMessageContaining(
                            LogLevel.Warning,
                            $"HTTP trigger function {nameof(HelloFunction)} rquest is authorized."));
        }
Example #3
0
        public async void Authorization_fail_returns_UnauthorizedResult()
        {
            const string ExpectedFailureReason = "some reason to fail.";

            var fakeApiAuthorization = new FakeApiAuthorizationService()
            {
                // Setup for athuorization fails.
                ApiAuthorizationResultForTests = new ApiAuthorizationResult(ExpectedFailureReason)
            };

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpGetRequest(
                "name",   // quertyStringKey doesn't matter.
                "world"); // quertyStringValue doesn't matter.

            var listLogger = new ListLoggerFixture();

            var func = new HelloFunction(fakeApiAuthorization);

            IActionResult actionResult = await func.Run(httpRequest, listLogger);

            Assert.NotNull(actionResult);

            Assert.IsType <UnauthorizedResult>(actionResult);

            Assert.NotEmpty(listLogger.LogEntries);

            Assert.True(listLogger.HasLogEntryMessageContaining(
                            LogLevel.Warning,
                            ExpectedFailureReason));
        }
Example #4
0
        static void Main(string[] args)
        {
            int[] numbers = { 3, 8, 12, 78, 91, 23, 45, 98, 17, 2, 1 };

            HelloFunction hf = HelloGerman;

            hf += HelloEnglish;
            hf += HelloHungarian;

            //hf -= HelloGerman;
            //hf -= HelloEnglish;
            //hf -= HelloHungarian;

            hf?.Invoke("John");

            // ===============================================================================

            Console.WriteLine();

            MathFunction mf = SUM;

            mf += Average;

            // double? result = mf?.Invoke(number);

            double?[] result  = new double?[2];
            int       pointer = 0;

            foreach (MathFunction item in mf.GetInvocationList())
            {
                Console.WriteLine(result[pointer++] = item?.Invoke(numbers));
                ;
            }
        }
Example #5
0
        public async void HttpTriggerWithoutParamsReturnsGenericMessage()
        {
            var query   = new Dictionary <string, StringValues>();
            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Query = new QueryCollection(query)
            };

            var response = (OkObjectResult)await HelloFunction.Run(request, logger);

            response.Value.ShouldBe("This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.");
        }
Example #6
0
        public async void HttpTriggerWithNameParamShouldReturnNameInResponse()
        {
            var query = new Dictionary <string, StringValues>();

            query.Add("name", "Robert");
            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Query = new QueryCollection(query)
            };

            var response = (OkObjectResult)await HelloFunction.Run(request, logger);

            response.Value.ShouldBe("Hello, Robert. Welcome to this amazing Azure Function!");
        }
Example #7
0
        //public static void Main()
        //{
        public static void test()
        {
            HelloFunction hf = new HelloFunction(Hello);

            hf("Arafat");
        }
Example #8
0
 protected BaseTestClass(TestFixture fixture)
 {
     fixture.Initialize();
     Sut = fixture.CreateHelloFunction();
 }