Beispiel #1
0
        /// <summary>
        /// Makes the fake strict. This means that any call to the fake
        /// that has not been explicitly configured will throw an exception,
        /// except calls to the <see cref="object"/> methods specified
        /// in <paramref name="strictOptions"/>.
        /// </summary>
        /// <param name="options">Options used to create the fake object.</param>
        /// <param name="strictOptions">Strict fake options.</param>
        /// <returns>An options object.</returns>
        public static IFakeOptions Strict(this IFakeOptions options, StrictFakeOptions strictOptions)
        {
            Guard.AgainstNull(options, nameof(options));

            return(options.ConfigureFake(fake =>
            {
                var manager = Fake.GetFakeManager(fake);
                manager.AddRuleFirst(new StrictFakeRule(strictOptions));
            }));
        }
Beispiel #2
0
        public static void CallToGetHashCodeNotAllowed(
            StrictFakeOptions strictOptions,
            IMyInterface fake,
            Exception exception)
        {
            "Given a strict fake that doesn't allow calls to GetHashCode"
            .x(() => fake = A.Fake <IMyInterface>(options =>
                                                  options.Strict(strictOptions)));

            "When I call GetHashCode on the fake"
            .x(() => exception = Record.Exception(
                   () => fake.GetHashCode()));

            "Then it should throw an exception"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());
        }
Beispiel #3
0
        public static void CallToGetHashCodeAllowed(
            StrictFakeOptions strictOptions,
            IMyInterface fake,
            Exception exception)
        {
            "Given a strict fake that allows calls to GetHashCode"
            .x(() => fake = A.Fake <IMyInterface>(options =>
                                                  options.Strict(strictOptions)));

            "When I call GetHashCode on the fake"
            .x(() => exception = Record.Exception(
                   () => fake.GetHashCode()));

            "Then it shouldn't throw an exception"
            .x(() => exception.Should().BeNull());
        }
Beispiel #4
0
 public StrictFakeRule(StrictFakeOptions options)
 {
     this.options = options;
 }
Beispiel #5
0
 private bool HasOption(StrictFakeOptions flag) => (flag & this.options) == flag;