Example #1
0
export function useInjector() {
  var injector:ReflectiveInjector;

//#enddocregion injector
/*
//#docregion injector-no-new
  // Cannot 'new' an ReflectiveInjector like this!
  var injector = new ReflectiveInjector([Car, Engine, Tires, Logger]);
//#enddocregion injector-no-new
*/

//#docregion injector
  //#docregion injector-create-and-call
  injector = ReflectiveInjector.resolveAndCreate([Car, Engine, Tires, Logger]);
  //#docregion injector-call
  var car = injector.get(Car);
 //#enddocregion injector-call
 //#enddocregion injector-create-and-call
  car.description = 'Injector';

  var logger = injector.get(Logger);
  logger.log('Injector car.drive() said: '+car.drive());

  return car;
}
Example #2
0
    beforeEach(() => {

      injector = ReflectiveInjector.resolveAndCreate([
        StoreModule.provideStore({ todos, todoCount }).providers
      ]);

      store = injector.get(Store);
      dispatcher = injector.get(Dispatcher);
    });
    beforeEach(() => {
      locationService = injector.get(LocationService);

      navService = injector.get(NavigationService);
      navService.currentNode.subscribe(selected => currentNode = selected);

      const backend = injector.get(ConnectionBackend);
      backend.connectionsArray[0].mockRespond(createResponse(navJson));
    });
    beforeEach(() => {
      navService = injector.get(NavigationService);
      navService.versionInfo.subscribe(info => versionInfo = info);

      const backend = injector.get(ConnectionBackend);
      backend.connectionsArray[0].mockRespond(createResponse({
        __versionInfo: { raw: '4.0.0' }
      }));
    });
    beforeEach(() => {
      location = injector.get(LocationService);

      service = injector.get(NavigationService);
      service.selectedNodes.subscribe(nodes => currentNodes = nodes);

      const backend = injector.get(ConnectionBackend);
      backend.connectionsArray[0].mockRespond(createResponse({ nav: nodeTree }));
    });
Example #6
0
  beforeEach(() => {
    spyOn(Reducer, 'reduce').and.callThrough();

    injector = ReflectiveInjector.resolveAndCreate([
      StoreModule.provideStore(Reducer.reduce, initialState).providers
    ]);

    state = injector.get(State);
    dispatcher = injector.get(Dispatcher);
  });
  beforeEach(() => {
    injector = ReflectiveInjector.resolveAndCreate([
      ResourceService,
      { provide: ConnectionBackend, useClass: MockBackend },
      { provide: RequestOptions, useClass: BaseRequestOptions },
      Http
    ]);

    backend = injector.get(ConnectionBackend);
    resourceService = injector.get(ResourceService);
  });
    beforeEach(() => {
        const injector: ReflectiveInjector = DOTTestBed.resolveAndCreate([
            DotContainerContentletService
        ]);

        dotContainerContentletService = injector.get(DotContainerContentletService);
        backend = injector.get(ConnectionBackend);
        backend.connections.subscribe(
            (connection: MockConnection) => (lastConnection = connection)
        );
    });
 beforeEach(() => {
     injector = ReflectiveInjector.resolveAndCreate([
         AlfrescoSearchService,
         AlfrescoSettingsService,
         AlfrescoApiService,
         AlfrescoAuthenticationService,
         StorageService
     ]);
     service = injector.get(AlfrescoSearchService);
     apiService = injector.get(AlfrescoApiService);
     spyOn(apiService, 'getInstance').and.returnValue(fakeApi);
 });
  beforeEach(() => {
    injector = ReflectiveInjector.resolveAndCreate([
        ContributorService,
        { provide: ConnectionBackend, useClass: MockBackend },
        { provide: RequestOptions, useClass: BaseRequestOptions },
        Http,
        Logger
    ]);

    backend = injector.get(ConnectionBackend);
    contribService = injector.get(ContributorService);
  });
 beforeEach(() => {
     injector = ReflectiveInjector.resolveAndCreate([
         ActivitiProcessService,
         AlfrescoApiService,
         AlfrescoAuthenticationService,
         AlfrescoSettingsService,
         StorageService
     ]);
     service = injector.get(ActivitiProcessService);
     authenticationService = injector.get(AlfrescoAuthenticationService);
     apiService = injector.get(AlfrescoApiService);
     alfrescoApi = apiService.getInstance();
 });
    beforeEach(() => {
        coreWebServiceMock = new CoreWebServiceMock();

        injector = ReflectiveInjector.resolveAndCreate([
            { provide: CoreWebService, useValue: coreWebServiceMock },
            StringUtils,
            LoggerService
        ]);

        const loggerService = injector.get(LoggerService);

        longPollingProtocol = new LongPollingProtocol(url, loggerService, injector.get(CoreWebService));
    });
