1

我正在测试用例中创建工厂

        + (TyphoonComponentFactory*)integrationTestFactory
{
    static TyphoonComponentFactory* factory;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^
    {
        factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[
            [MainAssembly assembly],
            [Kernel assembly],
            [NetworkComponents assembly],
            [PersistenceComponents assembly]
        ]];

        //Other config here. . . 
        TyphoonConfigPostProcessor *configurer = [TyphoonConfigPostProcessor configurer];
        [configurer useResourceWithName:@"testConfig.properties"];
        [factory attachPostProcessor:configurer];
        //this may be necessary
        [factory makeDefault 

    });
    return factory;
}

然后访问它

  - (void)setUp
{
    [super setUp];

    factory_instance = [LoginTest integrationTestFactory];
}

最后访问程序集给出了配置键未配置的错误值

DAO *dataManager = [(DaoAssembly*)factory_instance DAO];

组装如下

-(id)DAO {

return [TyphoonDefinition withClass:[DAO class] configuration:^(TyphoonDefinition* definition)
        {
            [definition useInitializer:@selector(shareManager)];
            [definition injectProperty:@selector(apikey) with:TyphoonConfig(@"api.key")];
            [definition injectProperty:@selector(dataParser) with:[self dataParser]];
            definition.scope = TyphoonScopeSingleton;

        }];

}

4

1 回答 1

0

正如以下测试用例所验证的,我无法重现您所遇到的情况。

请亲自尝试这个简单的示例 - 也许它会阐明问题所在。

SomeProperties.properties:

damsels.rescued=12

骑士.h/.m:

@interface Knight : NSObject

@property(nonatomic) NSUInteger damselsRescued;

@end

MyAssembly.m:

- (id)knight
{
    return [TyphoonDefinition withClass:[Knight class] configuration:
        ^(TyphoonDefinition *definition) {
        [definition injectProperty:@selector(damselsRescued)
             with:TyphoonConfig(@"damsels.rescued")];        
    }];
}

集成测试.m:

@interface IntegrationTests : XCTestCase
{
    TyphoonComponentFactory *_factory;
}


@end

@implementation IntegrationTests

+ (TyphoonComponentFactory *)integrationTestFactory
{
    static TyphoonComponentFactory *factory;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[
            [MyAssembly assembly],
        ]];

        //Other config here. . .
        TyphoonConfigPostProcessor *configurer = [TyphoonConfigPostProcessor configurer];
        [configurer useResourceWithName:@"SomeProperties.properties"];
        [configurer useResourceWithName:@"SomeOtherProperties.properties"];
        [factory attachPostProcessor:configurer];
        [factory makeDefault];
    });
    return factory;
}


- (void)setUp
{
    _factory = [IntegrationTests integrationTestFactory];
}

- (void)testPropertiesAreSet
{
    Knight *knight = [(InfrastructureComponentsAssembly *) _factory knight];
    XCTAssertEqual(knight.damselsRescued, 12);
}

@end
于 2014-06-18T03:03:37.763 回答