public void RegisterSingleByAction_WithAbstractType_ThrowsException()
        {
            // Arrange
            string expectedParameterName = "TConcrete";
            string expectedMessage = "IWeapon is not a concrete type.";

            var container = new SimpleServiceLocator();

            Action<IWeapon> validInstanceInitializer = _ => { };

            try
            {
                // Act
                container.RegisterSingle<IWeapon>(validInstanceInitializer);

                // Assert
                Assert.Fail("The registration was expected to fail, because IWeapon is not a concrete type.");
            }
            catch (ArgumentException ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException), "No sub type should be thrown.");

                Assert.IsTrue(ex.Message.Contains(expectedMessage), "Actual message: " + ex.Message);

                Assert.AreEqual(expectedParameterName, ex.ParamName);
            }
        }
        public void Constructor_ShouldCallTextboxConstructorWithNameEqualTablenamePlusFieldName()
        {
            //mock the service locator
            var ServiceLocatorMock = new Mock <ISimpleServiceLocator>();

            SimpleServiceLocator.SetServiceLocatorProvider(ServiceLocatorMock.Object);


            //var headerTextBoxMockLeft = new Mock<ITableHeaderTextBox>();
            //headerTextBoxMockLeft.Setup(x => x.TextboxStyle.TextAlign).Returns("");

            //ServiceLocatorMock.Setup(x => x.Get<ITableHeaderTextBox>
            //    ("TableHeaderTextBox", It.IsAny<Dictionary<string, object>>())).Returns(headerTextBoxMockLeft.Object);

            List <DataItem> fieldList = new List <DataItem>
            {
                //char datatype selects left aligned
                new DataItem {
                    Name = "Item1", Caption = "Cap1", DataType = "char"
                },
            };

            var mockRepository = new Moq.Mock <IDataTableRepository>();

            mockRepository.Setup(x => x.GetByCode(It.IsAny <Guid>())).Returns(new DataTable {
                Name = "TestTable"
            });

            TableHeader target = new TableHeader(fieldList, mockRepository.Object, new DataModel());

            ServiceLocatorMock.Verify(x => x.Get <ITableHeaderTextBox>
                                          ("TableHeaderTextBox", It.Is <Dictionary <string, object> >(y => y["name"] == "TestTableCap1" && y["caption"] == "Cap1")), Times.Once());
        }
示例#3
0
        public static void InitializeIoc()
        {
            // Outside "if" to reduce contention
            if (null == SimpleServiceLocator.Instance)
            {
                // Only one thread to execute this code to determine if the servicelocator has alerady been created.
                lock (_lockObject)
                {
                    if (null == SimpleServiceLocator.Instance)
                    {
                        // Call this method at App level e.g. Global.asax to ensure object referenced for app lifetime.
                        SimpleServiceLocator.SetServiceLocatorProvider(new UnityServiceLocator());

                        // UnitOfWork
                        SimpleServiceLocator.Instance.Register(typeof(IUnitOfWork), typeof(UnitOfWork));

                        // Register Context
                        SimpleServiceLocator.Instance.RegisterWithConstructorParameters(typeof(IObjectContext), typeof(AdepUcbDBEntities));
                        SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IObjectContext, AdepUcbDBEntities>("AdepUcbDBEntities", new object[0]);

                        //Register Generic Repositories
                        SimpleServiceLocator.Instance.Register(typeof(IRepository <>), typeof(Repository <>));
                    }
                }
            }
        }
示例#4
0
        public void TestAccessingExpiredTokenResource()
        {
            ResourceContext context = new ResourceContext();

            context.Headers = new NameValueCollection();
            context.Headers["Authorization"] = "bearer my-token";

            IAccessToken expiredToken = new AccessTokenBase
            {
                Token     = "my-token",
                ExpiresIn = 2,
                IssuedOn  = DateTime.Now.AddMinutes(-1).ToEpoch()
            };
            Mock <ContextProcessor <IResourceContext> > mckProvider = new Mock <ContextProcessor <IResourceContext> >(new Mock <IServiceFactory>().Object);

            mckProvider.Setup(x => x.IsSatisfiedBy(context)).Returns(true);
            mckProvider.Setup(x => x.Process(context)).Callback(() => context.Token = expiredToken);

            SimpleServiceLocator container = new SimpleServiceLocator();

            container.RegisterAll <ContextProcessor <IResourceContext> >(mckProvider.Object);

            ServiceLocator.SetLocatorProvider(() => container);

            ResourceProvider provider = new ResourceProvider();

            CommonErrorAssert(context, provider, Parameters.ErrorParameters.ErrorValues.InvalidToken);

            mckProvider.Verify();
        }
