<commit_before>﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSwag.CodeGeneration.SwaggerGenerators.WebApi;
using NSwag.Demo.Web.Controllers;

namespace NSwag.Tests.Integration
{
    [TestClass]
    public class WebApiToSwaggerGeneratorTests
    {
        [TestMethod]
        public void When_generating_swagger_from_controller_than_all_required_operations_are_available()
        {
            //// Arrange
            var generator = new WebApiToSwaggerGenerator("api/{controller}/{action}/{id}");

            //// Act
            var service = generator.Generate<PersonsController>();
            var swaggerSpecification = service.ToJson();

            //// Assert
            Assert.AreEqual(8, service.Operations.Count());
        }

        [TestMethod]
        public void When_there_is_a_ResultType_attribute_on_an_action_method_then_the_response_is_taken_from_the_given_type()
        {
            //// Arrange
            var generator = new WebApiToSwaggerGenerator("api/{controller}/{action}/{id}");

            //// Act
            var service = generator.Generate<PersonsController>();
            var operation = service.Operations.Single(o => o.Path == "api/Persons/Get/{id}");

            //// Assert
            Assert.AreEqual("Person", operation.Operation.Responses["200"].Schema.ActualSchema.TypeName);
        }
    }
}<commit_msg>Improved unit test<commit_after>﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSwag.CodeGeneration.SwaggerGenerators.WebApi;
using NSwag.Demo.Web.Controllers;

namespace NSwag.Tests.Integration
{
    [TestClass]
    public class WebApiToSwaggerGeneratorTests
    {
        [TestMethod]
        public void When_generating_swagger_from_controller_than_all_required_operations_are_available()
        {
            //// Arrange
            var generator = new WebApiToSwaggerGenerator("api/{controller}/{action}/{id}");

            //// Act
            var service = generator.Generate<PersonsController>();
            var swaggerSpecification = service.ToJson();

            //// Assert
            Assert.AreEqual(8, service.Operations.Count());
        }

        [TestMethod]
        public void When_there_is_a_ResultType_attribute_on_an_action_method_then_the_response_is_taken_from_the_given_type()
        {
            //// Arrange
            var generator = new WebApiToSwaggerGenerator("api/{controller}/{action}/{id}");

            //// Act
            var service = generator.Generate<PersonsController>();
            var operation = service.Operations.Single(o => o.Path == "api/Persons/Get/{id}");

            //// Assert
            Assert.AreEqual(1, operation.Operation.Responses.Count);
            Assert.AreEqual("Person", operation.Operation.Responses["200"].Schema.ActualSchema.TypeName);
        }
    }
}
{'fraction_non_alphanumeric': 0.11056682995101469, 'fraction_numerical': 0.0031490552834149755, 'mean_word_length': 2.5782227784730916, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6270402', 'n_tokens_mistral': 806, 'n_tokens_neox': 777, 'n_words': 112}