Esempio n. 1
0
        /// <summary>
        /// Verifies that the provided object raised INotifyPropertyChanged.PropertyChanged
        /// as a result of executing the given test code.
        /// </summary>
        /// <param name="object">The object which should raise the notification</param>
        /// <param name="propertyName">The property name for which the notification should be raised</param>
        /// <param name="testCode">The test code which should cause the notification to be raised</param>
        /// <exception cref="PropertyChangedException">Thrown when the notification is not raised</exception>
        public static void PropertyChanged(this IAssert assert, INotifyPropertyChanged @object, string propertyName, Action testCode)
        {
            Guard.ArgumentNotNull("object", @object);
            Guard.ArgumentNotNull("testCode", testCode);

            bool propertyChangeHappened = false;

            PropertyChangedEventHandler handler = (sender, args) =>
            {
                if (propertyName.Equals(args.PropertyName, StringComparison.OrdinalIgnoreCase))
                {
                    propertyChangeHappened = true;
                }
            };

            @object.PropertyChanged += handler;

            try
            {
                testCode();
                if (!propertyChangeHappened)
                {
                    assert.Fail(new PropertyChangedException(propertyName));
                }
                assert.Okay();
            }
            finally
            {
                @object.PropertyChanged -= handler;
            }
        }
        public CPlusPlusSWIGBindingGeneratorWorksTest(IAssert assert, ICategorize categorize)
            : base(assert)
        {
            _assert = assert;

            categorize.Method("CPlusPlusPotentialSWIGInstallation", () => GenerationIsCorrect());
        }
Esempio n. 3
0
 public static void True(this IAssert a, bool actual, string comment = "")
 {
     if (!actual)
     {
         throw new TectureValidationException(comment ?? $"{nameof(AssertExtensions.True)} failed");
     }
 }
Esempio n. 4
0
        public RenderPipelineTests(IAssert assert, IThreadControl threadControl, ITestAttachment testAttachment)
        {
            _assert         = assert;
            _testAttachment = testAttachment;

            threadControl.RequireTestsToRunOnMainThread();
        }
