public void MustThrowIfDuplicateQueryHandlers() { var assembly = New.Common().Assembly.WithTypes(typeof(FakeHandler), typeof(FakeHandler)).Creation; var sc = new ServiceCollection(); Assert.ThrowsAny <Exception>(() => sc.AddQueryHandlers(new Assembly[] { assembly })); }
public void MustReturnFalseWhenTypeIsNotGeneric() { var nonGenericType = New.Common().Type.Creation; var result = TypeExtensions.IsGenericTypeWithNonGenericTypeParameters(nonGenericType); Assert.False(result); }
public WhenDispatching() { _serviceProvider.Setup(p => p.GetService(typeof(IEnumerable <IMessageHandler <IMessage> >))) .Returns(new[] { _handler.Object }.TakeWhile(_ => true)); _logger = New.Common().Logger <EventDispatcher>(); _sut = new EventDispatcher(_serviceProvider.Object, _logger.Creation); }
public void MustReturnEmptyListIfOpenGenericTypeToMatchIsNull() { var type = New.Common().Type; var result = TypeExtensions.GetImplementedInterfacesThatMatchOpenGenericType(type, null); Assert.Empty(result); }
public void MustReturnEmptyListIfTypeHasNotImplementedInterfaces() { var type = New.Common().Type; var result = TypeExtensions.GetImplementedInterfacesThatMatchOpenGenericType(type, typeof(IEnumerable <>)); Assert.Empty(result); }
public WhenDispatchingGenericQuery() { _query = It.IsAny <IQuery <string> >(); _serviceProvider.Setup(p => p.GetService(typeof(IQueryHandler <IQuery <string>, string>))) .Returns(_handler.Object); _logger = New.Common().Logger <QueryDispatcher>(); _sut = new QueryDispatcher(_serviceProvider.Object, _logger.Creation); }
public void MustReturnEMptyIfTypeHasNoGenericArguments() { var type = New.Common().Type.Creation; var result = TypeExtensions.GetImplementedInterfacesOfSingleGenericTypeArgument(type); Assert.Empty(result); }
public WhenDispatchingStrongTypedQuery() { _query = new TestQuery(); _serviceProvider.Setup(p => p.GetService(typeof(IQueryHandler <TestQuery, string>))) .Returns(_handler.Object); _logger = New.Common().Logger <QueryDispatcher>(); _sut = new QueryDispatcher(_serviceProvider.Object, _logger.Creation); }
public WhenDispatching() { _serviceProvider.Setup(p => p.GetService(typeof(IMessageHandler <IMessage>))) .Returns(_handler.Object); _serviceProvider.Setup(p => p.GetService(typeof(ICommandBehaviorPipeline <IMessage>))) .Returns(_pipeline.Object); _logger = New.Common().Logger <CommandDispatcher>(); _sut = new CommandDispatcher(_serviceProvider.Object, _logger.Creation); }
public void MustThrowIfTypeHasMoreThanOneGenericArgument() { var implementedInterfaceType = typeof(ICommand); var type = New.Common().Type .WithGenericArguments(implementedInterfaceType, implementedInterfaceType) .Creation; Assert.Throws <InvalidOperationException>(() => TypeExtensions.GetImplementedInterfacesOfSingleGenericTypeArgument(type)); }
public void MustReturnTrueWhenTypeIsGenericAndNoTypeParametersAreGeneric() { var nonGenericType = New.Common().Type.Creation; var genericType = New.Common().Type .AsGeneric() .WithGenericArguments(nonGenericType).Creation; var result = TypeExtensions.IsGenericTypeWithNonGenericTypeParameters(genericType); Assert.True(result); }
public AssemblyCreator(INewContext newContext, Assembly assembly = null) : base(newContext, assembly) { WithFullName(Guid.NewGuid().ToString()); WithTypes(New.Common().Type.Creation); _assemblyMock.Setup(a => a.Equals(It.IsAny <Assembly>())) .Returns <Assembly>(x => x.FullName == _assemblyMock.Object.FullName && x.GetTypes() == _assemblyMock.Object.GetTypes()); Creation = _assemblyMock.Object; }
public void MustReturnFalseIfGenericImplementedInterfaceDoesNotHaveMatchingType() { var genericArgumentType = New.Common().Type; var type = New.Common().Type .WithGenericArguments(genericArgumentType) .Creation; var types = new Type[] { type }; var result = TypeExtensions.HasMatchingGenericArgumentType(types, typeof(ICommand)); Assert.False(result); }
public void MustNotReturnImplementedInterfacesThatAreNotGeneric() { var genericTypeDef = typeof(IMessageHandler <>); var interfaceType = New.Common().Type; var type = New.Common().Type .WithImplementedInterfaces(interfaceType).Creation; var result = TypeExtensions.GetImplementedInterfacesThatMatchOpenGenericType(type, genericTypeDef); Assert.DoesNotContain(interfaceType, result); Assert.Empty(result); }
public void MustReturnFalseIfTypeParameterTypeToMatchIsNull() { var genericArgumentType = New.Common().Type .WithImplementedInterfaces(typeof(ICommand)).Creation; var type = New.Common().Type .WithGenericArguments(genericArgumentType) .Creation; var types = new Type[] { type }; var result = TypeExtensions.HasMatchingGenericArgumentType(types, null); Assert.False(result); }
public void MustGetImplementedInterfacesIfTypeHasExactlyOneGenericArgument() { var implementedInterfaceType = typeof(ICommand); var genericArgumentType = New.Common().Type .WithImplementedInterfaces(implementedInterfaceType).Creation; var type = New.Common().Type .WithGenericArguments(genericArgumentType) .Creation; var result = TypeExtensions.GetImplementedInterfacesOfSingleGenericTypeArgument(type); Assert.Contains(implementedInterfaceType, result); }
public void MustNotFilterAnyAssembliesWhenNamespaceSelectorIsEmptyAndNoExplicitAssemblies() { var assembly = New.Common().Assembly.Creation; var assemblyFilterSourceProvider = New.Cqrs().AssemblyFilterSourceProvider .WithSourceAssemblies(assembly) .Creation; var filter = new AssemblySourceFilter(assemblyFilterSourceProvider, string.Empty, null); var result = filter.Apply(); result.Should().HaveCount(1); result.Should().Contain(assembly); }
public void MustRegisterHandlersForGenericEvent() { var assembly = New.Common().Assembly.WithTypes(typeof(FakeEventHandler3)).Creation; var sc = new ServiceCollection(); sc.AddEventHandlers(new Assembly[] { assembly }); var sd = sc.GetServiceDescriptorByImplementationType(typeof(FakeEventHandler3)); sd.Lifetime.Should().Be(ServiceLifetime.Transient); sd.ServiceType.Should().Be(typeof(IMessageHandler <FakeGenericEvent <string> >)); sd.ImplementationType.Should().Be(typeof(FakeEventHandler3)); }
public void MustNotContainDuplicateAssemblies() { var assembly = New.Common().Assembly.Creation; var explicitAssemblies = new Assembly[] { assembly }; var assemblyFilterSourceProvider = New.Cqrs().AssemblyFilterSourceProvider.WithSourceAssemblies(assembly).Creation; var filter = new AssemblySourceFilter(assemblyFilterSourceProvider, string.Empty, explicitAssemblies); var result = filter.Apply(); result.Should().HaveCount(1); Assert.Contains(assembly, result); }
public void MustRegisterAllQueryHandlers() { var assembly = New.Common().Assembly.WithTypes(typeof(FakeHandler)).Creation; var sc = new ServiceCollection(); sc.AddQueryHandlers(new Assembly[] { assembly }); var sd = sc.GetServiceDescriptorByImplementationType(typeof(FakeHandler)); sd.Lifetime.Should().Be(ServiceLifetime.Transient); sd.ServiceType.Should().Be(typeof(IQueryHandler <FakeQuery, string>)); sd.ImplementationType.Should().Be(typeof(FakeHandler)); }
public void MustReturnImplementedInterfacesThatAreGenericAndHaveMatchingGenericTypeDef() { var genericTypeDef = typeof(IMessageHandler <>); var interfaceType = New.Common().Type .AsGeneric() .WithGenericTypeDef(genericTypeDef); var type = New.Common().Type .WithImplementedInterfaces(interfaceType).Creation; var result = TypeExtensions.GetImplementedInterfacesThatMatchOpenGenericType(type, genericTypeDef); Assert.Contains(interfaceType, result); }
public void MustContainExplicitAssemblies() { var assembly = New.Common().Assembly.Creation; var explicitAssemblies = new Assembly[] { assembly }; var assemblyFilterSourceProvider = New.Cqrs().AssemblyFilterSourceProvider .Creation; var filter = new AssemblySourceFilter(assemblyFilterSourceProvider, string.Empty, explicitAssemblies); var result = filter.Apply(); Assert.Equal(explicitAssemblies, filter.ExplictAssemblies); Assert.Contains(assembly, result); }
public void MustReturnFalseWhenAtLeastOneTypeParameterIsGeneric() { var genericTypeParameter = New.Common().Type .AsGeneric() .AsGenericTypeParameter() .Creation; var genericType = New.Common().Type .AsGeneric() .WithGenericArguments(genericTypeParameter).Creation; var result = TypeExtensions.IsGenericTypeWithNonGenericTypeParameters(genericType); Assert.False(result); }
public void MustOnlyRegisterEventHandlers() { var assembly = New.Common().Assembly.WithTypes(typeof(FakeCommandHandler), typeof(FakeEventHandler)).Creation; var sc = new ServiceCollection(); sc.AddEventHandlers(new Assembly[] { assembly }); var sd = sc.GetServiceDescriptorByImplementationType(typeof(FakeEventHandler)); sc.Should().HaveCount(1); sd.Lifetime.Should().Be(ServiceLifetime.Transient); sd.ServiceType.Should().Be(typeof(IMessageHandler <FakeEvent>)); sd.ImplementationType.Should().Be(typeof(FakeEventHandler)); }
public void MustNotFilterAnyAssembliesWhenNameselectorIsNullWithExplicitAssemblies() { var assembly = New.Common().Assembly.Creation; var assembly2 = New.Common().Assembly.Creation; var explicitAssemblies = new Assembly[] { assembly }; var assemblyFilterSourceProvider = New.Cqrs().AssemblyFilterSourceProvider .WithSourceAssemblies(assembly2) .Creation; var filter = new AssemblySourceFilter(assemblyFilterSourceProvider, null, explicitAssemblies); var result = filter.Apply(); result.Should().HaveCount(2); result.Should().Contain(assembly); result.Should().Contain(assembly2); }
public void MustMatchNamespaceSelectorWithSingleSymbolWildcardToAssemblyFullName() { var fullName = "Chatter.Cqrs"; var assembly = New.Common().Assembly .WithFullName(fullName) .Creation; var assemblyFilterSourceProvider = New.Cqrs().AssemblyFilterSourceProvider .WithSourceAssemblies(assembly) .Creation; var filter = new AssemblySourceFilter(assemblyFilterSourceProvider, "Chatter?Cqrs", null); var result = filter.Apply(); result.Should().HaveCount(1); result.First().FullName.Should().Be(fullName); result.First().Should().BeSameAs(assembly); }
public void MustIgnoreCaseWhenApplyingNamespaceSelectorFilterToAssemblyFullName() { var fullName = "Chatter.Cqrs"; var assembly = New.Common().Assembly .WithFullName(fullName) .Creation; var assemblyFilterSourceProvider = New.Cqrs().AssemblyFilterSourceProvider .WithSourceAssemblies(assembly) .Creation; var filter = new AssemblySourceFilter(assemblyFilterSourceProvider, fullName.ToUpper(), null); var result = filter.Apply(); result.Should().HaveCount(1); result.First().FullName.Should().Be(fullName); result.First().Should().BeSameAs(assembly); }
public void MustReturnFalseIfTypeDoesNotImplementIMessageHandler() { var typeToMatch = typeof(ICommand); var argType = New.Common().Type .WithImplementedInterfaces(typeToMatch) .Creation; var closedGenericWithArgType = New.Common().Type .WithGenericTypeDef(typeof(IEnumerable <>)) .WithGenericArguments(argType) .Creation; var type = New.Common().Type .WithImplementedInterfaces(closedGenericWithArgType) .Creation; var result = CqrsExtensions.IsValidMessageHandler(type, typeToMatch); Assert.False(result); }
public void MustReturnTrueIfNotGenericTypeAndImplementsIMessageHandlerWithMatchingTypeParam() { var typeToMatch = typeof(ICommand); var argType = New.Common().Type .WithImplementedInterfaces(typeToMatch) .Creation; var closedGenericWithArgType = New.Common().Type .WithGenericTypeDef(typeof(IMessageHandler <>)) .WithGenericArguments(argType) .Creation; var type = New.Common().Type .WithImplementedInterfaces(closedGenericWithArgType) .Creation; var result = CqrsExtensions.IsValidMessageHandler(type, typeToMatch); Assert.True(result); }
public void MustNotReplaceDuplicateRegistrations() { var assembly = New.Common().Assembly .WithTypes(typeof(FakeEventHandler), typeof(FakeEventHandler2)) .Creation; var sc = new ServiceCollection(); sc.AddEventHandlers(new Assembly[] { assembly }); sc.Should().HaveCount(2); sc.Should().OnlyHaveUniqueItems(); sc[0].Lifetime.Should().Be(ServiceLifetime.Transient); sc[0].ServiceType.Should().Be(typeof(IMessageHandler <FakeEvent>)); sc[0].ImplementationType.Should().Be(typeof(FakeEventHandler)); sc[1].Lifetime.Should().Be(ServiceLifetime.Transient); sc[1].ServiceType.Should().Be(typeof(IMessageHandler <FakeEvent>)); sc[1].ImplementationType.Should().Be(typeof(FakeEventHandler2)); }