public static ValidationMessageCollection ValidateRequest(IAssertable assertable, params object[] dependentServices)
        {
            if (assertable == null)
                throw new ArgumentNullException(nameof(assertable), "request is null.");

            return assertable.Assert(dependentServices);
        }
示例#2
0
        /// <summary>
        /// Instanciates the given harness and makes it accessible.
        /// Throws exceptions, if
        ///  ...type is not found
        ///  ... type is not a harness
        ///  ... assembly hosting the harness is not found.
        /// </summary>
        /// <param name="usedHarness"></param>
        /// <param name="assemblyName"></param>
        public static void BeginTestCase(string usedHarness, string assemblyName)
        {
            Type harness;

            logger.Info("Load harness " + usedHarness + " from " + assemblyName);
            if (!string.IsNullOrWhiteSpace(assemblyName))
            {
                var assembly = System.Reflection.Assembly.LoadFrom(assemblyName);
                harness = assembly.GetType(usedHarness);
            }
            else
            {
                // Find implementing testharness
                harness = Type.GetType(usedHarness, null, null, true);
            }

            var implementsTestharness = harness.GetInterface("ITestHarness") != null;

            if (!implementsTestharness)
            {
                var ex = new InvalidCastException("The type " + usedHarness + " is not a testharness.");
                logger.ErrorException("Not a harness!", ex);
                throw ex;
            }

            // Instanciate Testharness, ready to go :)
            theHarness   = harness.GetConstructor(new Type[0]).Invoke(new object[0]) as ITestHarness;
            testContext  = IOC.Resolve <ITestContext>();
            testCaseCode = null;
            testResults  = new List <TestResult>();
        }
示例#3
0
 public static void ExecuteAssert <T>(this IAssertable <T> assertable, Func <T, bool> action, Func <T, IErrorMessageBuilder, IErrorMessageBuilder> messageBuilder) where T : ControlBase
 {
     assertable.ExecuteAssert(
         (x) => new BoolCheckResult(action(x)),
         (x, y, z) => messageBuilder(x, y)
         );
 }
示例#4
0
        public static void Init()
        {
            te           = IOC.Resolve <ITestEnvironment>();
            testContext  = IOC.Resolve <ITestContext>();
            testCaseCode = null;
            theHarness   = null;

            logger.Info("MutaGen Api - Init");
        }
示例#5
0
 public SpecFactoryFixture()
 {
     SpecFactory           = Substitute.For <ISpecFactory <object> >();
     BehaviourSpec         = Substitute.For <IBehaviourSpec <object> >();
     AssertionSpec         = Substitute.For <IAssertionSpec <object> >();
     AssertionSpecWithData = Substitute.For <IAssertionSpec <object, string> >();
     Assertable            = Substitute.For <IAssertable <object> >();
     AssertableWithData    = Substitute.For <IAssertable <object, string> >();
 }
示例#6
0
        public static ValidationMessageCollection ValidateRequest(IAssertable assertable, params object[] dependentServices)
        {
            if (assertable == null)
            {
                throw new ArgumentNullException(nameof(assertable), "request is null.");
            }

            return(assertable.Assert(dependentServices));
        }
 public PropertyControlContext(
     IAssertable <TControl> subject,
     Func <TControl, T> propertyPicker,
     string target
     )
 {
     this.subject = subject;
     this.target  = target;
     this.compiledPropertyPicker = propertyPicker;
 }
示例#8
0
 private Exception DoAssert(IAssertable assert)
 {
     try
     {
         assert.Assert();
         return(null);
     }
     catch (Exception e)
     {
         return(e);
     }
 }
示例#9
0
 private static IEnumerable <string> FormatExcuse(IAssertable failure, string excuseIcon)
 {
     if (failure.Failed)
     {
         var message    = FormatExcuseMessage(failure, excuseIcon);
         var stacktrace = failure.Excuse.StackTrace.SplitLines();
         return(message.Concat(stacktrace));
     }
     else
     {
         return(Array.Empty <string>());
     }
 }
示例#10
0
        private static IEnumerable <string> FormatAssertable(this IAssertable failure, string passIcon, string failIcon, string excuseIcon, int indent)
        {
            var header = GetHeader(failure, passIcon, failIcon);
            var excuse = FormatExcuse(failure, excuseIcon);

            var excuseIndentSize = header.BoundMorpheme.Length + header.Joiner.Length;
            var excusePrefix     = " ".Repeat(excuseIndentSize) + "| ";

            return(header
                   .Render()
                   .SplitLines()
                   .Concat(excuse.Prefix(excusePrefix))
                   .Indent(indent));
        }