Esempio n. 5
0
 public static void NotNull <T>(this IAssert a, T actual, string comment = "") where T : class
 {
     if (actual == null)
     {
         throw new TectureValidationException(comment ?? $"{nameof(AssertExtensions.NotNull)} failed");
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Verifies that the given collection contains only a single
        /// element of the given type which matches the given predicate. The
        /// collection may or may not contain other values which do not
        /// match the given predicate.
        /// </summary>
        /// <typeparam name="T">The collection type.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="predicate">The item matching predicate.</param>
        /// <returns>The single item in the filtered collection.</returns>
        /// <exception cref="SingleException">Thrown when the filtered collection does
        /// not contain exactly one element.</exception>
        public static T Single <T>(this IAssert assert, IEnumerable <T> collection, Predicate <T> predicate)
        {
            Guard.ArgumentNotNull("collection", collection);
            Guard.ArgumentNotNull("predicate", predicate);

            int count  = 0;
            T   result = default(T);

            foreach (T item in collection)
            {
                if (predicate(item))
                {
                    result = item;
                    ++count;
                }
            }

            if (count != 1)
            {
                assert.Fail(new SingleException(count));
            }

            assert.Okay();

            return(result);
        }
Esempio n. 7
0
        public override void Execute(IAssert assert)
        {
            var data = SetUp();
            var typesToTest = GetTypesToTest(data);
            if (typesToTest.Length == 0)
            {
                assert.Inconclusive(
                    "No types found to apply the convention to. Make sure the Types predicate is correct and that the right assemblies to scan are specified.");
            }
            var invalidItems = Array.FindAll(typesToTest, t => data.Must(t) == false);

            var message = new StringBuilder();
            message.AppendLine(data.Description ?? "Invalid types found");
            foreach (var invalidType in invalidItems)
            {
                message.Append('\t');
                data.ItemDescription(invalidType, message);
            }
            if (data.HasApprovedExceptions)
            {
                Approve(message.ToString());
            }
            else
            {
                assert.AreEqual(0, invalidItems.Count(), message.ToString());
            }
        }
 public TestAttributionHandler(DeviceUtil deviceUtil, IAssert assert, TargetPlatform targetPlatform)
     : base(deviceUtil, assert)
 {
     TargetPlatform                     = targetPlatform;
     TestActivityPackage.Assert         = Assert;
     TestActivityPackage.TargetPlatform = TargetPlatform;
 }
 public TestAttributionHandler(DeviceUtil deviceUtil, IAssert assert, TargetPlatform targetPlatform)
     : base(deviceUtil, assert)
 {
     TargetPlatform = targetPlatform;
     TestActivityPackage.Assert = Assert;
     TestActivityPackage.TargetPlatform = TargetPlatform;
 }
Esempio n. 10
0
        public static void Equal(this IAssert a, string actual, string expected, string comment = "")
        {
            if (actual == null && expected == null)
            {
                return;
            }
            if (actual != null && expected == null)
            {
                throw new TectureValidationException(comment ??
                                                     $"{nameof(AssertExtensions.Equal)} failed:actual is not null whether expected is");
            }
            if (actual == null && expected != null)
            {
                throw new TectureValidationException(comment ??
                                                     $"{nameof(AssertExtensions.Equal)} failed:actual is null whether expected is not");
            }

            if (string.Compare(actual, expected, StringComparison.InvariantCultureIgnoreCase) != 0)
            {
                actual   = actual.Replace("\r\n", "\n");
                expected = expected.Replace("\r\n", "\n");
                if (string.Compare(actual, expected, StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    throw new TectureValidationException((comment ?? $"{nameof(AssertExtensions.Equal)} failed:") +
                                                         $": expected \r\n [{expected}] \r\n but got \r\n [{actual}]");
                }
            }
        }
Esempio n. 11
0
        public static IAssert <TSubject, TResult, TVars, TSequence> ItCallsInOrder <TSubject, TResult, TVars, TSequence> (
            this IAssert <TSubject, TResult, TVars, TSequence> assert,
            string text,
            Assertion <TSubject, TResult, TVars, TSequence> orderedAssertion)
        {
            var controller = assert.GetTestController();

            controller.Replace <Act>(
                (x, originalAction) =>
            {
                var scope = Fake.CreateScope();
                x[Key]    = scope;
                using (scope)
                {
                    originalAction();
                }
            });
            controller.AddAssertion(
                "calls in order " + text,
                x =>
            {
                var scope = (IFakeScope)x[Key];
                using (scope.OrderedAssertions())
                {
                    orderedAssertion(x);
                }
            });
            return(assert);
        }
Esempio n. 12
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>
 /// </summary>
 /// <param name="assert"></param>
 /// <returns></returns>
 public static IAssert <IEnumerable <TAssert> > NotAny <TAssert>(this IAssert <IEnumerable <TAssert> > assert, Func <TAssert, bool> predicate, string message = null)
 {
     assert.NotNull()
     .Then(s => s.Any(predicate))
     .False(message ?? "已存在匹配项");
     return(assert);
 }
        public CPlusPlusExternalPlatformReferenceWorksTest(IAssert assert, ICategorize categorize)
            : base(assert)
        {
            _assert = assert;

            categorize.Method("CPlusPlusPotentialSWIGInstallation", () => GenerationIsCorrect());
        }
Esempio n. 14
0
        public static void Collection <T>(this IAssert a, IEnumerable <T> source, string explanation, params Action <T>[] validators)
        {
            var curValidatorIndex = 0;

            foreach (var item in source)
            {
                if (curValidatorIndex + 1 > validators.Length)
                {
                    throw new TectureValidationException($"{explanation}{(string.IsNullOrEmpty(explanation)?"":": ")} Not all elements present in collection or order is different.");
                }

                try
                {
                    validators[curValidatorIndex](item);
                }
                catch (Exception ex)
                {
                    throw new TectureValidationException($"{explanation}{(string.IsNullOrEmpty(explanation)?"":": ")} Validation for item #{curValidatorIndex} failed. See inner exception for details", ex);
                }

                curValidatorIndex++;
            }

            if (curValidatorIndex != validators.Length)
            {
                throw new TectureValidationException($"{explanation}{(string.IsNullOrEmpty(explanation)?"":": ")} Collection contains less than {validators.Length} items");
            }
        }
Esempio n. 15
0
        public CategoryTestA(IAssert assert, ICategorize categorize)
        {
            _assert = assert;

            categorize.Method("Functional", TestMethodA);
            categorize.Method("Functional", TestMethodB);
        }
Esempio n. 16
0
 public static IAssert <TSubject, TResult, TVars, TSequence> ItThrows <TSubject, TResult, TVars, TSequence> (
     this IAssert <TSubject, TResult, TVars, TSequence> assert,
     Type exceptionType,
     string message)
 {
     return(assert.ItThrows(exceptionType, x => message));
 }
Esempio n. 17
0
        public static IAssert <TSubject, TResult, TVars, TSequence> ItThrows <TSubject, TResult, TVars, TSequence> (
            this IAssert <TSubject, TResult, TVars, TSequence> assert,
            Type exceptionType,
            [CanBeNull] Func <TVars, string> messageProvider           = null,
            [CanBeNull] Func <TVars, Exception> innerExceptionProvider = null)
        {
            var controller = assert.GetTestController();

            controller.AddAssertion(
                "Throws " + exceptionType.Name,
                x =>
            {
                AssertionHelper.AssertInstanceOfType("Exception", exceptionType, x.Exception);
                if (messageProvider != null)
                {
                    AssertionHelper.AssertExceptionMessage(messageProvider(x.Vars), x.Exception);
                }
                if (innerExceptionProvider != null)
                {
                    AssertionHelper.AssertObjectEquals("InnerException", innerExceptionProvider(x.Vars), x.Exception.AssertNotNull().InnerException);
                }
            },
                c_expectException);
            return(assert);
        }
Esempio n. 18
0
        public TrainingEpochTester <TTrainingMethod> ExpectNeuralNetworkState(Action <NeuralNetworkAssertor.Builder> action)
        {
            var builder = new NeuralNetworkAssertor.Builder();

            action.Invoke(builder);
            neuralNetworkAssertor = builder.Build();
            return(this);
        }
Esempio n. 19
0
 public static void Equal(this IAssert a, ushort actual, ushort expected, string comment = "")
 {
     if (actual != expected)
     {
         throw new TectureValidationException((comment ?? $"{nameof(AssertExtensions.Equal)} failed:") +
                                              $": expected [{expected}] but got [{actual}]");
     }
 }
Esempio n. 20
0
 public SnapperCore(IAssert asserter, ISnapStore store, IPathResolver resolver, ISnapUpdateDecider snapUpdateDecider, ISnapComparer comparer)
 {
     _asserter          = asserter;
     _store             = store;
     _pathResolver      = resolver;
     _snapUpdateDecider = snapUpdateDecider;
     _comparer          = comparer;
 }
Esempio n. 21
0
 public static void Init(IAssert assert    = null, ILogger logger = null,
                         Timeouts timeouts = null, IDriverFactory <IWebDriver> driverFactory = null, List <ISmartLocator> smartLocators = null)
 {
     Assert.Logger = Logger;
     SmartLocators = smartLocators ?? new List <ISmartLocator> {
         new SmartLocatorById(), new SmartLocatorByCss()
     };
 }
Esempio n. 22
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>为<see cref="bool.TrueString"/>
 /// </summary>
 /// <param name="assert"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IAssert <bool> True(this IAssert <bool> assert, string message)
 {
     if (!assert.Current)
     {
         throw new SAEException(StatusCodes.ParamesterInvalid, message);
     }
     return(assert);
 }
Esempio n. 23
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>不为空null或一连串空格
 /// </summary>
 /// <param name="assert"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IAssert <string> NotNullOrWhiteSpace(this IAssert <string> assert, string message)
 {
     if (string.IsNullOrWhiteSpace(assert.Current))
     {
         throw new SAEException(StatusCodes.ParamesterInvalid, message);
     }
     return(assert);
 }
Esempio n. 24
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>为null
 /// </summary>
 /// <param name="assert"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IAssert <TAssert> Null <TAssert>(this IAssert <TAssert> assert, string message)
 {
     if (assert.Current != null)
     {
         throw new SAEException(StatusCodes.ParamesterInvalid, message);
     }
     return(assert);
 }
Esempio n. 25
0
 public static void Equal(this IAssert a, object actual, object expected, string comment = "")
 {
     if (!object.ReferenceEquals(actual, expected))
     {
         throw new TectureValidationException((comment ?? $"{nameof(AssertExtensions.Equal)} failed:") +
                                              $": expected [{expected}] but got [{actual}]");
     }
 }
Esempio n. 26
0
 /// <summary>
 /// Verifies that a string contains a given sub-string, using the given comparison type.
 /// </summary>
 /// <param name="expectedSubstring">The sub-string expected to be in the string</param>
 /// <param name="actualString">The string to be inspected</param>
 /// <param name="comparisonType">The type of string comparison to perform</param>
 /// <exception cref="ContainsException">Thrown when the sub-string is not present inside the string</exception>
 public static void Contains(this IAssert assert, string expectedSubstring, string actualString, StringComparison comparisonType)
 {
     if (actualString == null || actualString.IndexOf(expectedSubstring, comparisonType) < 0)
     {
         assert.Fail(new ContainsException(expectedSubstring, actualString));
     }
     assert.Okay();
 }
Esempio n. 27
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>不为null
 /// </summary>
 /// <param name="assert"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IAssert <TAssert> NotNull <TAssert>(this IAssert <TAssert> assert, string message)
 {
     if (assert.Current == null)
     {
         throw new SAEException(StatusCodes.ResourcesNotExist, message);
     }
     return(assert);
 }
Esempio n. 28
0
 public static void Equal <T>(this IAssert a, T actual, T expected, string comment = "") where T : struct
 {
     if (!actual.Equals(expected))
     {
         throw new TectureValidationException((comment ?? $"{nameof(AssertExtensions.Equal)} failed:") +
                                              $": expected [{expected}] but got [{actual}]");
     }
 }
Esempio n. 29
0
 /// <summary>
 /// Verifies that two objects are the same instance.
 /// </summary>
 /// <param name="expected">The expected object instance</param>
 /// <param name="actual">The actual object instance</param>
 /// <exception cref="SameException">Thrown when the objects are not the same instance</exception>
 public static void Same(this IAssert assert, object expected, object actual)
 {
     if (!object.ReferenceEquals(expected, actual))
     {
         assert.Fail(new SameException(expected, actual));
     }
     assert.Okay();
 }
Esempio n. 30
0
 /// <summary>
 /// Verifies that an object reference is null.
 /// </summary>
 /// <param name="object">The object to be inspected</param>
 /// <exception cref="NullException">Thrown when the object reference is not null</exception>
 public static void Null(this IAssert assert, object @object)
 {
     if (@object != null)
     {
         assert.Fail(new NullException(@object));
     }
     assert.Okay();
 }
Esempio n. 31
0
        public static Validator <T, TResult> That <T, TResult>(this IAssert <T> assert, Expression <Func <T, TResult> > accessor)
        {
            var assertion = new Assertion <T, TResult>();

            assertion.Accessors.Add(new Accessor <T, TResult>(accessor));
            assert.Assertions.Add(assertion);
            return(new Validator <T, TResult>(assertion));
        }
Esempio n. 32
0
 /// <summary>
 /// Verifies that a string does not contain a given sub-string, using the current culture.
 /// </summary>
 /// <param name="expectedSubstring">The sub-string which is expected not to be in the string</param>
 /// <param name="actualString">The string to be inspected</param>
 /// <param name="comparisonType">The type of string comparison to perform</param>
 /// <exception cref="DoesNotContainException">Thrown when the sub-string is present inside the given string</exception>
 public static void DoesNotContain(this IAssert assert, string expectedSubstring, string actualString, StringComparison comparisonType)
 {
     if (actualString != null && actualString.IndexOf(expectedSubstring, comparisonType) >= 0)
     {
         assert.Fail(new DoesNotContainException(expectedSubstring));
     }
     assert.Okay();
 }
Esempio n. 33
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>不为null
 /// </summary>
 /// <param name="assert"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IAssert <TAssert> NotNull <TAssert>(this IAssert <TAssert> assert, string message) where TAssert : class
 {
     if (assert.Current == null)
     {
         throw new SAEException(message);
     }
     return(assert);
 }
Esempio n. 34
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>为<see cref="bool.TrueString"/>
 /// </summary>
 /// <param name="assert"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IAssert <bool> True(this IAssert <bool> assert, string message)
 {
     if (!assert.Current)
     {
         throw new SAEException(message);
     }
     return(assert);
 }
Esempio n. 35
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>不为空null或一连串空格
 /// </summary>
 /// <param name="assert"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IAssert <string> NotNullOrWhiteSpace(this IAssert <string> assert, string message)
 {
     if (string.IsNullOrWhiteSpace(assert.Current))
     {
         throw new SAEException(message);
     }
     return(assert);
 }
Esempio n. 36
0
 public static void Init(ILogger logger = null, IAssert assert = null,
     TimeoutSettings timeouts = null, IDriver<IWebDriver> driverFactory = null)
 {
     DriverFactory = driverFactory ?? new WebDriverFactory();
     Asserter = assert ?? new WebAssert();
     Timeouts = timeouts ?? new WebTimeoutSettings();
     Logger = logger ?? new LogAgregator(new NUnitLogger(), new Log4Net());
     MapInterfaceToElement.Init(DefaultInterfacesMap);
 }
Esempio n. 37
0
        public static void InitFromProperties(ILogger logger = null, IAssert assert = null,
            TimeoutSettings timeouts = null, IDriver<IWebDriver> driverFactory = null)
        {
            Init(logger, assert, timeouts, driverFactory);
            JDISettings.InitFromProperties();
            FillFromSettings(p => Domain = p, "Domain");
            FillFromSettings(p => DriverFactory.DriverPath = p, "DriversFolder");

            // FillFromSettings(p => DriverFactory.DriverVersion = p, "DriversVersion");
            // fillAction(p->getDriverFactory().getLatestDriver =
            //        p.toLowerCase().equals("true") || p.toLowerCase().equals("1"), "driver.getLatest");
            // fillAction(p->asserter.doScreenshot(p), "screenshot.strategy");
            FillFromSettings(p =>
            {
                p = p.ToLower();
                if (p.Equals("soft"))
                    p = "any,multiple";
                if (p.Equals("strict"))
                    p = "visible,single";
                if (p.Split(',').Length != 2) return;
                var parameters = p.Split(',').ToList();
                if (parameters.Contains("visible") || parameters.Contains("displayed"))
                    WebDriverFactory.ElementSearchCriteria = el => el.Displayed;
                if (parameters.Contains("any") || parameters.Contains("all"))
                    WebDriverFactory.ElementSearchCriteria = el => el != null;
                if (parameters.Contains("single") || parameters.Contains("displayed"))
                    OnlyOneElementAllowedInSearch = true;
                if (parameters.Contains("multiple") || parameters.Contains("displayed"))
                    OnlyOneElementAllowedInSearch = false;
            }, "SearchElementStrategy");

            FillFromSettings(p =>
            {
                string[] split = null;
                if (p.Split(',').Length == 2)
                    split = p.Split(',');
                if (p.ToLower().Split('x').Length == 2)
                    split = p.ToLower().Split('x');
                if (split != null)
                    BrowserSize = new Size(Parse(split[0]), Parse(split[1]));
            }, "BrowserSize");
        }
Esempio n. 38
0
 private AssertFactory()
 {
     AssertMethod = new Assert();
 }
 public PlatformSpecificXSLTGenerationWorksTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public ModuleInfoGetsUpgradedTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public IncludeProjectPropertiesWorksTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public IncludeProjectAppliesToWorksTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public ConfigurationMappingWorksTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
Esempio n. 44
0
 public abstract void Execute(IAssert assert);
 public CheckForOverflowUnderflowPropertyWorksTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public PackageTemplateAppliesCorrectlyTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public PackageProtobuildHTTPResolvesSecondTimeForSourceAndBinaryTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public PostBuildHookHasHostPlatformTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
Esempio n. 49
0
 public ServicesDisableTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
Esempio n. 50
0
 public TestRequestHandler(DeviceUtil deviceUtil, IAssert assert)
     : base(deviceUtil, assert)
 {
 }
 public ExampleCocos2DXNATest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public PackageProtobuildHTTPSResolvesNewForSourceOnlyTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public BasicSynchronisationWorksTest(IAssert assert)
     : base(assert)
 {
 }
Esempio n. 54
0
 public PathUtilsTests(IAssert assert)
 {
     _assert = assert;
 }
 public SyncDoesNotIncludeContentExtensiveTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public MacOSPlatformForceAPIXamMacWorksTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public PackageEverythingCorrectGZipTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public NuGetAndroidDoesNotCrashTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public PackageFilterCorrectTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }
 public PlatformSpecificOutputFalseTest(IAssert assert)
     : base(assert)
 {
     _assert = assert;
 }