Example #13
0
  beforeEach(() => {
    spyOn(Reducer, 'reduce').and.callThrough();
    spyOn(Middleware, 'pre').and.callThrough();
    spyOn(Middleware, 'post').and.callThrough();

    injector = ReflectiveInjector.resolveAndCreate([
      provideStore(Reducer.reduce, initialState),
      usePreMiddleware(Middleware.pre),
      usePostMiddleware(Middleware.post)
    ]);

    backend = injector.get(StoreBackend);
    dispatcher = injector.get(Dispatcher);
  });
export function useInjector() {
    let injector: ReflectiveInjector;
    /*
     // Cannot instantiate an ReflectiveInjector like this!
     let injector = new ReflectiveInjector([Car, Engine, Tires]);
     */
    injector = ReflectiveInjector.resolveAndCreate([Car, Engine, Tires]);
    let car = injector.get(Car);
    car.description = 'Injector';

    injector = ReflectiveInjector.resolveAndCreate([Logger]);
    let logger = injector.get(Logger);
    logger.log('Injector car.drive() said: ' + car.drive());
    return car;
}
 beforeEach(() => {
   injector = ReflectiveInjector.resolveAndCreate([
     {provide: ConnectionBackend, useClass: MockBackend},
     {provide: RequestOptions, useClass: BaseRequestOptions},
     {provide: KeycloakService, useClass: MockKeycloakService},
     {
       provide: Http,
       useFactory: keycloakHttpFactory,
       deps: [ConnectionBackend, RequestOptions, KeycloakService]
     }
   ]);
   http = injector.get(Http);
   backend = injector.get(ConnectionBackend) as MockBackend;
   backend.connections.subscribe((c: MockConnection) => lastConnection = c);
 });
Example #16
0
  it('should call the reducer to scan over the dispatcher', function() {
    injector.get(Store);

    expect(reducer).toHaveBeenCalledWith(initialState, {
      type: INIT,
    });
  });
Example #17
0
    beforeEach(() => {
      const rootReducer = combineReducers({
        counter1: counterReducer,
        counter2: counterReducer,
        counter3: counterReducer
      });

      const initialValue = { counter1: 0, counter2: 1 };

      injector = ReflectiveInjector.resolveAndCreate([
        provideStore(rootReducer, initialValue)
      ]);

      store = injector.get(Store);
      dispatcher = injector.get(Dispatcher);
    });
Example #18
0
  /**
   * Resolve & retrieve an instance of the entity from the injector. Note that depending on the
   * provider definition, this could be a different class to the passed token
   * @param token
   * @returns {T}
   */
  protected getInstance<T extends Object>(token: RegistryEntityStatic<EntityMetadata>): T {
    const instance: T = this.injector.get(token);

    this.logger.info(`Resolved ${instance.constructor.name}`);

    return instance;
  }
Example #19
0
  beforeEach(() => {
    injector = ReflectiveInjector.resolveAndCreate([
      DB.DB_PROVIDERS,
      DB.provideDB(todoAppSchema)
    ]);

    idb = injector.get(DB.Database);
  });
  beforeEach(() => {
    sendMessageSpy = jasmine.createSpy('sendMessage').and.returnValue(Observable.of({}));
    mockWorker = { sendMessage: sendMessageSpy } as any;
    spyOn(WebWorkerClient, 'create').and.returnValue(mockWorker);

    injector = ReflectiveInjector.resolveAndCreate([
        SearchService,
        { provide: NgZone, useFactory: () => new NgZone({ enableLongStackTrace: false }) }
    ]);
    service = injector.get(SearchService);
  });
