public BackendLoginControllerTests()
        {
            _cultureInfo = CultureInfo.CurrentUICulture;
            var english = CultureInfo.CreateSpecificCulture("en");

            Thread.CurrentThread.CurrentUICulture = english;
            var localizationService = new MemoryLocalizationService
            {
                FallbackBehavior = FallbackBehaviors.MissingMessage
            };

            localizationService.AddString(english, "/Login/BackendLogin/Heading", "Heading");
            localizationService.AddString(english, "/Login/BackendLogin/LoginMessage", "LoginMessage");
            localizationService.AddString(english, "/Login/Form/Error/WrongPasswordOrEmail", "WrongPasswordOrEmail");

            var authenticationManager = new Mock <IAuthenticationManager>();
            var userStore             = new Mock <IUserStore <ApplicationUser> >();
            var userManager           = new Mock <ApplicationUserManager>(userStore.Object);
            var signInManager         = new Mock <ApplicationSignInManager>(userManager.Object, authenticationManager.Object);

            _subject = new BackendLoginController(localizationService, signInManager.Object, new FakeUrlAuthorization());

            var request = new Mock <HttpRequestBase>();

            request.Setup(x => x.Url).Returns(new Uri("http://test.com"));
            var httpContext = new Mock <HttpContextBase>();

            httpContext.SetupGet(x => x.Request).Returns(request.Object);
            _subject.ControllerContext = new ControllerContext(httpContext.Object, new RouteData(), _subject);
        }
Exemple #2
0
        public LoginControllerTests()
        {
            _cultureInfo = CultureInfo.CurrentUICulture;
            var english = CultureInfo.CreateSpecificCulture("en");

            Thread.CurrentThread.CurrentUICulture = english;
            var localizationService = new MemoryLocalizationService
            {
                FallbackBehavior = FallbackBehaviors.MissingMessage
            };

            localizationService.AddString(english, "/Login/Form/Error/WrongPasswordOrEmail", "WrongPasswordOrEmail");
            localizationService.AddString(english, "/Shared/Address/DefaultAddressName", "Default address");

            var startPageMock         = new Mock <StartPage>();
            var userStore             = new Mock <IUserStore <SiteUser> >();
            var authenticationManager = new Mock <IAuthenticationManager>();

            _orderGroupFactoryMock = new Mock <IOrderGroupFactory>();

            var customercontextFacadeMock = new Mock <CustomerContextFacade>();
            var countryManagerFacadeMock  = new Mock <CountryManagerFacade>();

            countryManagerFacadeMock.Setup(x => x.GetCountries()).Returns(() => new CountryDto());
            var addressBookService = new AddressBookService(customercontextFacadeMock.Object, countryManagerFacadeMock.Object, _orderGroupFactoryMock.Object);
            var request            = new Mock <HttpRequestBase>();

            _httpContextMock            = new Mock <HttpContextBase>();
            _requestContext             = new Mock <RequestContext>();
            _controllerExceptionHandler = new Mock <ControllerExceptionHandler>();

            _contentLoaderMock = new Mock <IContentLoader>();
            _userManagerMock   = new Mock <ApplicationUserManager <SiteUser> >(userStore.Object);
            _signinManagerMock = new Mock <ApplicationSignInManager <SiteUser> >(_userManagerMock.Object, authenticationManager.Object, new ApplicationOptions());
            _userServiceMock   = new Mock <UserService>(_userManagerMock.Object, _signinManagerMock.Object, authenticationManager.Object, localizationService, customercontextFacadeMock.Object);

            request.Setup(
                x => x.Url)
            .Returns(new Uri(_testUrl));

            request.SetupGet(
                x => x.UrlReferrer)
            .Returns(new Uri(_testUrl));

            _httpContextMock.SetupGet(
                x => x.Request)
            .Returns(request.Object);

            _contentLoaderMock.Setup(x => x.Get <StartPage>(It.IsAny <ContentReference>())).Returns(startPageMock.Object);

            _subject = new LoginControllerForTest(_signinManagerMock.Object, _userManagerMock.Object, _userServiceMock.Object, localizationService, _contentLoaderMock.Object, addressBookService, _controllerExceptionHandler.Object);
            _subject.ControllerContext = new ControllerContext(_httpContextMock.Object, new RouteData(), _subject);

            _exceptionContext = new ExceptionContext
            {
                HttpContext    = _httpContextMock.Object,
                RequestContext = _requestContext.Object
            };
        }