示例#5
0
        public void TestUnhandledGrantTypeContext()
        {
            TokenContext context = new TokenContext
            {
                AuthorizationCode = "auth-code",
                Client = new ClientBase { ClientId = "client-id", ClientSecret = "secret" },
                GrantType = Parameters.GrantTypeValues.AuthorizationCode,
                RedirectUri = new Uri("http://www.mysite.com/callback")
            };

            Mock<IServiceFactory> mckServiceFactory = new Mock<IServiceFactory>();
            Mock<IContextInspector<ITokenContext>> mckInspector = new Mock<IContextInspector<ITokenContext>>();
            Mock<ContextProcessor<ITokenContext>> mckUnsupportedProcessor = new Mock<ContextProcessor<ITokenContext>>(mckServiceFactory.Object);
            mckUnsupportedProcessor.Setup(x => x.IsSatisfiedBy(context)).Returns(false);


            SimpleServiceLocator locator = new SimpleServiceLocator();
            locator.RegisterAll<ContextProcessor<ITokenContext>>(mckUnsupportedProcessor.Object);
            locator.RegisterAll<IContextInspector<ITokenContext>>(mckInspector.Object);
            ServiceLocator.SetLocatorProvider(() => locator);

            TokenProvider provider = new TokenProvider();

            provider.GrantAccessToken(context);
        }
示例#6
0
        public void TestAccessingProtectedResource()
        {
            ResourceContext context = new ResourceContext();

            context.Headers = new NameValueCollection();
            context.Headers["Authorization"] = "bearer my-token";

            Mock <ContextProcessor <IResourceContext> > mckProvider = new Mock <ContextProcessor <IResourceContext> >(new Mock <IServiceFactory>().Object);

            mckProvider.Setup(x => x.IsSatisfiedBy(context)).Returns(true);
            mckProvider.Setup(x => x.Process(context)).Callback(() => { context.Token = new AccessTokenBase(); });

            SimpleServiceLocator container = new SimpleServiceLocator();

            container.RegisterAll <ContextProcessor <IResourceContext> >(mckProvider.Object);

            ServiceLocator.SetLocatorProvider(() => container);

            ResourceProvider provider = new ResourceProvider();

            provider.AccessProtectedResource(context);


            mckProvider.Verify();
        }
示例#7
0
        public static void InitializeIoc()
        {
            SimpleServiceLocator.SetServiceLocatorProvider(new UnityServiceLocator());
            SimpleServiceLocator.Instance.Register <IReportWizardViewModel, ReportWizardViewModel>();
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IReportListViewModel, ReportListViewModel>(new object[] { });
            SimpleServiceLocator.Instance.Register <IParticipantCsvToXmlConverterViewModel, ParticipantCsvToXmlConverterViewModel>();
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IUploadedFileMonitorViewModel, UploadedParticipantViewModel>(new object[] { });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IUploadFileViewModel, UploadFileViewModel>(new object[] { });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <ITransferPostCodeFilesViewModel, TransferPostCodeFilesViewModel>(new object[] { });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IJobQueueMonitorViewModel, JobQueueMonitorViewModel>(new object[] { });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IUploadDecisionViewModel, UploadDecisionViewModel>(new object[] { });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IUploadHistoryViewModel, UploadHistoryViewModel>(new object[] { });
            SimpleServiceLocator.Instance.Register <ILogoTimeSpinnerViewModel, LogoTimeSpinnerViewModel>();
            SimpleServiceLocator.Instance.Register <ISelectReportGroupViewModel, SelectReportGroupViewModel>();
            SimpleServiceLocator.Instance.Register <ISelectReportModelDialogViewModel, SelectReportModelDialogViewModel>();
            SimpleServiceLocator.Instance.Register <IAdvancedJoinViewModel, AdvancedJoinViewModel>();
            SimpleServiceLocator.Instance.Register <IESFTickerViewModel, FakeESFTickerViewModel>();
            SimpleServiceLocator.Instance.Register <IEditDataItemViewModel, EditDataItemViewModel>();
            SimpleServiceLocator.Instance.Register <IPublishToUcbViewModel, PublishToUcbViewModel>();
            SimpleServiceLocator.Instance.Register <IReportGroupPermissionsViewModel, ReportGroupPermissionsViewModel>();
            SimpleServiceLocator.Instance.Register <IMainPageViewModel, MainPageViewModel>();
            //SimpleServiceLocator.Instance.Register<ITimelineViewModel, TimelineViewModel>();

            SimpleServiceLocator.Instance.Register <IModalDialogService, ModalDialogService>();
            SimpleServiceLocator.Instance.Register <INavigationService, PageNavigationService>();
            SimpleServiceLocator.Instance.Register <IMessageBoxService, MessageBoxService>();
            SimpleServiceLocator.Instance.Register <IModalWindow, SelectReportGroupDialog>("SelectReportGroupDialog");
            SimpleServiceLocator.Instance.Register <IModalWindow, AdvancedJoinDialog>("AdvancedJoinDialog");
            SimpleServiceLocator.Instance.Register <IModalWindow, EditDataItemDialog>("EditDataItemDialog");
            SimpleServiceLocator.Instance.Register <IModalWindow, PublishToUcbDialog>("PublishToUcbDialog");
            SimpleServiceLocator.Instance.Register <IModalWindow, ReportGroupPermissions>("ReportGroupPermissions");

            SimpleServiceLocator.Instance.Register <IModalWindow, SelectReportModelDialog>("SelectReportModelDialog");
        }
