예제 #1
0
        public void TheyAreTreatedLikePrimitives()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(FauxPrimitiveController))
                      .Configure(options =>
            {
                options.TypeConverter.TreatAsPrimitive =
                    options.TypeConverter.TreatAsPrimitive.ExtendStrategy(
                        original => type =>
                        type == typeof(FauxPrimitiveController.FauxPrimitive) || original(type));
                options.ComplexTypeStrategy = options.ComplexTypeStrategy.ExtendStrategy(original => (writer, info, type) =>
                {
                    if (info.Name == nameof(FauxPrimitiveController.FauxPrimitive))
                    {
                        writer.WriteLine($"export type {info.Name} = string");
                    }
                    else
                    {
                        original(writer, info, type);
                    }
                });
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
예제 #2
0
        public void OnlyTypesForThatControllerAreOutput()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(TestController))
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
예제 #3
0
        public void AllRoutesAndDtosAreOutput()
        {
            var res = TeeSquareWebApi.GenerateForAssemblies(WebApiAssembly)
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void OnlySharedTypesAreEmitted()
        {
            var res = TeeSquareWebApi.GenerateForControllers()
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void TheRequestFactoryDestructuresTheDtoIntoTheRouteOrQuery()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(DtoFromRouteOrQueryController))
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
예제 #6
0
        public void FilterControllersAreNotEmitted()
        {
            var res = TeeSquareWebApi.GenerateForControllers(TestConstants.SimpleControllers)
                      .WithControllerFilter(c => c != typeof(FormValueController))
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void TheyAreIncludedInTheOutput()
        {
            var res = TeeSquareWebApi.GenerateForAssemblies(WebApiAssembly)
                      .AddTypes(typeof(NotUsedInApiTestDto))
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void TheKindDeterminedByTheStrategyIsUsed()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(OtherController))
                      .Configure(options =>
            {
                options.GetParameterKindStrategy = (paramInfo, route, method) => ParameterKind.Route;
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void TheyCanBeImportedFromElsewhere()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(TestController))
                      .Configure(options =>
            {
                options.RequestHelperTypeOption = RequestHelperTypeOptions.ImportTypes("./WhenNoControllersAreReferenced.OnlySharedTypesAreEmitted");
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void AllRoutesAndDtosAreOutput()
        {
            var res = TeeSquareWebApi.GenerateForAssemblies(TestConstants.WebApiAssembly)
                      .Configure(options =>
            {
                options.TypeConverter = new TypeConverter((typeof(IFormFile), "File"));
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
예제 #11
0
        public void TheyAreIncludedInTheOutput()
        {
            var res = TeeSquareWebApi.GenerateForControllers(TestConstants.SimpleControllers)
                      .Configure(options =>
            {
                options.TypeConverter = new TypeConverter((typeof(IFormFile), "File"));
            })
                      .AddTypes(typeof(NotUsedInApiTestDto))
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void NullableBodyTypesAreHandledCorrectly()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(OtherController))
                      .Configure(options =>
            {
                options.GetParameterKindStrategy = (paramInfo, route, method) => ParameterKind.Body;
                options.GetHttpMethodAndRequestFactoryStrategy =
                    (controller, action) => (RequestInfo.Post, HttpMethod.Post);
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void TheRouteDeterminedByTheStrategyIsUsed()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(ReturnValueAttributeController))
                      .Configure(options =>
            {
                var defaultStrategy        = options.BuildRouteStrategy;
                options.BuildRouteStrategy = (controller, action, defaultRoute) =>
                                             $"prefix/{defaultStrategy(controller, action, defaultRoute)}";
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
예제 #14
0
        public void RoutesAreSplitAcrossAllocatedClassesWhichMatchTheRequestFactoryName()
        {
            var res = TeeSquareWebApi.GenerateForControllers(TestConstants.SimpleControllers)
                      .Configure(options =>
            {
                options.TypeConverter       = new TypeConverter((typeof(IFormFile), "File"));
                options.FactoryNameStrategy = (controller, action, route) =>
                                              $"{controller.Name.Replace("Controller", "")}RequestFactory";
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
        public void TheTypeDeterminedByTheStrategyIsUsed()
        {
            var res = TeeSquareWebApi.GenerateForControllers(typeof(ReturnValueAttributeController))
                      .Configure(options =>
            {
                options.GetApiReturnTypeStrategy = (controller, action) =>
                                                   action.GetCustomAttributes <ProducesResponseTypeAttribute>()
                                                   .Select(a => a.Type)
                                                   .FirstOrDefault() ?? action.ReturnType;
            })
                      .WriteToString();

            Blurk.CompareImplicitFile("ts")
            .To(res)
            .AssertAreTheSame(Assert.Fail);
        }
예제 #16
0
        static void Main(string[] args)
        {
            Core22Configurator.Configure();
            var outputPath = args
                             .SkipWhile(a => a != "-o")
                             .Skip(1)
                             .FirstOrDefault();

            if (string.IsNullOrEmpty(outputPath))
            {
                throw new ArgumentException("Must provide value for output file '-o <output file path>'");
            }
            Console.WriteLine(outputPath);
            TeeSquareWebApi.GenerateForAssemblies(typeof(OtherController).Assembly)
            .Configure(options =>
            {
                options.ReflectMethods = type =>
                                         type.IsInterface && (type.Namespace?.StartsWith("TeeSquare") ?? false);
            })
            .AddTypes(typeof(IApplicationHubClient), typeof(IApplicationHubServer))
            .WriteToFile(outputPath);
        }