Ejemplo n.º 1
0
        public void VerifyMethodIgnoresEquals(Type type, Type argumentType)
        {
            // Fixture setup
            var method = type.GetMethod("Equals", new[] { argumentType });

            var invoked     = false;
            var expectation = new DelegatingBehaviorExpectation {
                OnVerify = c => invoked = true
            };

            var sut = new GuardClauseAssertion(new Fixture(), expectation);

            // Exercise system
            sut.Verify(method);
            // Verify outcome
            Assert.False(invoked);
            // Teardown
        }
Ejemplo n.º 2
0
        public static void ShouldNotAcceptNullArgumentsForAllMethods(this Type type, IFixture fixture, Func <MethodInfo, bool> whereFunc, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var assertion   = new GuardClauseAssertion(fixture);
            var methodInfos = type.GetMethods(bindingFlags);

            if (!methodInfos.Where(whereFunc).Any())
            {
                throw new InvalidOperationException($"Methods for type {type.FullName} isn't found.");
            }

            fixture.Customize(new AutoMoqCustomization());

            assertion.Verify(methodInfos.Where(whereFunc));
        }
Ejemplo n.º 3
0
        public static void ShouldNotAcceptNullMethodArguments(this Type type, IFixture fixture, string methodName, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var assertion  = new GuardClauseAssertion(fixture);
            var methodInfo = type.GetMethod(methodName, bindingFlags);

            if (methodInfo == null)
            {
                throw new InvalidOperationException($"Method '{methodName}' for type {type.FullName} isn't found.");
            }

            fixture.Customize(new AutoMoqCustomization());

            assertion.Verify(methodInfo);
        }
Ejemplo n.º 4
0
        public static void ShouldNotAcceptNullConstructorArguments(this Type type, IFixture fixture, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var assertion        = new GuardClauseAssertion(fixture);
            var constructorInfos = type.GetConstructors(bindingFlags);

            if (!constructorInfos.Any())
            {
                throw new InvalidOperationException($"Constructors for type {type.FullName} isn't found.");
            }

            fixture.Customize(new AutoMoqCustomization());

            assertion.Verify(constructorInfos);
        }
        public void DynamicDummyTypeIfVoidMethodIsCalledDoesNotThrows()
        {
            // Arrange
            bool mockVerification    = false;
            var  behaviorExpectation = new DelegatingBehaviorExpectation
            {
                OnVerify = c =>
                {
                    var dynamicInstance = (IDynamicInstanceTestType)GetParameters(c).ElementAt(0);
                    Assert.Null(Record.Exception(() => dynamicInstance.VoidMethod(null, 123)));
                    Assert.Null(Record.Exception(() => { dynamicInstance.Property = new object(); }));
                    mockVerification = true;
                }
            };
            var sut        = new GuardClauseAssertion(new Fixture(), behaviorExpectation);
            var methodInfo = typeof(DynamicInstanceTestConstraint <>).GetMethod("Method");

            // Act
            sut.Verify(methodInfo);
            // Assert
            Assert.True(mockVerification, "mock verification.");
        }
        public void VerifyConstructorInvokesBehaviorExpectationWithCorrectParametersForReplacement(MemberRef <ConstructorInfo> ctorRef)
        {
            // Arrange
            var ctor       = ctorRef.Member;
            var parameters = ctor.GetParameters();

            var expectation = new DelegatingBehaviorExpectation
            {
                OnVerify = c =>
                {
                    var unwrapper = Assert.IsAssignableFrom <ReflectionExceptionUnwrappingCommand>(c);
                    var methodCmd = Assert.IsAssignableFrom <MethodInvokeCommand>(unwrapper.Command);

                    var replacement = Assert.IsAssignableFrom <IndexedReplacement <object> >(methodCmd.Expansion);
                    Assert.True(replacement.Source.Select(x => x.GetType()).SequenceEqual(parameters.Select(p => p.ParameterType)));
                }
            };

            var sut = new GuardClauseAssertion(new Fixture(), expectation);

            // Act
            sut.Verify(ctor);
            // Assert (done by mock)
        }
Ejemplo n.º 7
0
        public void Sut_VerifyGuardClauses(IFixture fixture)
        {
            var assertion = new GuardClauseAssertion(fixture);

            assertion.Verify(typeof(ActionExecuteGiven).GetMethods());
        }
Ejemplo n.º 8
0
 public void Constructor_is_guarded(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(RetryErrorFilter).GetConstructors());
 }
 public void EmployeeWriterWithEmailAlreadyExistsValidation_Should_Guard_Its_Clause(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(EmployeeWriterWithEmailAlreadyExistsValidation).GetConstructors());
 }
        public void Ctors_ShouldReceiveInitializedParameters(GuardClauseAssertion assertion)
        {
            var members = typeof(SqliteConnectionSpecimenBuilder).GetConstructors();

            assertion.Verify(members);
        }
Ejemplo n.º 11
0
 public void SutHasAppropriateGuards(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(ScalarRouteValuesQuery));
 }
Ejemplo n.º 12
0
 public void Sut_VerifyGuardClause(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(SeleniumReporter));
 }
 public void Constructor_is_guarded(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(HttpRestClient).GetConstructors());
 }
Ejemplo n.º 14
0
 public void Constructor_is_guarded_against_nulls(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(ExceptionHandlerFilter).GetConstructors());
 }
 public void Methods_HaveNullGuards(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(ApplicationStyleViewModel).GetMethods().Where(method => !method.IsAbstract));
 }
 public void Constructor_is_guarded(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(ImprovedTranslateCommandHandler).GetConstructors());
 }
Ejemplo n.º 17
0
 public void Sut_VerifyGuardClause(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(QuestionBase <object>));
 }
 public void Constructor_HasNullGuards(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(DefaultGetNodeString).GetConstructors());
 }
Ejemplo n.º 19
0
 public void Constructor_is_guarded(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(InputReader).GetConstructors());
 }
Ejemplo n.º 20
0
 public void Sut_VerifyGuardClauses(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(ActorExtensions));
 }
 public void Constructor_is_guarded(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(DependencyInjectionServiceBehavior).GetConstructors());
 }
Ejemplo n.º 22
0
 public void Sut_ShouldGuardItsClause(GuardClauseAssertion assertion)
 => assertion.Verify(typeof(PdvCommandRepository).GetConstructors());
Ejemplo n.º 23
0
 public void Sut_VerifyGuardClauses(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(UIModel));
 }
 public void Constructor_GuardTests(GuardClauseAssertion guard)
 {
     guard.Verify(typeof(HttpRequestMessageBuilder).GetConstructors());
 }
Ejemplo n.º 25
0
 public void Sut_VerifyGuardClauses(
     GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(ReportingActor));
 }
Ejemplo n.º 26
0
 public void Constructor_HasNullGuards(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(Int32FromString).GetConstructors());
 }
 public void PublicSurfaceShouldNotAllowNullArgs(GuardClauseAssertion assertion) =>
 assertion.Verify(typeof(MaxStringLengthConstraint));
Ejemplo n.º 28
0
 public void Methods_HaveNullGuards(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(Int32FromString).GetMethods().Where(method => !method.IsAbstract));
 }
Ejemplo n.º 29
0
 public void Sut_VerifyGuardClauses(GuardClauseAssertion assertion)
 {
     assertion.Verify(typeof(Navigate));
 }
Ejemplo n.º 30
0
 public void Constructor_GuardTests(GuardClauseAssertion guard)
 {
     guard.Verify(typeof(DiffCommandHandler).GetConstructors());
 }