示例#8
0
        public void RegisterSingleByAction_WithAbstractType_ThrowsException()
        {
            // Arrange
            string expectedParameterName = "TConcrete";
            string expectedMessage       = "IWeapon is not a concrete type.";

            var container = new SimpleServiceLocator();

            Action <IWeapon> validInstanceInitializer = _ => { };

            try
            {
                // Act
                container.RegisterSingle <IWeapon>(validInstanceInitializer);

                // Assert
                Assert.Fail("The registration was expected to fail, because IWeapon is not a concrete type.");
            }
            catch (ArgumentException ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException), "No sub type should be thrown.");

                Assert.IsTrue(ex.Message.Contains(expectedMessage), "Actual message: " + ex.Message);

                Assert.AreEqual(expectedParameterName, ex.ParamName);
            }
        }
        public void TableHeaderTextBoxRender2010_ShouldRenderTextBoxRdlFragment()
        {
            var ServiceLocatorMock = new Mock <ISimpleServiceLocator>();

            SimpleServiceLocator.SetServiceLocatorProvider(ServiceLocatorMock.Object);

            var reportingStyleLeftMock = new Mock <IReportingServicesStyle>();

            reportingStyleLeftMock.Setup(x => x.TextAlign).Returns("");

            ServiceLocatorMock.Setup(x => x.Get <IReportingServicesStyle>
                                         ("ReportingServicesStyle", It.IsAny <Dictionary <string, object> >())).Returns(reportingStyleLeftMock.Object);

            string             name    = "Field1";
            string             caption = "Caption1";
            TableHeaderTextBox target  = new TableHeaderTextBox(name, caption);
            //Create stringbuilder for the xmlwriter
            StringBuilder sb = new StringBuilder();

            using (XmlWriter xmlWriter = XmlWriter.Create(sb))
            {
                //method under test
                target.Render2010(xmlWriter);

                //flush the output and grab the xml chunk
                xmlWriter.Flush();
                string outputRdl = sb.ToString();

                //compare output with expected xml
                XmlAssert.AreEqual(outputRdl, "<TablixCell><CellContents><Textbox Name=\"HeaderField1\"><Paragraphs><Paragraph><TextRuns><TextRun><Value>Caption1</Value></TextRun></TextRuns></Paragraph></Paragraphs><CanGrow>true</CanGrow><Top>0in</Top><Left>0in</Left><Width>.5in</Width></Textbox></CellContents></TablixCell>");
            }
        }
示例#10
0
        public static void InitNhibernate(SimpleServiceLocator ssl = null)
        {
            if (ssl == null)
            {
                ssl = new SimpleServiceLocator();
            }

            ssl.RegisterSingle <IUserDb>(new UserDb());
            ssl.RegisterSingle <IBranchDb>(new BranchDb());
            ssl.RegisterSingle <ICustomerDb>(new CustomerDb());
            ssl.RegisterSingle <ICustomerAccountsDb>(new CustomerAccountsDb());
            ssl.RegisterSingle <IGlCategoryDb>(new GlCategoryDb());
            ssl.RegisterSingle <IGlAccountDb>(new GlAccountDb());
            ssl.RegisterSingle <ISavingsConfigDb>(new SavingsConfigDb());
            ssl.RegisterSingle <ICurrentConfigDb>(new CurrentConfigDb());
            ssl.RegisterSingle <ILoanConfigDb>(new LoanConfigDb());
            ssl.RegisterSingle <ITellerDb>(new TellerDb());
            ssl.RegisterSingle <IGlPostingDb>(new GlPostingDb());
            ssl.RegisterSingle <ITellerPostingDb>(new TellerPostingDb());
            ssl.RegisterSingle <ILoanAccountDb>(new LoanAccountDb());
            ssl.RegisterSingle <IEODDb>(new EODDb());
            ssl.RegisterSingle <IOnUsWithdrawalDb>(new OnUsWithdrawalDb());


            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => ssl);
        }
