public async void Http_trigger_should_return_known_string() { var request = TestFactory.CreateHttpRequest("name", "Bill"); var response = (OkObjectResult)await Function1.Run(request, logger); Assert.Equal("Hello, Bill", response.Value); }
public void Run() { // Arrange var toDo = new ToDo { Description = $"description-{Guid.NewGuid()}" }; // Act var actionResult = Function1.Run(toDo, _logger); // Assert Assert.IsType <OkObjectResult>(actionResult); var okObjectResult = (OkObjectResult)actionResult; Assert.IsType <ToDo>(okObjectResult.Value); toDo = (ToDo)okObjectResult.Value; var expectedDataStore = nameof(ToDoSample1DataStore); Assert.Equal(expectedDataStore, toDo.DataStore); }
public async void Http_trigger_should_return_known_string_from_member_data(string queryStringKey, string queryStringValue) { var request = TestFactory.CreateHttpRequest(queryStringKey, queryStringValue); var response = (OkObjectResult)await Function1.Run(request, logger); Assert.Equal($"Hello, {queryStringValue}", response.Value); }
public async Task Function1Test() { var logMock = new Mock <ILogger <Application> >(); loggerMock = logMock.Object; var loggingMock = new Mock <ILogger>(); client = new DocumentClient(new Uri(endpointUrl), authorizationKey); var uri = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId); var doc = new Document(); doc.SetPropertyValue("name", "jay"); List <Document> documents = new List <Document>(); doc = await client.CreateDocumentAsync( "/dbs/MyDB/colls/MyCollection", doc, null); documents.Add(doc); Console.WriteLine("insert success"); var result = Function1.Run(documents, loggingMock.Object, new Application(loggerMock)); Assert.AreEqual("krati", result); }
public async void HttpTriggerWithoutParams() { var request = TestFactory.CreateHttpRequest("", ""); var response = (OkObjectResult)await Function1.Run(request, logger); Assert.Equal("Hello there! Welcome to Azure Functions!", response.Value); }
public async Task Request_With_Query() { var query = new Dictionary <String, StringValues>(); query.TryAdd("id", "2"); var body = ""; var logger = Mock.Of <ILogger>(); HGV abc = new HGV(); abc.Country = "etsimgn"; abc.HGVName = "etssd"; _service.Setup(p => p.test("2")).ReturnsAsync(abc); var result = await function.Run(req : HttpRequestSetup(query, body), logger); var resultObject = result as OkObjectResult; Assert.AreEqual("200", resultObject.StatusCode.ToString()); }
async Task HttpTriggerWithParams() { HttpRequestMessage request = new HttpRequestMessage(); request.Content = new StringContent("{'name': 'Bill'}", System.Text.Encoding.UTF8, "application/json"); request.SetConfiguration(new System.Web.Http.HttpConfiguration()); var result = await Function1.Run(request, fakeTraceWriter); (await result.Content.ReadAsStringAsync()).Should().Equal($"\"Hello Bill! Welcome to Azure Functions!\""); }
public async Task Request_Without_Query_And_Body() { var query = new Dictionary <String, StringValues>(); var body = ""; var result = await Function1.Run(HttpRequestSetup(query, body), _primary, _logger); var resultObject = (BadRequestObjectResult)result; Assert.AreEqual("Please pass a name on the query string or in the request body", resultObject.Value); }
public async Task Request_Without_Query() { var query = new Dictionary <String, StringValues>(); var body = "{\"name\":\"lee\"}"; var result = await Function1.Run(HttpRequestSetup(query, body), _primary, _logger); var resultObject = (OkObjectResult)result; Assert.AreEqual("Hello, You sent me hello lee. Thank you for calling me! Have a nice day!", resultObject.Value); }
public async Task Request_WithNaturalParameterUndefined_ErrorRespose() { var query = new Dictionary <String, StringValues>(); var body = ""; var logger = Mock.Of <ILogger>(); //using Moq for example var result = await Function1.Run(req : HttpRequestSetup(query, body), log : logger); var resultObject = (BadRequestObjectResult)result; Assert.AreEqual("Please pass a natural number (positve integer) natural on the query string or in the request body", resultObject.Value); Assert.AreEqual((int)HttpStatusCode.BadRequest, resultObject.StatusCode.Value); }
public void RunAsync_when_name_not_specfied_then_should_show_instruction() { var query = new Dictionary <string, StringValues>(); var req = CreateHttpRequest(query, ""); var function1 = new Function1(Mock.Of <IConfiguration>()); var result = (OkObjectResult)function1.Run(req, Mock.Of <ILogger>()); result.StatusCode.Should().Be(StatusCodes.Status200OK); result.Value.Should().Be("This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."); }
public async Task Request_With_Query() { var query = new Dictionary <String, StringValues>(); query.TryAdd("name", "kathy"); var body = ""; var result = await Function1.Run(req : HttpRequestSetup(query, body), primaryInterface : _primary, log : _logger); var resultObject = (OkObjectResult)result; Assert.AreEqual("Hello, You sent me hello kathy. Thank you for calling me! Have a nice day!", resultObject.Value); }
public async Task Request_WithNaturalDefinedButNoNaturalValue_ErrorRespose() { var query = new Dictionary <String, StringValues>(); query.TryAdd("natural", "ushio"); var body = ""; var logger = Mock.Of <ILogger>(); var result = await Function1.Run(req : HttpRequestSetup(query, body), log : logger); var response = (BadRequestObjectResult)result; Assert.AreEqual("Please pass a natural number (positve integer) natural on the query string or in the request body", response.Value); Assert.AreEqual((int)HttpStatusCode.BadRequest, response.StatusCode); }
public async Task Request_WithNaturalWellDefined_ReturnTrue() { var query = new Dictionary <String, StringValues>(); query.TryAdd("natural", "2"); var body = ""; var logger = Mock.Of <ILogger>(); var result = await Function1.Run(req : HttpRequestSetup(query, body), log : logger); var response = (OkObjectResult)result; Assert.AreEqual("Is Even: True", response.Value); Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode); }
public void Should_log_hello_word_anton() { var name = "Anton"; var expectedName = name.ToUpper(); var stringUppercaseServiceMock = Substitute.For <IStringUppercaseService>(); var loggerMock = Substitute.For <ILogger <Function1> >(); stringUppercaseServiceMock.Apply(Arg.Is <string>(v => v == name)).Returns(expectedName); var func1 = new Function1(stringUppercaseServiceMock, loggerMock); func1.Run("Anton"); loggerMock.Received().LogInformation($"Hello word: {expectedName}"); }
public void CallHttp() { HttpContext context = new DefaultHttpContext(); HttpRequest request = new DefaultHttpRequest(context) { Method = "GET", Body = null }; ILogger nullLogger = new NullLogger <string>(); var response = Function1.Run(request, nullLogger) as OkObjectResult; Assert.NotNull(response); Assert.Equal(200, response.StatusCode); }
public async Task Run_NoNameInQueryAndBody() { // Assert ListLogger logger = new ListLogger(); HttpRequest request = FunctionTest.HttpRequestSetup(new Dictionary <string, StringValues>(), ""); //act var response = await Function1.Run(request, logger); var resultObject = (OkObjectResult)response; // Assert Assert.AreEqual("This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", resultObject.Value); Assert.IsTrue(logger.Logs.Contains("C# HTTP trigger function processed a request.")); }
public async Task TestQuery() { var query = new Dictionary <String, StringValues>(); query.TryAdd("name", "Michael"); var body = ""; IActionResult result = await Function1.Run(HttpRequestSetup(query, body), LoggerSetup()); Console.WriteLine(result.ToString()); // Assert what result came back and then do further assertions. OkObjectResult casted = (Microsoft.AspNetCore.Mvc.OkObjectResult)result; Console.WriteLine(casted.Value.ToString()); }
public void RunAsync_when_name_specfied_then_should_be_in_response() { var query = new Dictionary <string, StringValues> { { "name", new StringValues("Bob") } }; var req = CreateHttpRequest(query, ""); var function1 = new Function1(Mock.Of <IConfiguration>()); var result = (OkObjectResult)function1.Run(req, Mock.Of <ILogger>()); result.StatusCode.Should().Be(StatusCodes.Status200OK); result.Value.Should().Be("Hello, Bob. This HTTP triggered function executed successfully."); }
public async Task Run_QueryContainsName() { // Arrange ListLogger logger = new ListLogger(); Dictionary <string, StringValues> query = new Dictionary <string, StringValues>(); query["name"] = new StringValues("Abc"); HttpRequest request = FunctionTest.HttpRequestSetup(query, ""); // Act var response = await Function1.Run(request, logger); var resultObject = (OkObjectResult)response; // Assert Assert.AreEqual("Hello Abc", resultObject.Value); Assert.IsTrue(logger.Logs.Contains("C# HTTP trigger function processed a request.")); }
public async Task Run_QueryBodyContainsName() { // Arrange ListLogger logger = new ListLogger(); var query = new Dictionary <string, StringValues>(); // body should be json format string body = "{\"name\":\"Def\"}"; HttpRequest request = FunctionTest.HttpRequestSetup(query, body); // Act var response = await Function1.Run(request, logger); var resultObject = (OkObjectResult)response; //Assert Assert.AreEqual("Hello Def", resultObject.Value); Assert.IsTrue(logger.Logs.Contains("C# HTTP trigger function processed a request.")); }
public async Task Run_CatchAnyExceptionsTricklingUpToTopLevelFunctionCode() { //arrange var mockHttpRequest = new Mock <HttpRequest>(); //act var actionResult = _function1.Run(mockHttpRequest.Object, out _cosmosDocument, _mockLogger); //assert Assert.IsTrue(_mockLogger.GetLogs().Where(m => m.Contains(UserFriendlyMessages.UnhandledException)).Any()); Assert.IsInstanceOfType(actionResult, typeof(StatusCodeResult)); Assert.IsTrue(String.Equals(((StatusCodeResult)actionResult).StatusCode, 500)); Assert.IsNull(_cosmosDocument); //Make sure cosmos document won't be saved }
public async Task TestFunction1ViaDirectCall() { // GIVEN a Mock HttpRequest var mockHttpRequest = new Mock <HttpRequest> { CallBase = true }; // AND it has an empty Query mockHttpRequest.SetupGet(request => request.Query).Returns(new QueryCollection()); // AND it has an empty Body mockHttpRequest.SetupGet(request => request.Body).Returns(new MemoryStream()); // WHEN Function1.Run is called // AND the Mock HttpRequest is passed in var result = await Function1.Run(mockHttpRequest.Object, "Direct", Mock.Of <ILogger>()); // THEN BadRequestObjectResult is returned Assert.That(result, Is.InstanceOf <BadRequestObjectResult>()); // AND the Value of it is 'Direct: Please pass a name on the query string or in the request body' Assert.That(((BadRequestObjectResult)result).Value, Is.EqualTo("Direct: Please pass a name on the query string or in the request body")); }
public async Task Test1() { var httpRequest = new DefaultHttpRequest(new DefaultHttpContext()) { Method = HttpMethods.Post }; string json = JsonConvert.SerializeObject(new PostBody()); var memoryStream = new MemoryStream(); using var writer = new StreamWriter(memoryStream); await writer.WriteAsync(json); await writer.FlushAsync(); memoryStream.Position = 0; httpRequest.Body = memoryStream; var response = (OkObjectResult)await Function1.Run(httpRequest, Logger); Assert.True(((string)response.Value).Contains("bob")); }
public async Task <IActionResult> GetFunction1(string custom) { return(await Function1.Run(HttpContext.Request, custom, Mock.Of <ILogger>())); }
public void Test1() { Function1.Run("Hello, world!", null); }
public async Task TestMethod1() { var mockLogger = new Mock <ILogger>(); await Function1.Run(new DefaultHttpRequest(new DefaultHttpContext()), mockLogger.Object); }