예제 #1
0
        public void Constructor_ValidParameters_BooksCollectionInstaniated()
        {
            // Act
            IBookManager bookManager = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, bookController.Object);

            // Assert
            Assert.NotNull(bookManager.Books, "the constructor should instantiate it");
        }
예제 #2
0
        public void AddBook_InvalidEntityParameter_ArgumentExceptionThrown(string entity)
        {
            // Arrange
            IBookManager bookManager = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, bookController.Object);

            // Act
            bookManager.AddBook("test bookCode", entity, true);
        }
예제 #3
0
        public void RemoveBook_InvalidBookCodeParameter_ArgumentExceptionThrown(String bookCode)
        {
            // Arrange
            IBookManager bookManager = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, bookController.Object);

            // Act
            bookManager.RemoveBook(bookCode);
        }
예제 #4
0
        public void SaveToDatabase_InvalidBookCodeParameter_ArgumentExceptionThrown(String bookCode)
        {
            // Arrange
            IBookManager bookManager = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, bookController.Object);

            // Act
            bookManager.SaveToDatabase(bookCode, "test entity", true);
        }
예제 #5
0
        public void AddBook_ValidParameters_BooksCollectionPopulated()
        {
            // Arrange
            IBookManager bookManager = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, bookController.Object);

            // Act
            bookManager.AddBook("test bookCode", "test entity", true);
            // Assert
            Assert.IsNotEmpty(bookManager.Books, "because a new book is added to the collection by AddBook");
        }
예제 #6
0
        public void Initialize_StandAloneMode_BooksCollectionPopulated()
        {
            // Arrange
            IBookManager bookManager = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, bookController.Object);

            configManagerMock.Setup(cm => cm.IsStandAlone).Returns(true);
            // Act
            bookManager.Initialize();
            // Assert
            Assert.IsNotEmpty(bookManager.Books, "because it is populated in standalone mode.");
        }
예제 #7
0
        public void AddBook_ValidParameters_NewBookEventShouldBePublished()
        {
            // Arrange
            IBookManager bookManager = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, bookController.Object);
            var          wasCalled   = false;

            eventAggregatorMock.Setup(ea => ea.GetEvent <NewBookEvent>().Publish(It.IsAny <NewBookEventPayload>())).Callback(() => wasCalled = true);
            // Act
            bookManager.AddBook("test bookCode", "test entity", true);
            // Assert
            Assert.IsTrue(wasCalled, "because a new book is published to all listeners by the AddBook method.");
        }
예제 #8
0
 public void Constructor_NullBookControllerProxy_ArgumentNullExceptionThrown()
 {
     // Act
     var test = new BookManagerImpl(configManagerMock.Object, eventAggregatorMock.Object, null);
 }
예제 #9
0
 public void Constructor_NullConfigManager_ArgumentNullExceptionThrown()
 {
     // Act
     var test = new BookManagerImpl(null, eventAggregatorMock.Object, bookController.Object);
 }
예제 #10
0
        public void Initialize()
        {
            var configManager = new ConfigurationManagerImpl();

            container.RegisterInstance <IConfigurationManager>(configManager);
            configManager.Initialize();

            var tasks = new Task[7];

            var underlyingManager = new UnderlyingManagerImpl(configManager, eventAggregator);

            container.RegisterInstance <IUnderlyingManager>(underlyingManager);
            tasks[0] = Task.Factory.StartNew(() => underlyingManager.Initialize());

            var clientManager = new ClientManagerImpl(configManager, eventAggregator);

            container.RegisterInstance <IClientManager>(clientManager);
            tasks[1] = Task.Factory.StartNew(() => clientManager.Initialize());

            var bookManager = new BookManagerImpl(configManager, eventAggregator, new BookControllerClient());

            container.RegisterInstance <IBookManager>(bookManager);
            tasks[2] = Task.Factory.StartNew(() => bookManager.Initialize());

            var bankHolidayManager = new BankHolidayManagerImpl(configManager, eventAggregator);

            container.RegisterInstance <IBankHolidayManager>(bankHolidayManager);
            tasks[3] = Task.Factory.StartNew(() => bankHolidayManager.Initialize());

            var searchManager = new SearchManagerImpl(configManager, eventAggregator);

            container.RegisterInstance <ISearchManager>(searchManager);
            tasks[4] = Task.Factory.StartNew(() => searchManager.Initialize());

            var userManager = new UserManagerImpl(configManager, eventAggregator, new UserControllerClient());

            container.RegisterInstance <IUserManager>(userManager);
            tasks[5] = Task.Factory.StartNew(() => userManager.Initialize());

            var groupManager = new GroupManagerImpl(configManager, eventAggregator, new GroupControllerClient());

            container.RegisterInstance <IGroupManager>(groupManager);
            tasks[6] = Task.Factory.StartNew(() => groupManager.Initialize());

            var optionRequestPersistanceManager = new OptionRequestPersistanceManagerImpl(clientManager, configManager);

            container.RegisterInstance <IOptionRequestPersistanceManager>(optionRequestPersistanceManager);

            container.RegisterType <IOptionRequestParser, OptionRequestParserImpl>(new ContainerControlledLifetimeManager())
            .RegisterType <IOptionRequestPricer, OptionRequestPricerImpl>(new ContainerControlledLifetimeManager())
            .RegisterType <IChatServiceManager, ChatServiceManagerImpl>(new ContainerControlledLifetimeManager())
            .RegisterType <IReportDataManager, ReportDataManagerImpl>(new ContainerControlledLifetimeManager())
            .RegisterInstance(new JsonParserImpl());

            InitializeServerCommunicator(configManager.IsStandAlone);

            // Exceptions thrown by tasks will be propagated to the main thread
            // while it waits for the tasks. The actual exceptions will be wrapped in AggregateException.
            try
            {
                // Wait for all the tasks to finish.
                Task.WaitAll(tasks);

                if (log.IsDebugEnabled)
                {
                    log.Debug("Successfully completed initialization of all service implementations");
                }
            }
            catch (AggregateException e)
            {
                foreach (var exception in e.InnerExceptions)
                {
                    log.Error("Catastrophic failure! Exception thrown: " + exception);
                    throw new ModuleInitializeException();
                }
            }
        }