示例#11
0
        /*public void Assert<T>(OneParamAssertTypes AssertType, T param, AssertionInfo assertion)
         * {
         *      IAssertable assert = getAssertFromParams(AssertType, param, assertion);
         *      var result = GetAssertResult(assert, assertion);
         *      Assertions.Add(result);
         * }
         *
         *
         * public void Assert<T>(TwoParamsAssertTypes AssertType, T firstParam, T secondParam, AssertionInfo assertion)
         * {
         *      IAssertable assert = getAssertFromParams(AssertType, firstParam, secondParam, assertion);
         *      var result = GetAssertResult(assert, assertion);
         *      Assertions.Add(result);
         * }
         *
         * public void Assert<T>(TwoParamsAssertWithDeltaTypes AssertType, double firstParam, double secondParam, double delta, AssertionInfo assertion)
         * {
         *      IAssertable assert = getAssertFromParams(AssertType, firstParam, secondParam, delta, assertion);
         *      var result = GetAssertResult(assert, assertion);
         *      Assertions.Add(result);
         * }
         *
         *
         * public void Assert(ZeroParamAssertTypes AssertType, AssertionInfo assertion)
         * {
         *      IAssertable assert = getAssertFromParams(AssertType, assertion);
         *      var result = GetAssertResult(assert, assertion);
         *      Assertions.Add(result);
         * }*/

        protected AssertionResult GetAssertResult(IAssertable assert, AssertionInfo assertion)
        {
            var exception = DoAssert(assert);

            if (exception == null)
            {
                assertion.Result = AssertionResults.Passed;
                return(new AssertionResult(assert, assertion));
            }
            else
            {
                assertion.Result          = AssertionResults.Failed;
                assertion.AssertException = exception;
                ThrowExceptionIfNeeded(Settings.IsSoftAssertEnabled, exception);
                return(new AssertionResult(assert, assertion));
            }
        }
示例#12
0
        private void RunTestIteration <T>(IAssertable <T> obj, KarmaOptions options)
        {
            byte[] bytes;
            using (var mStream = new MemoryStream())
                using (var serializer = new KarmaSerializer(mStream, options))
                {
                    serializer.Write(obj);
                    bytes = mStream.ToArray();
                }

            using (var mStream = new MemoryStream(bytes))
                using (var deserializer = new KarmaDeserializer(mStream))
                {
                    var resultObj = deserializer.Read <T>();
                    obj.AssertEqualsTo(resultObj);
                }
        }
        /// <summary>
        /// Defines the return value for a specific method expectation.
        /// </summary>
        /// <typeparam name="TReturn">Type of the return value.</typeparam>
        /// <param name="assertable">Reference to <see cref="IAssertable" /> interface.</param>
        /// <param name="value">Any object value.</param>
        /// <returns>Reference to <see cref="IMustBeCalled" /> interface</returns>
        public static IAssertable Returns <TReturn>(this IAssertable assertable, TReturn value)
        {
            return(ProfilerInterceptor.GuardInternal(() =>
            {
                var callPattern = ((IMethodMock)assertable).CallPattern.Clone();
                var func = assertable as IFunc <TReturn>;
                if (func == null)
                {
                    var methodReturnType = callPattern.Method.GetReturnType();
                    var returnTypeMessage = methodReturnType.IsAssignableFrom(typeof(TReturn))
                                                ? String.Format("The arranged function is not set up to return a value of type {0}.  If this is a non-public arrangement then make sure that the call to Arrange specifies the correct return type, e.g. Mock.NonPublic.Arrange<int>(...) if the method returns 'int'.", typeof(TReturn))
                                                : String.Format("The chained return value type '{0}' is not compatible with the arranged method's return type '{1}'", typeof(TReturn), methodReturnType);

                    throw new MockException(returnTypeMessage);
                }

                var methodMock = MockingContext.CurrentRepository.Arrange(callPattern, () => { return new FuncExpectation <TReturn>(); });
                ((IMethodMock)assertable).IsSequential = true;
                ((IMethodMock)methodMock).IsSequential = true;
                return methodMock.Returns(value);
            }));
        }
 public static LabelAssertions ExpectTo(this IAssertable <Label> input)
 {
     return(new LabelAssertions(input));
 }