示例#11
0
        public void TestUnhandledGrantTypeContext()
        {
            TokenContext context = new TokenContext
            {
                AuthorizationCode = "auth-code",
                Client            = new ClientBase {
                    ClientId = "client-id", ClientSecret = "secret"
                },
                GrantType   = Parameters.GrantTypeValues.AuthorizationCode,
                RedirectUri = new Uri("http://www.mysite.com/callback")
            };

            Mock <IServiceFactory> mckServiceFactory = new Mock <IServiceFactory>();
            Mock <IContextInspector <ITokenContext> > mckInspector            = new Mock <IContextInspector <ITokenContext> >();
            Mock <ContextProcessor <ITokenContext> >  mckUnsupportedProcessor = new Mock <ContextProcessor <ITokenContext> >(mckServiceFactory.Object);

            mckUnsupportedProcessor.Setup(x => x.IsSatisfiedBy(context)).Returns(false);


            SimpleServiceLocator locator = new SimpleServiceLocator();

            locator.RegisterAll <ContextProcessor <ITokenContext> >(mckUnsupportedProcessor.Object);
            locator.RegisterAll <IContextInspector <ITokenContext> >(mckInspector.Object);
            ServiceLocator.SetLocatorProvider(() => locator);

            TokenProvider provider = new TokenProvider();

            provider.GrantAccessToken(context);
        }
示例#12
0
        public static void InitializeIoc()
        {
            // Outside "if" to reduce contention
            if (null == SimpleServiceLocator.Instance)
            {
                // Only one thread to execute this code to determine if the servicelocator has alerady been created.
                lock (_lockObject)
                {
                    if (null == SimpleServiceLocator.Instance)
                    {
                        SimpleServiceLocator.SetServiceLocatorProvider(new UnityServiceLocator());

                        // UnitOfWork
                        // SimpleServiceLocator.Instance.RegisterWithConstructorParameters<IUnitOfWork, UnitOfWork>("ManagementConsole", new object[] { "ManagementConsole" });
                        SimpleServiceLocator.Instance.Register(typeof(IUnitOfWork), typeof(UnitOfWork));

                        // Register Context
                        SimpleServiceLocator.Instance.RegisterWithConstructorParameters(typeof(IObjectContext), typeof(AdepDatabaseEntities));
                        SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IObjectContext, AdepDatabaseEntities>("AdepDatabaseEntities", new object[0]);

                        //Register Generic Repositories
                        SimpleServiceLocator.Instance.Register(typeof(IRepository <>), typeof(Repository <>));
                    }
                }
            }
        }
示例#13
0
        public void RegisterSingleByAction_WithValidAction_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            // Act
            container.RegisterSingle <Samurai>(samurai => { });
        }
        public void SetUp(IServiceFactory factory)
        {
            SimpleServiceLocator container = new SimpleServiceLocator();

            container.RegisterAll <IContextInspector <IAuthorizationContext> >(new SpecificationInspector());
            container.RegisterAll <ContextProcessor <IAuthorizationContext> >(new AuthorizationCodeProcessor(factory));
            ServiceLocator.SetLocatorProvider(() => container);
        }
        /// <summary>
        /// Setup the SUT and dependencies
        /// </summary>
        protected override void GivenThat()
        {
            base.GivenThat();

            this.Sut = new SimpleServiceLocator();

            this.Sut.Register<IDontKnow>(new NotSure());
        }
        public void RegisterSingleByAction_WithValidAction_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            // Act
            container.RegisterSingle<Samurai>(samurai => { });
        }
示例#17
0
        public void RegisterSingleByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterSingleFuncByKey_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterSingleByKey <Samurai>("Sammy the Samurai", () => new Samurai(null));

            // Act
            container.RegisterSingle <Samurai>(_ => { });
        }
示例#18
0
        public void RegisterSingleByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterSingleByAction_ThrowsException()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterSingle <Samurai>(_ => { });

            // Act
            container.RegisterSingle <Samurai>(_ => { });
        }
        public void RegisterByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterByKeyedFunc_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterByKey <Samurai>(key => new Samurai(null));

            // Act
            container.Register <Samurai>(_ => { });
        }
示例#20
0
        public void RegisterSingleByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterAll_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterAll <Samurai>(new[] { new Samurai(null) });

            // Act
            container.RegisterSingle <Samurai>(_ => { });
        }
示例#21
0
        public void RegisterSingleByAction_WithNullArgument_ThrowsException()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            Action <Samurai> invalidInstanceInitializer = null;

            // Act
            container.RegisterSingle <Samurai>(invalidInstanceInitializer);
        }
        public void RegisterSingleByAction_WithNullArgument_ThrowsException()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            Action<Samurai> invalidInstanceInitializer = null;

            // Act
            container.RegisterSingle<Samurai>(invalidInstanceInitializer);
        }
        /// <summary>
        /// Setup the service locator
        /// </summary>
        protected override void GivenThat()
        {
            base.GivenThat();

            var srv = new SimpleServiceLocator();

            srv.Register<IDontKnow>(new NotSure());

            ServiceLocator.Initialize(srv);
        }
