Esempio n. 1
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
            };
        }
        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
            };
        }