Exemple #3
0
        public AddressBookControllerTests()
        {
            _controllerExceptionHandlerMock = new Mock <ControllerExceptionHandler>();
            _requestContextMock             = new Mock <RequestContext>();
            _httpRequestBaseMock            = new Mock <HttpRequestBase>();


            _httpContextBaseMock = new Mock <HttpContextBase>();
            _httpContextBaseMock.SetupGet(x => x.Request).Returns(_httpRequestBaseMock.Object);

            _exceptionContext = new ExceptionContext
            {
                HttpContext    = _httpContextBaseMock.Object,
                RequestContext = _requestContextMock.Object
            };

            _contentLoaderMock      = new Mock <IContentLoader>();
            _addressBookServiceMock = new Mock <IAddressBookService>();
            _addressBookServiceMock.Setup(x => x.CanSave(It.IsAny <AddressModel>())).Returns(true);

            _contentLoaderMock.Setup(c => c.Get <StartPage>(ContentReference.StartPage)).Returns(new StartPage());

            _localizationService = new MemoryLocalizationService();
            _localizationService.AddString(CultureInfo.CreateSpecificCulture("en"), "/AddressBook/Form/Error/ExistingAddress", "error");

            _subject = new AddressBookController(_contentLoaderMock.Object, _addressBookServiceMock.Object, _localizationService, _controllerExceptionHandlerMock.Object);
            _subject.ControllerContext = new ControllerContext(_httpContextBaseMock.Object, new RouteData(), _subject);
        }
