public static void ThrowNewDataProviderAssertionExceptionWithNoEntries(ComponentTestContext testContext, string name)
 {
     ThrowNewDataProviderAssertionException(
         testContext,
         name,
         " with no entries",
         "in fact it had some");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionMessageTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="exceptionTestBuilder">Test builder of <see cref="IAndExceptionTestBuilder"/> type.</param>
 public ExceptionMessageTestBuilder(
     ComponentTestContext testContext,
     IAndExceptionTestBuilder exceptionTestBuilder)
     : base(testContext)
 {
     this.exceptionTestBuilder = exceptionTestBuilder;
     this.actualMessage = testContext.CaughtException.Message;
 }
 public object TryGetValue(Type type, ComponentTestContext testContext)
     => Reflection.AreAssignable(baseHttpContextType, type) // HttpContext
         ? testContext.HttpContext
         : Reflection.AreAssignable(baseHttpRequestType, type) // HttpRequest
         ? testContext.HttpRequest
         : Reflection.AreAssignable(baseHttpResponseType, type) // HttpResponse
         ? (object)testContext.HttpResponse
         : null;
 /// <summary>
 /// Initializes a new instance of the <see cref="BadRequestErrorMessageTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="actualMessage">Actual text error message received from bad request result.</param>
 /// <param name="badRequestTestBuilder">Bad request test builder.</param>
 public BadRequestErrorMessageTestBuilder(
     ComponentTestContext testContext,
     string actualMessage,
     IAndBadRequestTestBuilder badRequestTestBuilder)
     : base(testContext)
 {
     this.actualMessage = actualMessage;
     this.badRequestTestBuilder = badRequestTestBuilder;
 }
 public static void ValidateDataProviderNumberOfEntries(ComponentTestContext testContext, string name, int? expectedCount, int actualCount)
 {
     if (actualCount == 0
         || (expectedCount != null && actualCount != expectedCount))
     {
         ThrowNewDataProviderAssertionException(
             testContext,
             name,
             expectedCount == null ? " entries" : $" with {expectedCount} {(expectedCount != 1 ? "entries" : "entry")}",
             expectedCount == null ? "none were found" : $"in fact contained {actualCount}");
     }
 }
 public static void ThrowNewDataProviderAssertionException(
     ComponentTestContext testContext,
     string name,
     string expectedValue,
     string actualValue)
 {
     throw new DataProviderAssertionException(string.Format(
         "{0} to have {1}{2}, but {3}.",
         testContext.ExceptionMessagePrefix,
         name,
         expectedValue,
         actualValue));
 }
Example #7
0
 public object TryGetValue(Type type, ComponentTestContext testContext)
 => Reflection.AreAssignable(exceptionType, type)     // Exception
         ? testContext.CaughtException
         : null;
 public object TryGetValue(Type type, ComponentTestContext testContext)
     => Reflection.AreAssignable(exceptionType, type) // Exception
         ? testContext.CaughtException
         : null;
 public object TryGetValue(Type type, ComponentTestContext testContext)
     => Reflection.AreAssignable(serviceProviderType, type) // ServiceProvider
         ? testContext.HttpContext.RequestServices
         : null;
 public object TryGetValue(Type type, ComponentTestContext testContext)
 => testContext.MethodResult switch
 {
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseAttributesTestBuilder{TAttributesBuilder}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseAttributesTestBuilder(ComponentTestContext testContext)
     : base(testContext)
 {
 }
        public static void ValidateInvocationResultType(
            ComponentTestContext testContext,
            Type typeOfExpectedReturnValue,
            bool canBeAssignable = false,
            bool allowDifferentGenericTypeDefinitions = false,
            Type typeOfActualReturnValue = null)
        {
            InvocationValidator.CheckForException(testContext.CaughtException, testContext.ExceptionMessagePrefix);

            var typeInfoOfExpectedReturnValue = typeOfExpectedReturnValue.GetTypeInfo();

            var typeOfResult = typeOfActualReturnValue ?? testContext.MethodResult?.GetType();

            if (typeOfResult == null)
            {
                ThrowNewInvocationResultAssertionException(
                    testContext,
                    typeOfExpectedReturnValue.ToFriendlyTypeName(),
                    "null");
            }

            var typeInfoOfResult = typeOfResult.GetTypeInfo();

            var isAssignableCheck = canBeAssignable && Reflection.AreNotAssignable(typeOfExpectedReturnValue, typeOfResult);

            if (isAssignableCheck && allowDifferentGenericTypeDefinitions &&
                Reflection.IsGeneric(typeOfExpectedReturnValue) && Reflection.IsGenericTypeDefinition(typeOfExpectedReturnValue))
            {
                isAssignableCheck = Reflection.AreAssignableByGeneric(typeOfExpectedReturnValue, typeOfResult);

                if (!isAssignableCheck && !typeInfoOfResult.IsGenericType)
                {
                    isAssignableCheck = true;
                }
                else
                {
                    isAssignableCheck =
                        !Reflection.ContainsGenericTypeDefinitionInterface(typeOfExpectedReturnValue, typeOfResult);
                }
            }

            var strictlyEqualCheck = !canBeAssignable && Reflection.AreDifferentTypes(typeOfExpectedReturnValue, typeOfResult);

            var invalid = isAssignableCheck || strictlyEqualCheck;

            if (invalid && typeInfoOfExpectedReturnValue.IsGenericTypeDefinition && typeInfoOfResult.IsGenericType)
            {
                var actionResultGenericDefinition = typeInfoOfResult.GetGenericTypeDefinition();
                if (actionResultGenericDefinition == typeOfExpectedReturnValue)
                {
                    invalid = false;
                }
            }

            if (invalid && typeInfoOfExpectedReturnValue.IsGenericType && typeInfoOfResult.IsGenericType)
            {
                invalid = !Reflection.AreAssignableByGeneric(typeOfExpectedReturnValue, typeOfResult);
            }

            if (invalid)
            {
                ThrowNewInvocationResultAssertionException(
                    testContext,
                    typeOfExpectedReturnValue.ToFriendlyTypeName(),
                    typeOfResult.ToFriendlyTypeName());
            }
        }
 public static void ValidateInvocationResultType <TExpectedType>(
     ComponentTestContext testContext,
     bool canBeAssignable = false,
     bool allowDifferentGenericTypeDefinitions = false)
 => ValidateInvocationResultType(testContext, typeof(TExpectedType), canBeAssignable, allowDifferentGenericTypeDefinitions);
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseDataProviderTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="dataProviderName">Name of the data provider.</param>
 protected BaseDataProviderTestBuilder(ComponentTestContext testContext, string dataProviderName)
     : base(testContext)
 {
     CommonValidator.CheckForNotWhiteSpaceString(dataProviderName);
     this.DataProviderName = dataProviderName;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpResponseTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 public HttpResponseTestBuilder(ComponentTestContext testContext)
     : base(testContext)
 {
     this.httpResponse = testContext.HttpResponse;
 }
 public object TryGetValue(Type type, ComponentTestContext testContext)
     => Reflection.AreAssignable(controllerAttributesType, type) // ControllerAttributes
         ? new ControllerAttributes(testContext.ComponentAttributes)
         : Reflection.AreAssignable(actionAttributesType, type) // ActionAttributes
         ? (object)new ActionAttributes(testContext.MethodAttributes)
         : null;
 /// <summary>
 /// Initializes a new instance of the <see cref="ShouldThrowTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 public ShouldThrowTestBuilder(ComponentTestContext testContext)
     : base(testContext)
 {
     this.exceptionTestBuilder = new ExceptionTestBuilder(this.TestContext);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseAttributesTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseAttributesTestBuilder(ComponentTestContext testContext)
     : base(testContext)
 {
     this.Validations = new List<Action<IEnumerable<object>>>();
 }
Example #19
0
 public object TryGetValue(Type type, ComponentTestContext testContext)
 => Reflection.AreAssignable(serviceProviderType, type)     // ServiceProvider
         ? testContext.HttpContext.RequestServices
         : null;
 public object TryGetValue(Type type, ComponentTestContext testContext)
     => Reflection.AreAssignable(viewComponentAttributesType, type) // ViewComponentAttributes
         ? new ViewComponentAttributes(testContext.ComponentAttributes)
         : null;
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseDataProviderTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="dataProviderName">Name of the data provider.</param>
 protected BaseDataProviderWithStringKeyTestBuilder(ComponentTestContext testContext, string dataProviderName)
     : base(testContext, dataProviderName)
 {
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryCacheTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 public MemoryCacheTestBuilder(ComponentTestContext testContext)
     : base(testContext)
 {
     this.memoryCache = this.GetMemoryCache();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthenticationPropertiesTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
 public AuthenticationPropertiesTestBuilder(ComponentTestContext testContext)
     :base(testContext)
 {
     this.authenticationProperties = new AuthenticationProperties();
     this.validations = new List<Action<AuthenticationProperties, AuthenticationProperties>>();
 }
 public AndTestBuilder(ComponentTestContext testContext)
     : base(testContext)
 {
 }
 protected BaseTestBuilderWithComponentBuilder(ComponentTestContext testContext)
     : base(testContext)
 {
 }