Example #21
0
export function useInjector() {
  let injector: ReflectiveInjector;
  // #enddocregion injector
  /*
  // #docregion injector-no-new
  // Cannot instantiate an ReflectiveInjector like this!
  let injector = new ReflectiveInjector([Car, Engine, Tires]);
  // #enddocregion injector-no-new
  */
  // #docregion injector, injector-create-and-call
  injector = ReflectiveInjector.resolveAndCreate([Car, Engine, Tires]);
  // #docregion injector-call
  let car = injector.get(Car);
  // #enddocregion injector-call, injector-create-and-call
  car.description = 'Injector';

  injector = ReflectiveInjector.resolveAndCreate([Logger]);
  let logger = injector.get(Logger);
  logger.log('Injector car.drive() said: ' + car.drive());
  return car;
}
    beforeEach(() => {
        injector = ReflectiveInjector.resolveAndCreate([
            AlfrescoApiService,
            AlfrescoAuthenticationService,
            AlfrescoContentService,
            AlfrescoSettingsService,
            AlfrescoThumbnailService,
            StorageService
        ]);

        service = injector.get(AlfrescoThumbnailService);
    });
Example #23
0
    beforeEach(() => {

        // TestBed.overrideComponent(NoContent, {
        //     set: {
        //     template: `<div>NoContent Component</div>
        //                <router-outlet></router-outlet>`,
        //     styleUrls: [``]
        //     }
        // });

        rootReducer = combineReducers({});

        injector = ReflectiveInjector.resolveAndCreate([
            StoreModule.provideStore(rootReducer, undefined).providers
        ]);

        store = injector.get(Store);

        TestBed.configureTestingModule({
            declarations: [NoContent],
            imports: [
                FormsModule,
                ReactiveFormsModule,
                RouterTestingModule.withRoutes([
                    {
                        path: '**',
                        loadChildren: () => System.import('app/components/shared/access/logon')
                    }
                ])
            ],
            providers: [
                LogService,
                provideStore(rootReducer, undefined),
                MockBackend,
                {
                    provide: Http,
                    useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
                        return new Http(backend, defaultOptions);
                    },
                    deps: [MockBackend, BaseRequestOptions]
                },
            ]
        });

        fixture = TestBed.createComponent(NoContent);
        noContent = fixture.debugElement.componentInstance;
    });
