示例#1
0
        public void NoInputParamPostResponseTest()
        {
            HelloController controller = new HelloController();
            var             response   = controller.Post().Value as Response;

            Assert.Equal("2Hello World!", response.output);
        }
示例#2
0
        public void InputParamPostResponseTest(string inputValue, string expectedOutput)
        {
            HelloController controller = new HelloController();
            var             response   = controller.Post(inputValue).Value as Response;

            Assert.Equal(expectedOutput, response.output);
        }
 public void InputParamPostResponseTest(string inputValue, string expectedOutput)
 {
     HelloController controller = new HelloController();
     var             response   = controller.Post(inputValue).Value as Response;
     //Uncomment this line and this will fail unless you update the test data
     // to match my modified strings. {GWC}
     //Assert.Equal(expectedOutput, response.output);
 }
示例#4
0
        public void Post()
        {
            // Arrange
            var controller = new HelloController();

            // Act
            controller.Post("value");

            // Assert
        }
        public void TestWithConfigFile()
        {
            // Arange
            var config = new Dictionary <string, string>();

            config.Add("DefaultWriter", "file");
            var configuration = new ConfigurationBuilder().AddInMemoryCollection(config).Build();
            var controller    = new HelloController(configuration: configuration);

            var sampleText = "Hello World";
            var body       = $"{{\"text\": \"{sampleText}\"}}";
            var elem       = JsonDocument.Parse(body);
            var result     = controller.Post(elem.RootElement);

            // Act
            var s = ((Microsoft.AspNetCore.Mvc.OkObjectResult)result).Value;

            // Assert
            Assert.Equal($"\"{sampleText}\" was written to HelloWorld.CustomWriters.FileWriter", s);
        }
        public void TestWithoutConfig()
        {
            // Arrange
            var controller = new HelloController(configuration: null);

            Assert.Equal(1, 1);
            var sampleText = "Hello World";
            var writeTo    = "console";

            var body = $"{{\"text\": \"{sampleText}\",\"writeTo\": \"{writeTo}\"}}";

            var elem   = JsonDocument.Parse(body);
            var result = controller.Post(elem.RootElement);

            // Act
            var s = ((Microsoft.AspNetCore.Mvc.OkObjectResult)result).Value;

            // Assert
            Assert.Equal($"\"{sampleText}\" was written to HelloWorld.CustomWriters.ConsoleWriter", s);
        }
        public void TestWithoutText()
        {
            // Arange
            var config = new Dictionary <string, string>();

            config.Add("DefaultWriter", "console");
            var configuration = new ConfigurationBuilder().AddInMemoryCollection(config).Build();
            var controller    = new HelloController(configuration: configuration);

            var sampleText = "Hello World";
            var writeTo    = "console";
            var body       = $"{{\"textkeyiswrong\": \"{sampleText}\",\"writeTo\": \"{writeTo}\"}}";
            var elem       = JsonDocument.Parse(body);
            var result     = controller.Post(elem.RootElement);

            // Act
            var r = ((Microsoft.AspNetCore.Mvc.BadRequestObjectResult)result);

            // Assert
            Assert.Equal(400, r.StatusCode);
            Assert.Equal("text is required", r.Value);
        }