示例#24
0
        public void RegisterSingleByAction_CalledAfterCallToGetInstance_ThrowsException()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.Register <IWeapon>(() => new Katana());
            container.GetInstance <IWeapon>();

            Action <Samurai> validInstanceInitializer = _ => { };

            // Act
            container.RegisterSingle <Samurai>(validInstanceInitializer);
        }
        public void TableHeaderTextBoxConstructor_ShouldSetTheNameAndCaptionProperties()
        {
            var ServiceLocatorMock = new Mock <ISimpleServiceLocator>();

            SimpleServiceLocator.SetServiceLocatorProvider(ServiceLocatorMock.Object);

            string             name           = "Table1";
            string             caption        = "Caption1";
            bool               isRightAligned = false;
            TableHeaderTextBox target         = new TableHeaderTextBox(name, caption, isRightAligned);

            Assert.AreEqual(target.Name, "Table1");
            Assert.AreEqual(target.Caption, "Caption1");
        }
        public static void InitializeIoc()
        {
            // Create and store instance of ServiceLocator
            // Call this method at App level e.g. Global.asax to ensure object referenced for app lifetime.
            SimpleServiceLocator.SetServiceLocatorProvider(new UnityServiceLocator());

            // UnitOfWork
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IUnitOfWork, UnitOfWork>("UcbManagementInformation", new object[] { "UcbManagementInformation" });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IUnitOfWork, UnitOfWork>("Ucb", new object[] { "Ucb" });

            // Register Context
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IObjectContext, UcbManagementInformationEntities>("UcbManagementInformation", new object[] {});
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IObjectContext, AdepUcbEntities>("Ucb", new object[] { });

            //Register Generic Repositories
            SimpleServiceLocator.Instance.Register(typeof(IUcbManagementInformationRepository <>), typeof(UcbManagementInformationRepository <>));
            SimpleServiceLocator.Instance.Register(typeof(IUcbRepository <>), typeof(UcbRepository <>));

            //Reporting Services 2010
            SimpleServiceLocator.Instance.Register(typeof(IReportingServices), typeof(ReportingServices));

            //Register Specialised UcbManagementInformation Repositories
            SimpleServiceLocator.Instance.Register <IDataItemRepository, DataItemRepository>();
            SimpleServiceLocator.Instance.Register <IDataTableJoinRepository, DataTableJoinRepository>();
            SimpleServiceLocator.Instance.Register <IDataTableRelationshipJoinRepository, DataTableRelationshipJoinRepository>();
            SimpleServiceLocator.Instance.Register <IDataTableRelationshipRepository, DataTableRelationshipRepository>();
            SimpleServiceLocator.Instance.Register <IDataTableRepository, DataTableRepository>();
            SimpleServiceLocator.Instance.Register <IDataModelRepository, DataModelRepository>();
            SimpleServiceLocator.Instance.Register <IMCUserRepository, MCUserRepository>();

            SimpleServiceLocator.Instance.Register <IReportGroupRepository, ReportGroupRepository>();
            //Register Specialised MI Repositories


            //ReportEngine
            //SimpleServiceLocator.Instance.Register<IReportingServicesStyle, ReportingServicesStyle>();// ("ReportingServicesStyle");
            //SimpleServiceLocator.Instance.Register<IReportingServicesStyle, ReportingServicesStyle>("ReportingServicesStyleRight");
            //SimpleServiceLocator.Instance.Register<ITableHeaderTextBox, TableHeaderTextBox>();
            // SimpleServiceLocator.Instance.Register<ITableHeaderTextBox, TableHeaderTextBox>();

            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IReportingServicesStyle, ReportingServicesStyle>
                ("ReportingServicesStyle", new object[] { ReportingServicesStyle.TextBoxStyle.TableHeaderTextBox });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <IReportingServicesStyle, ReportingServicesStyle>
                ("ReportingServicesStyleRight", new object[] { ReportingServicesStyle.TextBoxStyle.TableHeaderTextBox, "Right" });
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <ITableHeaderTextBox, TableHeaderTextBox>
                ("TableHeaderTextBox", "", "");
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters <ITableHeaderTextBox, TableHeaderTextBox>
                ("TableHeaderTextBoxRight", "", "", true);
        }
示例#27
0
        public static void InitializeIoc()
        {
            // Call this method at App level e.g. Global.asax to ensure object referenced for app lifetime.
            SimpleServiceLocator.SetServiceLocatorProvider(new UnityServiceLocator());

            // UnitOfWork
            // SimpleServiceLocator.Instance.RegisterWithConstructorParameters<IUnitOfWork, UnitOfWork>("ManagementConsole", new object[] { "ManagementConsole" });
            SimpleServiceLocator.Instance.Register(typeof(IUnitOfWork), typeof(UnitOfWork));

            // Register Context
            SimpleServiceLocator.Instance.RegisterWithConstructorParameters(typeof(IObjectContext), typeof(AdepDatabaseEntities));

            //Register Generic Repositories
            SimpleServiceLocator.Instance.Register(typeof(IRepository <>), typeof(Repository <>));
        }