Example #24
0
  describe('todo integration spec', function() {

    let injector: ReflectiveInjector;
    let store: Store<TodoAppSchema>;
    let currentState: TodoAppSchema;

    const rootReducer = combineReducers({ todos, visibilityFilter });
    const initialValue = { todos: [], visibilityFilter: VisibilityFilters.SHOW_ALL };

    injector = ReflectiveInjector.resolveAndCreate([
      provideStore(rootReducer, initialValue)
    ]);

    store = injector.get(Store);

    store.subscribe(state => {
      currentState = state;
    });

    it('should successfully instantiate', () => {
      expect(store).toBeDefined();
    });

    it('should combine reducers automatically if a key/value map is provided', () => {
      const reducers = { test: function(){} };
      spyOn(reducers, 'test');
      const action = { type: 'Test Action' };
      const reducer = ReflectiveInjector.resolveAndCreate([ provideStore(reducers) ]).get(INITIAL_REDUCER);

      expect(reducer).toBeDefined();
      expect(typeof reducer === 'function').toBe(true);

      reducer(undefined, action);

      expect(reducers.test).toHaveBeenCalledWith(undefined, action);
    });

    it('should probe the reducer to resolve the initial state if no initial state is provided', () => {
      const reducer = () => 2;
      const initialState = ReflectiveInjector.resolveAndCreate([ provideStore(reducer) ]).get(INITIAL_STATE);

      expect(initialState).toBe(2);
    });

    it('should use a provided initial state', () => {
      const reducer = () => 2;
      const initialState = ReflectiveInjector.resolveAndCreate([ provideStore(reducer, 3) ]).get(INITIAL_STATE);

      expect(initialState).toBe(3);
    });

    it('should start with no todos and showing all filter', () => {
      expect(currentState.todos.length).toEqual(0);
      expect(currentState.visibilityFilter).toEqual(VisibilityFilters.SHOW_ALL);
    });

    it('should add a todo', () => {
      store.dispatch({ type: ADD_TODO, payload: { text: 'first todo' } });
      expect(currentState.todos.length).toEqual(1);

      expect(currentState.todos[0].text).toEqual('first todo');
      expect(currentState.todos[0].completed).toEqual(false);
      expect(currentState.todos[0].id).toEqual(1);
    });

    it('should add another todo', () => {
      store.dispatch({ type: ADD_TODO, payload: { text: 'second todo' } });
      expect(currentState.todos.length).toEqual(2);

      expect(currentState.todos[1].text).toEqual('second todo');
      expect(currentState.todos[1].completed).toEqual(false);
      expect(currentState.todos[1].id).toEqual(2);
    });

    it('should complete the first todo', () => {
      store.dispatch({ type: COMPLETE_TODO, payload: { id: 1 } });
      expect(currentState.todos.length).toEqual(2);

      expect(currentState.todos[0].text).toEqual('first todo');
      expect(currentState.todos[0].completed).toEqual(true);
      expect(currentState.todos[0].id).toEqual(1);
    });

    it('should use visibilityFilter to filter todos', () => {

      const filterVisibleTodos = (visibilityFilter, todos) => {
        let predicate;
        if (visibilityFilter === VisibilityFilters.SHOW_ALL) {
          predicate = () => true;
        }
        else if (visibilityFilter === VisibilityFilters.SHOW_ACTIVE) {
          predicate = (todo) => !todo.completed;
        }
        else {
          predicate = (todo) => todo.completed;
        }
        return todos.filter(predicate);
      };

      let currentlyVisibleTodos;

      Observable.combineLatest(store.select('visibilityFilter'), store.select('todos'), filterVisibleTodos)
        .subscribe(visibleTodos => {
          currentlyVisibleTodos = visibleTodos;
        });

      expect(currentlyVisibleTodos.length).toBe(2);

      store.dispatch({ type: SET_VISIBILITY_FILTER, payload: VisibilityFilters.SHOW_ACTIVE });

      expect(currentlyVisibleTodos.length).toBe(1);
      expect(currentlyVisibleTodos[0].completed).toBe(false);

      store.dispatch({ type: SET_VISIBILITY_FILTER, payload: VisibilityFilters.SHOW_COMPLETED });

      expect(currentlyVisibleTodos.length).toBe(1);
      expect(currentlyVisibleTodos[0].completed).toBe(true);

      store.dispatch({ type: COMPLETE_ALL_TODOS });

      expect(currentlyVisibleTodos.length).toBe(2);
      expect(currentlyVisibleTodos[0].completed).toBe(true);
      expect(currentlyVisibleTodos[1].completed).toBe(true);

      store.dispatch({ type: SET_VISIBILITY_FILTER, payload: VisibilityFilters.SHOW_ACTIVE });

      expect(currentlyVisibleTodos.length).toBe(0);

    });
  });
Example #25
0
 static dependencies(): {auth: AuthService, router: Router} {
   const injector: ReflectiveInjector = AuthRouteHelper.injector();
   const auth: AuthService = injector.get(AuthService);
   const router: Router = injector.get(Router);
   return {auth, router};
 }
 beforeEach(() => {
   backend = injector.get(ConnectionBackend);
   navService = injector.get(NavigationService);
 });
 it('should be creatable', () => {
   const service: NavigationService = injector.get(NavigationService);
   expect(service).toBeTruthy();
 });
Example #28
0
 it('GetItems() on fake Obj should work', () => {
     let sut: NanaDal = injector.get(NanaDal);
     sut.getItems().subscribe(data => {
         expect(data).toEqual({ NavigateID: 1, NavigateName: 'name1' });
     });
 });
Example #29
0
 beforeEach(() => {
   gaSpy = jasmine.createSpy('ga');
   mockWindow = { ga: gaSpy };
   injector = ReflectiveInjector.resolveAndCreate([GaService, { provide: WindowToken, useFactory: () => mockWindow }]);
   gaService = injector.get(GaService);
 });
Example #30
0
 /**
  * Kick off the bootstrapping function. The logger instance is assigned here as the injector is
  * not available at constructor time.
  * @returns {void|Promise<void>}
  */
 public invokeBootstrap(): void | Promise<void> {
   this.logger = this.injector.get(Logger)
     .source(this.constructor.name);
   return this.bootstrap();
 }