public void ApplicationCanCreateRuntimeTypeForValidType() { // arrange var type = typeof(Aggregate); var typeAnalyzerService = A.Fake<ITypeAnalyzerService>(o => o.Strict()); A.CallTo(() => typeAnalyzerService.IsValidAggregateRoot(type)).Returns(true); A.CallTo(() => typeAnalyzerService.IsValidEntity(type)).Returns(true); A.CallTo(() => typeAnalyzerService.GetNaturalKey(type)).Returns(null); A.CallTo(() => typeAnalyzerService.IsValidAggregateRoot(typeof(AggregateRoot))).Returns(true); A.CallTo(() => typeAnalyzerService.IsValidEntity(typeof(AggregateRoot))).Returns(true); A.CallTo(() => typeAnalyzerService.GetNaturalKey(typeof(AggregateRoot))).Returns(null); A.CallTo(() => typeAnalyzerService.IsValidEntity(typeof(Entity))).Returns(true); A.CallTo(() => typeAnalyzerService.GetNaturalKey(typeof(Entity))).Returns(null); var entityType = new EntityType(typeof(Entity), typeAnalyzerService); var aggregateType = new AggregateRootType(typeof(AggregateRoot), typeAnalyzerService, entityType); var expectedType = new AggregateRootType(type, typeAnalyzerService, aggregateType); var factory = A.Fake<Func<Type, AggregateRootType>>(o => o.Strict()); A.CallTo(() => factory.Invoke(type)).Returns(expectedType); using (new Application(factory, t => null, t => null)) { // act var actualType = Application.Current.GetAggregateRootType(type); // assert actualType.Should().Be(expectedType); } }
/// <summary> /// Initializes a new instance of the <see cref="AggregateRootType"/> class. /// </summary> /// <param name="runtimeType">The runtime type.</param> /// <param name="typeAnalyzerService">The type analyzer service.</param> /// <param name="baseEntity">The base entity.</param> public AggregateRootType(Type runtimeType, ITypeAnalyzerService typeAnalyzerService, EntityType baseEntity) : base(runtimeType, typeAnalyzerService, baseEntity) { Guard.Against.Null(() => runtimeType); Guard.Against.Null(() => typeAnalyzerService); if (!typeAnalyzerService.IsValidAggregateRoot(runtimeType)) { throw new BusinessException( string.Format(CultureInfo.InvariantCulture, "The specified runtime type '{0}' is not an aggregate root.", runtimeType)); } // NOTE (Cameron): Defaults. this.EventDispatcher = new DefaultEventDispatcher(runtimeType); }
/// <summary> /// Initializes a new instance of the <see cref="EntityType"/> class. /// </summary> /// <param name="runtimeType">Type of the runtime.</param> /// <param name="entityAnalyzerService">The entity analyzer service.</param> /// <param name="baseEntity">The base entity.</param> public EntityType(Type runtimeType, ITypeAnalyzerService entityAnalyzerService, EntityType baseEntity) : this(runtimeType, entityAnalyzerService) { Guard.Against.Null(() => runtimeType); Guard.Against.Null(() => baseEntity); if (baseEntity.RuntimeType != runtimeType.BaseType) { throw new BusinessException( string.Format( CultureInfo.InvariantCulture, "The specified base entity runtime type '{0}' does not match the runtime type base type '{1}'.", baseEntity.RuntimeType, runtimeType.BaseType)); } this.baseEntityNaturalKey = baseEntity.NaturalKey; }
public EntityType Create(Type type) { var entityType = default(EntityType); foreach (var subType in type.GetTypeHierarchyUntil(typeof(object)).Reverse()) { if (entityType == null) { entityType = new EntityType(subType, this.typeAnalyzerService); continue; } entityType = new EntityType(subType, this.typeAnalyzerService, entityType); } var configuration = new BootstrapperConfiguration(entityType, this.typeAnalyzerService); var bootstrapper = this.bootstrapperProvider.GetBootstrapper(type); bootstrapper.Invoke(configuration); return entityType; }
public TypeInformation(EntityType entityType) { Guard.Against.Null(() => entityType); this.GetNaturalKeyValue = entityType.NaturalKey == null ? (Func<Entity, object>)null : entity => entityType.NaturalKey.GetValue(entity); }