示例#15
0
        public void Run_ShouldUpgrade(bool shouldUpgrade, bool isOutdatedEmpty)
        {
            const string repository = "test-repository";

            IEnumerable <WorkflowInfo> infos = new List <WorkflowInfo>();
            var workflowServiceMock          = Mock.Create <IWorkflowService>();

            Mock.Arrange(() => workflowServiceMock.GetWorkflows(repository)).Returns(infos);

            IDictionary <WorkflowInfo, IEnumerable <GitHubAction> > outdated;
            var actionPrinterMock = Mock.Create <IActionPrinter>();

            if (isOutdatedEmpty)
            {
                outdated = new Dictionary <WorkflowInfo, IEnumerable <GitHubAction> >();
                Mock.Arrange(() => actionPrinterMock.PrintHeader(Arg.AnyString, Arg.AnyString))
                .OccursNever();
                Mock.Arrange(() => actionPrinterMock.Print(Arg.IsAny <IEnumerable <GitHubAction> >()))
                .OccursNever();
                Mock.Arrange(() => actionPrinterMock.PrintNoUpgradeNeeded()).DoNothing().OccursOnce();
            }
            else
            {
                const string fileName       = ".github/test-file";
                var          actionWorkflow = new ActionWorkflow {
                    Name = "test-action-workflow-name"
                };
                var actions = new List <GitHubAction>();
                outdated = new Dictionary <WorkflowInfo, IEnumerable <GitHubAction> >
                {
                    { new WorkflowInfo($"some-folder/{fileName}", actionWorkflow), actions }
                };
                Mock.Arrange(() => actionPrinterMock.PrintHeader(actionWorkflow.Name, fileName))
                .DoNothing().OccursOnce();
                Mock.Arrange(() => actionPrinterMock.Print(actions))
                .DoNothing().OccursOnce();
                Mock.Arrange(() => actionPrinterMock.PrintNoUpgradeNeeded()).OccursNever();
            }

            var gitHubServiceMock = Mock.Create <IGitHubService>();

            Mock.Arrange(() => gitHubServiceMock.GetOutdated(infos)).Returns(outdated);

            var progressBarMock = Mock.Create <Ghacu.Runner.Cli.Progress.IProgressBar>();

            Mock.Arrange(() => progressBarMock.Report(0.25)).DoNothing().OccursOnce();
            Mock.Arrange(() => progressBarMock.Dispose()).DoNothing().OccursOnce();

            var streamerMock = Mock.Create <IStreamer>();

            Mock.Arrange(() => streamerMock.Push <CliService>(Arg.IsAny <StreamOptions>())).OccursNever();

            IAssertable pushEmptySetup  = Mock.Arrange(() => streamerMock.PushEmpty()).DoNothing();
            IAssertable runUpgradeSetup = Mock.Arrange(() => actionPrinterMock.PrintRunUpgrade()).DoNothing();

            if (isOutdatedEmpty)
            {
                pushEmptySetup.OccursNever();
                runUpgradeSetup.OccursNever();
            }
            else if (!shouldUpgrade)
            {
                pushEmptySetup.OccursOnce();
                runUpgradeSetup.OccursOnce();
            }

            var service = new CliService(
                workflowServiceMock, gitHubServiceMock, actionPrinterMock, null, streamerMock);

            service.Run(repository, shouldUpgrade);

            Mock.Assert(workflowServiceMock);
            Mock.Assert(gitHubServiceMock);
            Mock.Assert(actionPrinterMock);
            Mock.Assert(streamerMock);
        }
示例#16
0
 public LabelAssertions(IAssertable <Label> subject)
     : base(subject)
 {
 }
示例#17
0
 public ControlListAllItemAssertions(IAssertable <ControlListBase <T> > subject)
 {
     this.subject = subject;
 }
示例#18
0
 public ButtonAssertions(IAssertable <Button> button)
     : base(button)
 {
 }
 public static LinkAssertions ExpectTo(this IAssertable <Link> input)
 {
     return(new LinkAssertions(input));
 }
 public static TextAreaAssertions ExpectTo(this IAssertable <TextArea> input)
 {
     return(new TextAreaAssertions(input));
 }
 public static CompoundControlAssertions <CompoundControl> ExpectTo(this IAssertable <CompoundControl> control)
 {
     return(new CompoundControlAssertions <CompoundControl>(control));
 }
示例#22
0
 protected void LogAssertIfNeeded(IAssertable assert)
 {
 }
 public static ComboBoxAssertions ExpectTo(this IAssertable <ComboBox> input)
 {
     return(new ComboBoxAssertions(input));
 }
 public static InputAssertions ExpectTo(this IAssertable <Input> input)
 {
     return(new InputAssertions(input));
 }
示例#25
0
 public static void CommitTestCaseCode(IAssertable code)
 {
     testCaseCode = code;
 }
 public static GenericAssertions <ModalBase> ExpectTo(this IAssertable <ModalBase> input)
 {
     return(new GenericAssertions <ModalBase>(input));
 }
 public static ButtonAssertions ExpectTo(this IAssertable <Button> input)
 {
     return(new ButtonAssertions(input));
 }
 public CheckBoxAssertions(IAssertable <Checkbox> subject)
     : base(subject)
 {
 }
 public static ControlBaseAssertions ExpectTo(this IAssertable <ControlBase> input)
 {
     return(new ControlBaseAssertions(input));
 }
 public static SelectAssertions ExpectTo(this IAssertable <Select> input)
 {
     return(new SelectAssertions(input));
 }
 public static CheckBoxAssertions ExpectTo(this IAssertable <Checkbox> input)
 {
     return(new CheckBoxAssertions(input));
 }