Exemple #4
0
        public SearchServiceTests()
        {
            SetupSearchResultMock();

            var marketMock = new Mock <IMarket>();

            marketMock.Setup(x => x.MarketId).Returns(new MarketId("Market"));
            _currentMarketMock = new Mock <ICurrentMarket>();
            _currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(marketMock.Object);

            _currentCurrency     = new Currency("USD");
            _currencyServiceMock = new Mock <ICurrencyService>();
            _currencyServiceMock.Setup(x => x.GetCurrentCurrency()).Returns(_currentCurrency);

            var urlResolverMock = new Mock <UrlResolver>();

            urlResolverMock.Setup(x => x.GetUrl(It.IsAny <ContentReference>())).Returns("http://domain.com");

            _searchFacadeMock = new Mock <SearchFacade>();
            _searchFacadeMock.Setup(x => x.Search(It.IsAny <CatalogEntrySearchCriteria>())).Returns(_searchResultsMock.Object);
            _searchFacadeMock.Setup(x => x.SearchFilters).Returns(new[] { new SearchFilter() });
            _searchFacadeMock.Setup(x => x.GetOutlinesForNode(It.IsAny <string>())).Returns(new StringCollection());
            _searchFacadeMock.Setup(x => x.GetSearchProvider()).Returns(SearchFacade.SearchProviderType.Lucene);

            _languageResolverMock = new Mock <LanguageResolver>();
            _languageResolverMock.Setup(x => x.GetPreferredCulture()).Returns(CultureInfo.GetCultureInfo("en"));

            _localizationService = new MemoryLocalizationService();
            _localizationService.AddString(CultureInfo.GetCultureInfo("en"), "/Facet/Category", "Category");

            _contentLoaderMock = new Mock <IContentLoader>();
            _contentLoaderMock.Setup(x => x.GetChildren <NodeContent>(It.IsAny <ContentReference>())).Returns(new[] { new NodeContent()
                                                                                                                      {
                                                                                                                          DisplayName = "Node",
                                                                                                                          Code        = "Node"
                                                                                                                      } });

            _subject = new SearchService(
                _currentMarketMock.Object,
                _currencyServiceMock.Object,
                urlResolverMock.Object,
                _searchFacadeMock.Object,
                _languageResolverMock.Object,
                _contentLoaderMock.Object,
                _localizationService,
                null,
                null);
        }
        public void Setup()
        {
            _cultureInfo = CultureInfo.CurrentUICulture;
            var english = CultureInfo.CreateSpecificCulture("en");
            Thread.CurrentThread.CurrentUICulture = english;
            var localizationService = new MemoryLocalizationService
            {
                FallbackBehavior = FallbackBehaviors.MissingMessage
            };
            localizationService.AddString(english, "/Login/BackendLogin/Heading", "Heading");
            localizationService.AddString(english, "/Login/BackendLogin/LoginMessage", "LoginMessage");
            localizationService.AddString(english, "/Login/Form/Error/WrongPasswordOrEmail", "WrongPasswordOrEmail");

            var authenticationManager = new Mock<IAuthenticationManager>();
            var userStore = new Mock<IUserStore<ApplicationUser>>();
            var userManager = new Mock<ApplicationUserManager>(userStore.Object);
            var signInManager = new Mock<ApplicationSignInManager>(userManager.Object, authenticationManager.Object);
            _subject = new BackendLoginController(localizationService, signInManager.Object, new FakeUrlAuthorization());

            var request = new Mock<HttpRequestBase>();
            request.Setup(x => x.Url).Returns(new Uri("http://test.com"));
            var httpContext = new Mock<HttpContextBase>();
            httpContext.SetupGet(x => x.Request).Returns(request.Object);
            _subject.ControllerContext = new ControllerContext(httpContext.Object, new RouteData(), _subject);
        }
        public SearchServiceTests()
        {
            SetupSearchResultMock();

            var marketMock = new Mock<IMarket>();
            marketMock.Setup(x => x.MarketId).Returns(new MarketId("Market"));
            _currentMarketMock = new Mock<ICurrentMarket>();
            _currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(marketMock.Object);

            _currentCurrency = new Currency("USD");
            _currencyServiceMock = new Mock<ICurrencyService>();
            _currencyServiceMock.Setup(x => x.GetCurrentCurrency()).Returns(_currentCurrency);

            var urlResolverMock = new Mock<UrlResolver>();
            urlResolverMock.Setup(x => x.GetUrl(It.IsAny<ContentReference>())).Returns("http://domain.com");

            _searchFacadeMock = new Mock<SearchFacade>();
            _searchFacadeMock.Setup(x => x.Search(It.IsAny<CatalogEntrySearchCriteria>())).Returns(_searchResultsMock.Object);
            _searchFacadeMock.Setup(x => x.SearchFilters).Returns(new[] { new SearchFilter() });
            _searchFacadeMock.Setup(x => x.GetOutlinesForNode(It.IsAny<string>())).Returns(new StringCollection());
            _searchFacadeMock.Setup(x => x.GetSearchProvider()).Returns(SearchFacade.SearchProviderType.Lucene);

            _localizationService = new MemoryLocalizationService();
            _localizationService.AddString(CultureInfo.GetCultureInfo("en"), "/Facet/Category", "Category");

            _contentLoaderMock = new Mock<IContentLoader>();
            _contentLoaderMock.Setup(x => x.GetChildren<NodeContent>(It.IsAny<ContentReference>())).Returns(new[] { new NodeContent()
            {
                DisplayName = "Node",
                Code = "Node"
            }});

            _subject = new SearchService(
                _currentMarketMock.Object,
                _currencyServiceMock.Object,
                urlResolverMock.Object,
                _searchFacadeMock.Object,
                () => CultureInfo.GetCultureInfo("en"),
                _contentLoaderMock.Object,
                _localizationService);
        }
        public void Setup()
        {
            _controllerExceptionHandler = new Mock<ControllerExceptionHandler>();
            _requestContext = new Mock<RequestContext>();
            _httpRequestBase = new Mock<HttpRequestBase>();

            _httpContextBase = new Mock<HttpContextBase>();
            _httpContextBase.Setup(x => x.Request).Returns(_httpRequestBase.Object);

            _exceptionContext = new ExceptionContext
            {
                HttpContext = _httpContextBase.Object,
                RequestContext = _requestContext.Object
            };

            _contentLoaderMock = new Mock<IContentLoader>();
            _addressBookServiceMock = new Mock<IAddressBookService>();
            _addressBookServiceMock.Setup(x => x.CanSave(It.IsAny<Address>())).Returns(true);

            _contentLoaderMock.Setup(c => c.Get<StartPage>(ContentReference.StartPage)).Returns(new StartPage());

            _localizationService = new MemoryLocalizationService();
            _localizationService.AddString(CultureInfo.CreateSpecificCulture("en"), "/AddressBook/Form/Error/ExistingAddress", "error");

            _subject = new AddressBookController(_contentLoaderMock.Object, _addressBookServiceMock.Object, _localizationService, _controllerExceptionHandler.Object);
        }
        public void TestInitialize()
        {
            // IContentEvents
            _contentEventsMock = new Mock<IContentEvents>();

            // IContentTypeRepository
            var contentTypeRepositoryMock = new Mock<IContentTypeRepository>();

            contentTypeRepositoryMock.Setup(x => x.Load(1)).Returns(new ContentType());

            // IContentModelUsage
            var contentModelUsageMock = new Mock<IContentModelUsage>();

            var usages = new List<ContentUsage>();
            var contentUsage = new ContentUsage();
            var contentReference = new ContentReference();
            contentReference.ID = 1;
            contentUsage.ContentLink = contentReference;
            contentModelUsageMock.Setup(x => x.ListContentOfContentType(It.IsAny<ContentType>())).Returns(new List<ContentUsage>() { contentUsage });

            // IContentRepository
            var contentRepositoryMock = new Mock<IContentRepository>();

            contentRepositoryMock.Setup(x => x.GetItems(It.IsAny<IEnumerable<ContentReference>>(), LanguageSelector.MasterLanguage())).Returns(new List<IContent>());

            // LocalizationService
            var localizationService = new MemoryLocalizationService();
            localizationService.AddString(new CultureInfo("en"), "/RestrictMultiple/max", " Max Error");
            localizationService.AddString(new CultureInfo("en"), "/RestrictMultiple/culturemax", "CultureMax Error");

            // IServiceLocator
            var serviceLocatorMock = new Mock<IServiceLocator>();

            serviceLocatorMock.Setup(x => x.GetInstance<IContentEvents>()).Returns(_contentEventsMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IContentTypeRepository>()).Returns(contentTypeRepositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IContentRepository>()).Returns(contentRepositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IContentModelUsage>()).Returns(contentModelUsageMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<LocalizationService>()).Returns(localizationService);

            ServiceLocator.SetLocator(serviceLocatorMock.Object);
        }
        public void Setup()
        {
            _cultureInfo = CultureInfo.CurrentUICulture;
            var english = CultureInfo.CreateSpecificCulture("en");
            Thread.CurrentThread.CurrentUICulture = english;
            var localizationService = new MemoryLocalizationService
            {
                FallbackBehavior = FallbackBehaviors.MissingMessage
            };
            localizationService.AddString(english, "/Login/Form/Error/WrongPasswordOrEmail", "WrongPasswordOrEmail");
            localizationService.AddString(english, "/Shared/Address/DefaultAddressName", "Default address");

            var startPageMock = new Mock<StartPage>();
            var userStore = new Mock<IUserStore<ApplicationUser>>();
            var authenticationManager = new Mock<IAuthenticationManager>();

            var customercontextFacadeMock = new Mock<CustomerContextFacade>();
            var countryManagerFacadeMock = new Mock<CountryManagerFacade>();
            countryManagerFacadeMock.Setup(x => x.GetCountries()).Returns(() => new CountryDto());
            var addressBookService = new AddressBookService(customercontextFacadeMock.Object, countryManagerFacadeMock.Object);
            var request = new Mock<HttpRequestBase>();
            _httpContextMock = new Mock<HttpContextBase>();
            _requestContext = new Mock<RequestContext>();
            _controllerExceptionHandler = new Mock<ControllerExceptionHandler>();

            _contentLoaderMock = new Mock<IContentLoader>();
            _userManagerMock = new Mock<ApplicationUserManager>(userStore.Object);
            _signinManagerMock = new Mock<ApplicationSignInManager>(_userManagerMock.Object, authenticationManager.Object);
            _userServiceMock = new Mock<UserService>(_userManagerMock.Object, _signinManagerMock.Object, authenticationManager.Object, localizationService, customercontextFacadeMock.Object);

            request.Setup(
                x => x.Url)
                .Returns(new Uri(_testUrl));

            request.SetupGet(
                x => x.UrlReferrer)
                .Returns(new Uri(_testUrl));

            _httpContextMock.SetupGet(
                x => x.Request)
                .Returns(request.Object);

            _contentLoaderMock.Setup(x => x.Get<StartPage>(It.IsAny<ContentReference>())).Returns(startPageMock.Object);

            _subject = new LoginControllerForTest(_signinManagerMock.Object, _userManagerMock.Object, _userServiceMock.Object, localizationService, _contentLoaderMock.Object, addressBookService, _controllerExceptionHandler.Object);
            _subject.ControllerContext = new ControllerContext(_httpContextMock.Object, new RouteData(), _subject);

            _exceptionContext = new ExceptionContext
            {
                HttpContext = _httpContextMock.Object,
                RequestContext = _requestContext.Object
            };
        }