示例#28
0
        public void RegisterSingleByAction_WithIncompleteSingletonRegistration_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            // Samurai is dependant on IWeapon.
            container.RegisterSingle <Warrior>(() => container.GetInstance <Samurai>());

            // Act
            // Kingdom is dependant on Warrior. Registration should succeed even though IWeapon is not
            // registered yet.
            container.RegisterSingle <Kingdom>(k =>
            {
                k.Karma = 5;
            });
        }
        public void Constructor_ShouldCreateATextboxForEachField()
        {
            var ServiceLocatorMock = new Mock <ISimpleServiceLocator>();

            SimpleServiceLocator.SetServiceLocatorProvider(ServiceLocatorMock.Object);

            var headerTextBoxMock = new Mock <ITableHeaderTextBox>();

            headerTextBoxMock.Setup(x => x.TextboxStyle.TextAlign).Returns("Right");

            var headerTextBoxMockLeft = new Mock <ITableHeaderTextBox>();

            headerTextBoxMockLeft.Setup(x => x.TextboxStyle.TextAlign).Returns("");

            ServiceLocatorMock.Setup(x => x.Get <ITableHeaderTextBox>
                                         ("TableHeaderTextBoxRight", It.IsAny <Dictionary <string, object> >())).Returns(headerTextBoxMock.Object);
            ServiceLocatorMock.Setup(x => x.Get <ITableHeaderTextBox>
                                         ("TableHeaderTextBox", It.IsAny <Dictionary <string, object> >())).Returns(headerTextBoxMockLeft.Object);


            List <DataItem> fieldList = new List <DataItem>
            {
                new DataItem {
                    Name = "Item1", Caption = "Cap1", DataType = "char"
                },
                new DataItem {
                    Name = "Item2", Caption = "Cap2", DataType = "int"
                }
            };

            var mockRepository = new Moq.Mock <IDataTableRepository>();

            mockRepository.Setup(x => x.GetByCode(It.IsAny <Guid>())).Returns(new DataTable {
                Name = "TestTable"
            });

            //method under test
            TableHeader target = new TableHeader(fieldList, mockRepository.Object, new DataModel());

            ServiceLocatorMock.Verify(x => x.Get <ITableHeaderTextBox>
                                          ("TableHeaderTextBox", It.IsAny <Dictionary <string, object> >()), Times.Once());
            ServiceLocatorMock.Verify(x => x.Get <ITableHeaderTextBox>
                                          ("TableHeaderTextBoxRight", It.IsAny <Dictionary <string, object> >()), Times.Once());

            Assert.IsTrue(target.TableHeaderTextBoxList.Count == 2);
        }
示例#30
0
        public static void InitializeIoc()
        {
            SimpleServiceLocator.SetServiceLocatorProvider(new UnityServiceLocator());
            SimpleServiceLocator.Instance.Register <IModalDialogService, ModalDialogService>();
            SimpleServiceLocator.Instance.Register <IMessageBoxService, MessageBoxService>();
            SimpleServiceLocator.Instance.Register <IMainViewModel, MainViewModel>();
            SimpleServiceLocator.Instance.Register <IProfileEditorViewModel, ProfileEditorViewModel>();

            SimpleServiceLocator.Instance.Register <IModalWindow, EditWorkView>(Constants.EditUserModalDialog);
            SimpleServiceLocator.Instance.Register <IModalWindow, ArticleDetailView>(Constants.ArticleDetailDialog);
            SimpleServiceLocator.Instance.Register <IModalWindow, ThreadTableView>(Constants.TabellaFilettaturaModalDialog);
            SimpleServiceLocator.Instance.Register <IModalWindow, MachinesDialogView>(Constants.MacchineModalDialog);
            //SimpleServiceLocator.Instance.Register<IModalWindow, MaterialsDialogView>(Constants.MaterialiModalDialog);
            SimpleServiceLocator.Instance.Register <IModalWindow, ToolsDialogView>(Constants.UtensiliModalDialog);
            SimpleServiceLocator.Instance.Register <IModalWindow, EditPhaseDetailView>(Constants.PhaseDetailEditModalDialog);
            SimpleServiceLocator.Instance.Register <IModalWindow, SelectionUnitView>(Constants.UnitSelectionDialog);
            SimpleServiceLocator.Instance.Register <IModalWindow, ProgramPreferenceView>(Constants.PreferenceModalDialog);
        }
        public void GetInstance_ForTypeDependingOnTransientType_ContainerWillRunInitializerOnType()
        {
            // Arrange
            int expectedValue = 10;

            var container = new SimpleServiceLocator();

            container.Register <Service>(createdService =>
            {
                createdService.Value = expectedValue;
            });

            // Act
            var consumer = container.GetInstance <Consumer>();

            // Assert
            Assert.AreEqual(expectedValue, consumer.Service.Value, "The Service initializer was not called.");
        }
示例#32
0
        public void TestAccessingNullTokenResource()
        {
            ResourceContext context = new ResourceContext();
            context.Headers = new NameValueCollection();
            context.Headers["Authorization"] = "bearer my-token";

            Mock<ContextProcessor<IResourceContext>> mckProvider = new Mock<ContextProcessor<IResourceContext>>(new Mock<IServiceFactory>().Object);
            mckProvider.Setup(x => x.IsSatisfiedBy(context)).Returns(true);
            mckProvider.Setup(x => x.Process(context));

            SimpleServiceLocator container = new SimpleServiceLocator();
            container.RegisterAll<ContextProcessor<IResourceContext>>(mckProvider.Object);

            ServiceLocator.SetLocatorProvider(() => container);

            ResourceProvider provider = new ResourceProvider();

            CommonErrorAssert(context, provider, Parameters.ErrorParameters.ErrorValues.InvalidToken);

            mckProvider.Verify();
        }
示例#33
0
        public void TestAccessingResourceUnhandledByProcessor()
        {
            ResourceContext context = new ResourceContext();
            context.Headers = new NameValueCollection();
            context.Headers["Authorization"] = "bearer my-token";

            Mock<ContextProcessor<IResourceContext>> mckProvider = new Mock<ContextProcessor<IResourceContext>>(new Mock<IServiceFactory>().Object);
            mckProvider.Setup(x => x.IsSatisfiedBy(context)).Returns(false);

            SimpleServiceLocator container = new SimpleServiceLocator();
            container.RegisterAll<ContextProcessor<IResourceContext>>(mckProvider.Object);

            ServiceLocator.SetLocatorProvider(() => container);

            ResourceProvider provider = new ResourceProvider();

            provider.AccessProtectedResource(context);


            mckProvider.Verify();

        }
        public void TableHeaderTextBoxConstructor_ShouldSetTheAlignmentToRightIfPassed()
        {
            var ServiceLocatorMock = new Mock <ISimpleServiceLocator>();

            SimpleServiceLocator.SetServiceLocatorProvider(ServiceLocatorMock.Object);

            var reportingStyleMock = new Mock <IReportingServicesStyle>();

            reportingStyleMock.Setup(x => x.TextAlign).Returns("Right");

            ServiceLocatorMock.Setup(x => x.Get <IReportingServicesStyle>
                                         ("ReportingServicesStyleRight", It.IsAny <Dictionary <string, object> >())).Returns(reportingStyleMock.Object);

            string name           = "Table1";
            string caption        = "Caption1";
            bool   isRightAligned = true;

            TableHeaderTextBox target = new TableHeaderTextBox(name, caption, isRightAligned);

            ServiceLocatorMock.Verify(x => x.Get <IReportingServicesStyle>("ReportingServicesStyleRight", It.IsAny <Dictionary <string, object> >()), Times.Once());
            ServiceLocatorMock.Verify(x => x.Get <IReportingServicesStyle>("ReportingServicesStyle", It.IsAny <Dictionary <string, object> >()), Times.Never());
            Assert.AreEqual(target.TextboxStyle.TextAlign, "Right");
        }
示例#35
0
        public void TestAccessingNullTokenResource()
        {
            ResourceContext context = new ResourceContext();

            context.Headers = new NameValueCollection();
            context.Headers["Authorization"] = "bearer my-token";

            Mock <ContextProcessor <IResourceContext> > mckProvider = new Mock <ContextProcessor <IResourceContext> >(new Mock <IServiceFactory>().Object);

            mckProvider.Setup(x => x.IsSatisfiedBy(context)).Returns(true);
            mckProvider.Setup(x => x.Process(context));

            SimpleServiceLocator container = new SimpleServiceLocator();

            container.RegisterAll <ContextProcessor <IResourceContext> >(mckProvider.Object);

            ServiceLocator.SetLocatorProvider(() => container);

            ResourceProvider provider = new ResourceProvider();

            CommonErrorAssert(context, provider, Parameters.ErrorParameters.ErrorValues.InvalidToken);

            mckProvider.Verify();
        }
        public void GetInstance_RegisterSingleByAction_CallsActionOnce()
        {
            // Arrange
            const int ExpectedNumberOfCalls = 1;
            int actualNumberOfCalls = 0;

            var container = new SimpleServiceLocator();

            // Samurai takes an IWeapon as a constructor argument.
            container.RegisterSingle<IWeapon>(new Katana());

            Action<Samurai> instanceInitializer = _ => { actualNumberOfCalls++; };

            container.RegisterSingle<Samurai>(instanceInitializer);

            // Act
            container.GetInstance<Samurai>();
            container.GetInstance<Samurai>();
            container.GetInstance<Samurai>();

            // Assert
            Assert.AreEqual(ExpectedNumberOfCalls, actualNumberOfCalls,
                "The Action<T> was expected to be called once.");
        }
