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 }
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)); }
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); }
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) }
public void Sut_VerifyGuardClauses(IFixture fixture) { var assertion = new GuardClauseAssertion(fixture); assertion.Verify(typeof(ActionExecuteGiven).GetMethods()); }
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); }
public void SutHasAppropriateGuards(GuardClauseAssertion assertion) { assertion.Verify(typeof(ScalarRouteValuesQuery)); }
public void Sut_VerifyGuardClause(GuardClauseAssertion assertion) { assertion.Verify(typeof(SeleniumReporter)); }
public void Constructor_is_guarded(GuardClauseAssertion assertion) { assertion.Verify(typeof(HttpRestClient).GetConstructors()); }
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()); }
public void Sut_VerifyGuardClause(GuardClauseAssertion assertion) { assertion.Verify(typeof(QuestionBase <object>)); }
public void Constructor_HasNullGuards(GuardClauseAssertion assertion) { assertion.Verify(typeof(DefaultGetNodeString).GetConstructors()); }
public void Constructor_is_guarded(GuardClauseAssertion assertion) { assertion.Verify(typeof(InputReader).GetConstructors()); }
public void Sut_VerifyGuardClauses(GuardClauseAssertion assertion) { assertion.Verify(typeof(ActorExtensions)); }
public void Constructor_is_guarded(GuardClauseAssertion assertion) { assertion.Verify(typeof(DependencyInjectionServiceBehavior).GetConstructors()); }
public void Sut_ShouldGuardItsClause(GuardClauseAssertion assertion) => assertion.Verify(typeof(PdvCommandRepository).GetConstructors());
public void Sut_VerifyGuardClauses(GuardClauseAssertion assertion) { assertion.Verify(typeof(UIModel)); }
public void Constructor_GuardTests(GuardClauseAssertion guard) { guard.Verify(typeof(HttpRequestMessageBuilder).GetConstructors()); }
public void Sut_VerifyGuardClauses( GuardClauseAssertion assertion) { assertion.Verify(typeof(ReportingActor)); }
public void Constructor_HasNullGuards(GuardClauseAssertion assertion) { assertion.Verify(typeof(Int32FromString).GetConstructors()); }
public void PublicSurfaceShouldNotAllowNullArgs(GuardClauseAssertion assertion) => assertion.Verify(typeof(MaxStringLengthConstraint));
public void Methods_HaveNullGuards(GuardClauseAssertion assertion) { assertion.Verify(typeof(Int32FromString).GetMethods().Where(method => !method.IsAbstract)); }
public void Sut_VerifyGuardClauses(GuardClauseAssertion assertion) { assertion.Verify(typeof(Navigate)); }
public void Constructor_GuardTests(GuardClauseAssertion guard) { guard.Verify(typeof(DiffCommandHandler).GetConstructors()); }