public void Equals_DifferentDistinctCondition() { var dataInfo = new TestStreamedValueInfo(typeof(int)); var selectProjection = Expression.Constant(1); var isDistinctQuery = BooleanObjectMother.GetRandomBoolean(); var sqlStatement1 = new SqlStatement( dataInfo, selectProjection, new SqlTable[] { }, null, null, new Ordering[] { }, null, isDistinctQuery, null, null); var sqlStatement2 = new SqlStatement( dataInfo, selectProjection, new SqlTable[] { }, null, null, new Ordering[] { }, null, !isDistinctQuery, null, null); Assert.That(sqlStatement1.Equals(sqlStatement2), Is.False); }
public void CreateModuleBuilder() { var assemblyName = "assembly name"; var assemblyDirectoryOrNull = "directory"; var strongNamed = BooleanObjectMother.GetRandomBoolean(); var keyFilePathOrNull = "key file path"; var moduleBuilderMock = MockRepository.GenerateStrictMock <IModuleBuilder>(); var assemblyBuilderMock = MockRepository.GenerateStrictMock <IAssemblyBuilder>(); _innerFactoryMock .Expect(mock => mock.CreateModuleBuilder(assemblyName, assemblyDirectoryOrNull, strongNamed, keyFilePathOrNull)) .Return(moduleBuilderMock); moduleBuilderMock.Expect(mock => mock.AssemblyBuilder).Return(assemblyBuilderMock); assemblyBuilderMock .Expect(mock => mock.SetCustomAttribute(Arg <CustomAttributeDeclaration> .Is.Anything)) .WhenCalled( mi => { var declaration = (CustomAttributeDeclaration)mi.Arguments.Single(); Assert.That(declaration.Type, Is.SameAs(typeof(NonApplicationAssemblyAttribute))); Assert.That(declaration.ConstructorArguments, Is.Empty); }); var result = _factory.CreateModuleBuilder(assemblyName, assemblyDirectoryOrNull, strongNamed, keyFilePathOrNull); _innerFactoryMock.VerifyAllExpectations(); moduleBuilderMock.VerifyAllExpectations(); assemblyBuilderMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(moduleBuilderMock)); }
public void CreateInstance_WithConcreteType_AndPreparedMixins() { var allowNonPublicCtor = BooleanObjectMother.GetRandomBoolean(); var concreteType = TypeFactory.GetConcreteType(typeof(BaseType1)); var paramList = ParamList.Create("blub"); var fakePreparedInstance = new object(); var reflectionServiceMock = MockRepository.GenerateStrictMock <IReflectionService>(); _defaultPipelineMock.Stub(_ => _.ReflectionService).Return(reflectionServiceMock); reflectionServiceMock .Expect(_ => _.InstantiateAssembledType(concreteType, paramList, allowNonPublicCtor)) .Return(new object()) .WhenCalled( mi => { Assert.That(MixedObjectInstantiationScope.HasCurrent, Is.True); Assert.That(MixedObjectInstantiationScope.Current.SuppliedMixinInstances, Is.EqualTo(new[] { fakePreparedInstance })); }); _implementation.CreateInstance(allowNonPublicCtor, concreteType, paramList, fakePreparedInstance); reflectionServiceMock.VerifyAllExpectations(); }
public void DelegatingMembers() { var objectID = DomainObjectIDs.Order1; var dataContainer = DataContainer.CreateNew(objectID); var relationEndPointID = RelationEndPointID.Create(objectID, typeof(Order), "OrderTicket"); var virtualEndPoint = MockRepository.GenerateStub <IVirtualEndPoint>(); var domainObject = DomainObjectMother.CreateFakeObject <Order>(); var persistableData = new PersistableData(domainObject, StateType.Unchanged, dataContainer, new IRelationEndPoint[0]); var dataManagementCommand = MockRepository.GenerateStub <IDataManagementCommand> (); var randomBoolean = BooleanObjectMother.GetRandomBoolean(); CheckDelegation(dm => dm.GetOrCreateVirtualEndPoint(relationEndPointID), virtualEndPoint); CheckDelegation(dm => dm.GetRelationEndPointWithLazyLoad(relationEndPointID), virtualEndPoint); CheckDelegation(dm => dm.GetRelationEndPointWithoutLoading(relationEndPointID), virtualEndPoint); CheckDelegation(dm => dm.GetDataContainerWithoutLoading(objectID), dataContainer); CheckDelegation(dm => dm.RegisterDataContainer(dataContainer)); CheckDelegation(dm => dm.Discard(dataContainer)); CheckDelegation(dm => dm.DataContainers, MockRepository.GenerateStub <IDataContainerMapReadOnlyView> ()); CheckDelegation(dm => dm.RelationEndPoints, MockRepository.GenerateStub <IRelationEndPointMapReadOnlyView> ()); CheckDelegation(dm => dm.GetState(objectID), StateType.Deleted); CheckDelegation(dm => dm.GetDataContainerWithLazyLoad(objectID, randomBoolean), dataContainer); CheckDelegation(dm => dm.GetDataContainersWithLazyLoad(new[] { objectID }, true), new[] { dataContainer }); CheckDelegation(dm => dm.GetLoadedDataByObjectState(StateType.Unchanged), new[] { persistableData }); CheckDelegation(dm => dm.MarkInvalid(domainObject)); CheckDelegation(dm => dm.MarkNotInvalid(objectID)); CheckDelegation(dm => dm.Commit()); CheckDelegation(dm => dm.Rollback()); CheckDelegation(dm => dm.CreateDeleteCommand(domainObject), dataManagementCommand); CheckDelegation(dm => dm.CreateUnloadCommand(new[] { objectID }), dataManagementCommand); CheckDelegation(dm => dm.CreateUnloadVirtualEndPointsCommand(new[] { relationEndPointID }), dataManagementCommand); CheckDelegation(dm => dm.CreateUnloadAllCommand(), dataManagementCommand); CheckDelegation(dm => dm.LoadLazyCollectionEndPoint(relationEndPointID)); CheckDelegation(dm => dm.LoadLazyVirtualObjectEndPoint(relationEndPointID)); CheckDelegation(dm => dm.LoadLazyDataContainer(objectID), dataContainer); }
public void SetUp() { _declaringType = MutableTypeObjectMother.Create(); _isStatic = BooleanObjectMother.GetRandomBoolean(); _context = new TestableMethodBaseBodyContextBase(_declaringType, new ParameterExpression[0], _isStatic); }
public void DefineType() { var name = "DomainType"; var attributes = (TypeAttributes)7; var forceStrongNaming = BooleanObjectMother.GetRandomBoolean(); var keyFilePath = "key file path"; _flusher.SetAssemblyNamePattern("custom assembly name pattern"); _configurationProviderMock.Expect(mock => mock.ForceStrongNaming).Return(forceStrongNaming); _configurationProviderMock.Expect(mock => mock.KeyFilePath).Return(keyFilePath); _moduleBuilderFactoryMock .Expect(mock => mock.CreateModuleBuilder("custom assembly name pattern", null, forceStrongNaming, keyFilePath)) .Return(_moduleBuilderMock); var fakeTypeBuilder1 = MockRepository.GenerateStub <ITypeBuilder>(); var fakeTypeBuilder2 = MockRepository.GenerateStub <ITypeBuilder>(); _moduleBuilderMock.Expect(mock => mock.DefineType(name, attributes)).Return(fakeTypeBuilder1); _moduleBuilderMock.Expect(mock => mock.DefineType("OtherType", 0)).Return(fakeTypeBuilder2); var result1 = _flusher.DefineType(name, attributes, _emittableOperandProviderMock); var result2 = _flusher.DefineType("OtherType", 0, _emittableOperandProviderMock); _moduleBuilderFactoryMock.VerifyAllExpectations(); _moduleBuilderMock.VerifyAllExpectations(); _configurationProviderMock.VerifyAllExpectations(); Assert.That(result1.As <TypeBuilderDecorator>().DecoratedTypeBuilder, Is.SameAs(fakeTypeBuilder1)); Assert.That(result2.As <TypeBuilderDecorator>().DecoratedTypeBuilder, Is.SameAs(fakeTypeBuilder2)); Assert.That(PrivateInvoke.GetNonPublicField(result1, "EmittableOperandProvider"), Is.SameAs(_emittableOperandProviderMock)); Assert.That(PrivateInvoke.GetNonPublicField(result2, "EmittableOperandProvider"), Is.SameAs(_emittableOperandProviderMock)); }
public void PrepareAssembledTypeInstance_Initializable() { var initializableObjectMock = new Mock <IInitializableObject>(); var reason = BooleanObjectMother.GetRandomBoolean() ? InitializationSemantics.Construction : InitializationSemantics.Deserialization; _service.PrepareExternalUninitializedObject(initializableObjectMock.Object, reason); initializableObjectMock.Verify(mock => mock.Initialize(reason), Times.Once()); }
public void RaiseVirtualRelationEndPointStateUpdatedEvent() { var endPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, ReflectionMappingHelper.GetPropertyName(typeof(Order), "OrderItems")); var newEndPointChangeState = BooleanObjectMother.GetRandomBoolean(); CheckEventWithListenersOnly( s => s.RaiseVirtualRelationEndPointStateUpdatedEvent(endPointID, newEndPointChangeState), l => l.VirtualRelationEndPointStateUpdated(_clientTransaction, endPointID, newEndPointChangeState)); }
public void PrepareAssembledTypeInstance_Initializable() { var initializableObjectMock = MockRepository.GenerateMock <IInitializableObject>(); var reason = BooleanObjectMother.GetRandomBoolean() ? InitializationSemantics.Construction : InitializationSemantics.Deserialization; _service.PrepareExternalUninitializedObject(initializableObjectMock, reason); initializableObjectMock.AssertWasCalled(mock => mock.Initialize(reason)); }
public void Initialize() { bool includeBaseProperties = BooleanObjectMother.GetRandomBoolean(); bool includeMixinProperties = BooleanObjectMother.GetRandomBoolean(); var propertyFinder = new StubPropertyFinderBase( typeof(ClassWithDifferentProperties), includeBaseProperties, includeMixinProperties, _persistentMixinFinderStub); Assert.That(propertyFinder.Type, Is.SameAs(typeof(ClassWithDifferentProperties))); Assert.That(propertyFinder.IncludeBaseProperties, Is.EqualTo(includeBaseProperties)); Assert.That(propertyFinder.IncludeMixinProperties, Is.EqualTo(includeMixinProperties)); }
public void GetObject() { Assert.That(_dataContainer1.State, Is.Not.EqualTo(StateType.Deleted)); _dataManagerMock.Expect(mock => mock.GetDataContainerWithLazyLoad(_objectID1, true)).Return(_dataContainer1); var result = _agent.GetObject(_objectID1, BooleanObjectMother.GetRandomBoolean()); _dataManagerMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(_dataContainer1.DomainObject)); }
public void SetUp() { _declaringType = MutableTypeObjectMother.Create(); _isStatic = BooleanObjectMother.GetRandomBoolean(); _parameters = new List <ParameterExpression> { Expression.Parameter(typeof(int)), Expression.Parameter(typeof(object)) }; _previousBody = Expression.Block(_parameters[0], _parameters[1]); _context = new ConstructorBodyModificationContext(_declaringType, _isStatic, _parameters, _previousBody); }
public void SetUp() { _declaringType = MutableTypeObjectMother.Create(); _isStatic = BooleanObjectMother.GetRandomBoolean(); _parameters = new[] { Expression.Parameter(typeof(string)) }; _genericParameters = new[] { ReflectionObjectMother.GetSomeGenericParameter() }; _returnType = ReflectionObjectMother.GetSomeType(); _baseMethod = ReflectionObjectMother.GetSomeMethod(); _context = new TestableMethodBodyContextBase( _declaringType, _isStatic, _parameters.AsOneTime(), _genericParameters.AsOneTime(), _returnType, _baseMethod); }
public void SetUp() { _typeCacheMock = new Mock <ITypeCache> (MockBehavior.Strict); _constructorDelegateFactoryMock = new Mock <IConstructorDelegateFactory> (MockBehavior.Strict); _constructorCallCache = new ConstructorCallCache(_typeCacheMock.Object, _constructorDelegateFactoryMock.Object); _constructorCalls = (ConcurrentDictionary <ConstructionKey, Delegate>)PrivateInvoke.GetNonPublicField(_constructorCallCache, "_constructorCalls"); _delegateType = ReflectionObjectMother.GetSomeDelegateType(); _allowNonPublic = BooleanObjectMother.GetRandomBoolean(); }
public void CreateForCurrentAppDomain() { var considerDynamicDirectory = BooleanObjectMother.GetRandomBoolean(); var finder = SearchPathRootAssemblyFinder.CreateForCurrentAppDomain(considerDynamicDirectory, _loaderStub); Assert.That(finder.BaseDirectory, Is.EqualTo(AppDomain.CurrentDomain.BaseDirectory)); Assert.That(finder.RelativeSearchPath, Is.EqualTo(AppDomain.CurrentDomain.RelativeSearchPath)); Assert.That(finder.DynamicDirectory, Is.EqualTo(AppDomain.CurrentDomain.DynamicDirectory)); Assert.That(finder.AssemblyLoader, Is.SameAs(_loaderStub)); Assert.That(finder.ConsiderDynamicDirectory, Is.EqualTo(considerDynamicDirectory)); }
public void IsAssembledType() { var type = ReflectionObjectMother.GetSomeType(); var fakeResult = BooleanObjectMother.GetRandomBoolean(); _typeAssemblerMock.Expect(mock => mock.IsAssembledType(type)).Return(fakeResult); var result = _service.IsAssembledType(type); _typeAssemblerMock.VerifyAllExpectations(); Assert.That(result, Is.EqualTo(fakeResult)); }
public void CanWrite_WithSecurableObject_WithoutSetter_UsesNullMethodInfo_ReturnsResult() { var expectedResult = BooleanObjectMother.GetRandomBoolean(); ExpectHasAccessOnObjectSecurityStrategy(expectedResult, GeneralAccessTypes.Edit); var bindableProperty = CreateBindableProperty((() => ((ClassWithReferenceType <string>)null).PropertyWithNoSetter)); var actualResult = _strategy.CanWrite(_securableObject, bindableProperty); Assert.That(actualResult, Is.EqualTo(expectedResult)); _objectSecurityStrategyMock.VerifyAllExpectations(); }
public void CanRead_WithSecurableObject_EvaluatesObjectSecurityStratey_ReturnsResult() { var expectedResult = BooleanObjectMother.GetRandomBoolean(); ExpectHasAccessOnObjectSecurityStrategy(expectedResult, TestAccessTypes.TestRead); var bindableProperty = CreateBindableProperty(() => ((SecurableClassWithReferenceType <string>)null).CustomPermissisons); var actualResult = _strategy.CanRead(_securableObject, bindableProperty); Assert.That(actualResult, Is.EqualTo(expectedResult)); _objectSecurityStrategyMock.VerifyAllExpectations(); }
public void Remove() { bool result = BooleanObjectMother.GetRandomBoolean(); _innerDataStoreMock .Expect(mock => mock.Remove("key")) .Return(result) .WhenCalled(mi => CheckInnerDataStoreIsProtected()); var actualResult = _store.Remove("key"); _innerDataStoreMock.VerifyAllExpectations(); Assert.That(actualResult, Is.EqualTo(result)); }
public void CreateInstance_UsesPipeline() { var allowNonPublicConstructors = BooleanObjectMother.GetRandomBoolean(); var fakeInstance = new object(); _defaultPipelineMock .Expect(mock => mock.Create(typeof(BaseType1), ParamList.Empty, allowNonPublicConstructors)) .Return(fakeInstance); var instance = _implementation.CreateInstance(allowNonPublicConstructors, typeof(BaseType1), ParamList.Empty); _defaultPipelineMock.VerifyAllExpectations(); Assert.That(instance, Is.SameAs(fakeInstance)); }
public void GetCustomAttributes_ArrayType_BehavesLikeReflection() { var member = MethodBase.GetCurrentMethod(); var mutableInfo = CreateMutableInfo(); var inherit = BooleanObjectMother.GetRandomBoolean(); var expectedType1 = member.GetCustomAttributes(inherit).GetType(); Assert.That(mutableInfo.GetCustomAttributes(inherit), Is.TypeOf(expectedType1)); var expectedType2 = member.GetCustomAttributes(typeof(BaseAttribute), inherit).GetType(); Assert.That(mutableInfo.GetCustomAttributes(typeof(BaseAttribute), inherit), Is.TypeOf(expectedType2)); }
public void LoadObject() { _persistenceStrategyMock.Expect(mock => mock.LoadObjectData(DomainObjectIDs.Order1)).Return(_loadedObjectDataStub1); var throwOnNotFound = BooleanObjectMother.GetRandomBoolean(); _loadedObjectDataRegistrationAgentMock.Expect(mock => mock.RegisterIfRequired(Arg.Is(new[] { _loadedObjectDataStub1 }), Arg.Is(throwOnNotFound))); _mockRepository.ReplayAll(); var result = _objectLoader.LoadObject(DomainObjectIDs.Order1, throwOnNotFound); _mockRepository.VerifyAll(); Assert.That(result, Is.SameAs(_loadedObjectDataStub1)); }
public void CanRead_WithSecurableObject_WithoutSetter_UsesNullMethodInfo_ReturnsResult() { var expectedResult = BooleanObjectMother.GetRandomBoolean(); ExpectHasAccessOnObjectSecurityStrategy(expectedResult, GeneralAccessTypes.Read); var bindableProperty = new StubPropertyBase( GetPropertyParameters(PropertyInfoAdapter.Create(typeof(ClassWithReferenceType <string>).GetProperty("PropertyWithNoGetter")))); var actualResult = _strategy.CanRead(_securableObject, bindableProperty); Assert.That(actualResult, Is.EqualTo(expectedResult)); _objectSecurityStrategyMock.VerifyAllExpectations(); }
public void IsStrongNamed_Generic() { var type = typeof(IList <Lazy <IParticipant> >); var fakeResult = BooleanObjectMother.GetRandomBoolean(); _assemblyAnalyzerMock.Setup(x => x.IsStrongNamed(typeof(IList <>).Assembly)).Returns(true).Verifiable(); _assemblyAnalyzerMock.Setup(x => x.IsStrongNamed(typeof(Lazy <>).Assembly)).Returns(true).Verifiable(); _assemblyAnalyzerMock.Setup(x => x.IsStrongNamed(typeof(IParticipant).Assembly)).Returns(fakeResult).Verifiable(); var result = _analyzer.IsStrongNamed(type); _assemblyAnalyzerMock.Verify(); Assert.That(result, Is.EqualTo(fakeResult)); }
public void SetUp() { _typeAssemblerMock = MockRepository.GenerateStrictMock <ITypeAssembler>(); _constructorDelegateFactoryMock = MockRepository.GenerateStrictMock <IConstructorDelegateFactory>(); _cache = new ConstructorForAssembledTypeCache(_typeAssemblerMock, _constructorDelegateFactoryMock); _constructorCalls = (ConcurrentDictionary <ConstructorForAssembledTypeCacheKey, Delegate>)PrivateInvoke.GetNonPublicField(_cache, "_constructorCalls"); _assembledType = ReflectionObjectMother.GetSomeType(); _delegateType = ReflectionObjectMother.GetSomeDelegateType(); _allowNonPublic = BooleanObjectMother.GetRandomBoolean(); _generatedCtorCall = new Func <int> (() => 7); }
public void IsStrongNamed() { var type = ReflectionObjectMother.GetSomeType(); var fakeResult = BooleanObjectMother.GetRandomBoolean(); _assemblyAnalyzerMock.Setup(x => x.IsStrongNamed(type.Assembly)).Returns(fakeResult).Verifiable(); var result1 = _analyzer.IsStrongNamed(type); var result2 = _analyzer.IsStrongNamed(type); _assemblyAnalyzerMock.Verify(); Assert.That(result1, Is.EqualTo(fakeResult)); Assert.That(result2, Is.EqualTo(fakeResult)); }
public void SetUp() { _declaringType = MutableTypeObjectMother.Create(); _isStatic = BooleanObjectMother.GetRandomBoolean(); _parameters = new[] { Expression.Parameter(typeof(int)), Expression.Parameter(typeof(object)) }; _baseMethod = ReflectionObjectMother.GetSomeMethod(); _genericParameters = new[] { ReflectionObjectMother.GetSomeGenericParameter() }; _returnType = ReflectionObjectMother.GetSomeType(); _previousBody = Expression.Block(_parameters[0], _parameters[1]); _context = new MethodBodyModificationContext( _declaringType, _isStatic, _parameters.AsOneTime(), _genericParameters.AsOneTime(), _returnType, _baseMethod, _previousBody); _contextWithoutPreviousBody = new MethodBodyModificationContext( _declaringType, _isStatic, _parameters, _genericParameters, _returnType, _baseMethod, null); }
public void InstantiateAssembledType_WithExactAssembledType() { var assembledType = ReflectionObjectMother.GetSomeType(); var arguments = ParamList.Create("abc", 7); var allowNonPublic = BooleanObjectMother.GetRandomBoolean(); _constructorForAssembledTypeCacheMock .Expect(mock => mock.GetOrCreateConstructorCall(assembledType, arguments.FuncType, allowNonPublic)) .Return(new Func <string, int, object> ((s, i) => "blub")); var result = _service.InstantiateAssembledType(assembledType, arguments, allowNonPublic); _typeCacheMock.VerifyAllExpectations(); Assert.That(result, Is.EqualTo("blub")); }
public void CreateInstance_WithConcreteType() { var allowNonPublicCtor = BooleanObjectMother.GetRandomBoolean(); var concreteType = TypeFactory.GetConcreteType(typeof(BaseType1)); var paramList = ParamList.Create("blub"); var fakeInstance = new object(); var reflectionServiceMock = MockRepository.GenerateStrictMock <IReflectionService>(); _defaultPipelineMock.Stub(_ => _.ReflectionService).Return(reflectionServiceMock); reflectionServiceMock.Expect(_ => _.InstantiateAssembledType(concreteType, paramList, allowNonPublicCtor)).Return(fakeInstance); var instance = _implementation.CreateInstance(allowNonPublicCtor, concreteType, paramList); reflectionServiceMock.VerifyAllExpectations(); Assert.That(instance, Is.SameAs(fakeInstance)); }
public void GetInterfaceMap_AllowPartialInterfaceMapping() { var interfaceType = typeof(IDomainInterface); var allowPartial = BooleanObjectMother.GetRandomBoolean(); var fakeResult = new InterfaceMapping { InterfaceType = ReflectionObjectMother.GetSomeType() }; _memberSelectorMock.Stub(stub => stub.SelectMethods <MethodInfo> (null, 0, null)).IgnoreArguments().Return(new MethodInfo[0]); _interfaceMappingComputerMock .Expect(mock => mock.ComputeMapping(_mutableType, typeof(DomainType).GetInterfaceMap, interfaceType, allowPartial)) .Return(fakeResult); var result = _mutableType.GetInterfaceMap(interfaceType, allowPartial); _interfaceMappingComputerMock.VerifyAllExpectations(); Assert.That(result, Is.EqualTo(fakeResult), "Interface mapping is a struct, therefore we must use EqualTo and a non-empty struct."); }