示例#37
0
        public void GetInstance_RegisterSingleByAction_CallsActionOnce()
        {
            // Arrange
            const int ExpectedNumberOfCalls = 1;
            int       actualNumberOfCalls   = 0;

            var container = new SimpleServiceLocator();

            // Samurai takes an IWeapon as a constructor argument.
            container.RegisterSingle <IWeapon>(new Katana());

            Action <Samurai> instanceInitializer = _ => { actualNumberOfCalls++; };

            container.RegisterSingle <Samurai>(instanceInitializer);

            // Act
            container.GetInstance <Samurai>();
            container.GetInstance <Samurai>();
            container.GetInstance <Samurai>();

            // Assert
            Assert.AreEqual(ExpectedNumberOfCalls, actualNumberOfCalls,
                            "The Action<T> was expected to be called once.");
        }
        public void RegisterSingleByAction_WithIncompleteSingletonRegistration_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            // Samurai is dependant on IWeapon.
            container.RegisterSingle<Warrior>(() => container.GetInstance<Samurai>());

            // Act
            // Kingdom is dependant on Warrior. Registration should succeed even though IWeapon is not 
            // registered yet.
            container.RegisterSingle<Kingdom>(k =>
            {
                k.Karma = 5;
            });
        }
        public void RegisterSingleByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterAll_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterAll<Samurai>(new[] { new Samurai(null) });

            // Act
            container.RegisterSingle<Samurai>(_ => { });
        }
        public void RegisterSingleByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterSingleFuncByKey_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterSingleByKey<Samurai>("Sammy the Samurai", () => new Samurai(null));

            // Act
            container.RegisterSingle<Samurai>(_ => { });
        }
        public void RegisterByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterByKeyedFunc_Succeeds()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterByKey<Samurai>(key => new Samurai(null));

            // Act
            container.Register<Samurai>(_ => { });
        }
        public void RegisterSingleByAction_CalledAfterTypeAlreadyRegisteredUsingRegisterSingleByAction_ThrowsException()
        {
            // Arrange
            var container = new SimpleServiceLocator();

            container.RegisterSingle<Samurai>(_ => { });

            // Act
            container.RegisterSingle<Samurai>(_ => { });
        }
 internal TransientInitializerInstanceProducer(SimpleServiceLocator container,
                                               Action <TConcrete> instanceInitializer) : base(container)
 {
     this.instanceInitializer = instanceInitializer;
 }
        public void RegisterSingleByAction_CalledAfterCallToGetInstance_ThrowsException()
        {
            // Arrange
            var container = new SimpleServiceLocator();
            container.Register<IWeapon>(() => new Katana());
            container.GetInstance<IWeapon>();

            Action<Samurai> validInstanceInitializer = _ => { };

            // Act
            container.RegisterSingle<Samurai>(validInstanceInitializer);
        }
示例#45
0
        public void TestAccessingExpiredTokenResource()
        {
            ResourceContext context = new ResourceContext();
            context.Headers = new NameValueCollection();
            context.Headers["Authorization"] = "bearer my-token";

			IAccessToken expiredToken = new AccessTokenBase
            {
                Token = "my-token",
                ExpiresIn = 2,
                IssuedOn = DateTime.Now.AddMinutes(-1).ToEpoch()
            };
            Mock<ContextProcessor<IResourceContext>> mckProvider = new Mock<ContextProcessor<IResourceContext>>(new Mock<IServiceFactory>().Object);
            mckProvider.Setup(x => x.IsSatisfiedBy(context)).Returns(true);
            mckProvider.Setup(x => x.Process(context)).Callback(() => context.Token = expiredToken);

            SimpleServiceLocator container = new SimpleServiceLocator();
            container.RegisterAll<ContextProcessor<IResourceContext>>(mckProvider.Object);

            ServiceLocator.SetLocatorProvider(() => container);

            ResourceProvider provider = new ResourceProvider();

            CommonErrorAssert(context, provider, Parameters.ErrorParameters.ErrorValues.InvalidToken);

            mckProvider.Verify();
        }
        public void GetInstance_ForTypeDependingOnTransientType_ContainerWillRunInitializerOnType()
        {
            // Arrange
            int expectedValue = 10;

            var container = new SimpleServiceLocator();

            container.Register<Service>(createdService =>
            {
                createdService.Value = expectedValue;
            });

            // Act
            var consumer = container.GetInstance<Consumer>();

            // Assert
            Assert.AreEqual(expectedValue, consumer.Service.Value, "The Service initializer was not called.");
        }