|
| 1 | +namespace MyTested.AspNetCore.Mvc |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using Builders.Contracts.Application; |
| 5 | + using Builders.Contracts.Controllers; |
| 6 | + using Builders.Contracts.ViewComponents; |
| 7 | + using Internal.Application; |
| 8 | + |
| 9 | + /// <summary> |
| 10 | + /// Provides methods to specify an ASP.NET Core MVC test case. |
| 11 | + /// </summary> |
| 12 | + public static class MyMvc |
| 13 | + { |
| 14 | + static MyMvc() |
| 15 | + { |
| 16 | + TestApplication.TryInitialize(); |
| 17 | + } |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Configures the tested application with the provided startup class. |
| 21 | + /// </summary> |
| 22 | + /// <typeparam name="TStartup">Type of startup class.</typeparam> |
| 23 | + /// <returns>Builder of <see cref="IApplicationConfigurationBuilder"/> type.</returns> |
| 24 | + public static IApplicationConfigurationBuilder StartsFrom<TStartup>() |
| 25 | + where TStartup : class |
| 26 | + { |
| 27 | + return new MyApplication(typeof(TStartup)); |
| 28 | + } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Starts a controller test. |
| 32 | + /// </summary> |
| 33 | + /// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam> |
| 34 | + /// <returns>Test builder of <see cref="IControllerBuilder{TController}"/> type.</returns> |
| 35 | + public static IControllerBuilder<TController> Controller<TController>() |
| 36 | + where TController : class |
| 37 | + { |
| 38 | + return new MyController<TController>(); |
| 39 | + } |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Starts a controller test. |
| 43 | + /// </summary> |
| 44 | + /// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam> |
| 45 | + /// <param name="controller">Instance of the ASP.NET Core MVC controller to test.</param> |
| 46 | + /// <returns>Test builder of <see cref="IControllerBuilder{TController}"/> type.</returns> |
| 47 | + public static IControllerBuilder<TController> Controller<TController>(TController controller) |
| 48 | + where TController : class |
| 49 | + { |
| 50 | + return new MyController<TController>(controller); |
| 51 | + } |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Starts a controller test. |
| 55 | + /// </summary> |
| 56 | + /// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam> |
| 57 | + /// <param name="construction">Construction function returning the instantiated controller.</param> |
| 58 | + /// <returns>Test builder of <see cref="IControllerBuilder{TController}"/> type.</returns> |
| 59 | + public static IControllerBuilder<TController> Controller<TController>(Func<TController> construction) |
| 60 | + where TController : class |
| 61 | + { |
| 62 | + return new MyController<TController>(construction); |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Starts a view component test. |
| 67 | + /// </summary> |
| 68 | + /// <typeparam name="TViewComponent">Class representing ASP.NET Core MVC view component.</typeparam> |
| 69 | + /// <returns>Test builder of <see cref="IViewComponentBuilder{TViewComponent}"/> type.</returns> |
| 70 | + public static IViewComponentBuilder<TViewComponent> ViewComponent<TViewComponent>() |
| 71 | + where TViewComponent : class |
| 72 | + { |
| 73 | + return new MyViewComponent<TViewComponent>(); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Starts a view component test. |
| 78 | + /// </summary> |
| 79 | + /// <typeparam name="TViewComponent">Class representing ASP.NET Core MVC view component.</typeparam> |
| 80 | + /// <param name="viewComponent">Instance of the ASP.NET Core MVC view component to use.</param> |
| 81 | + /// <returns>Test builder of <see cref="IViewComponentBuilder{TViewComponent}"/> type.</returns> |
| 82 | + public static IViewComponentBuilder<TViewComponent> ViewComponent<TViewComponent>(TViewComponent viewComponent) |
| 83 | + where TViewComponent : class |
| 84 | + { |
| 85 | + return new MyViewComponent<TViewComponent>(viewComponent); |
| 86 | + } |
| 87 | + |
| 88 | + /// <summary> |
| 89 | + /// Starts a view component test. |
| 90 | + /// </summary> |
| 91 | + /// <typeparam name="TViewComponent">Class representing ASP.NET Core MVC view component.</typeparam> |
| 92 | + /// <param name="construction">Construction function returning the instantiated view component.</param> |
| 93 | + /// <returns>Test builder of <see cref="IViewComponentBuilder{TViewComponent}"/> type.</returns> |
| 94 | + public static IViewComponentBuilder<TViewComponent> ViewComponent<TViewComponent>(Func<TViewComponent> construction) |
| 95 | + where TViewComponent : class |
| 96 | + { |
| 97 | + return new MyViewComponent<TViewComponent>(construction); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments