Пример #1
0
        public static IDictionaryPhraseRepository GetCurrentFromCacheOrCreate()
        {
            if (HttpContext.Current != null)
            {
                var repository = HttpContext.Current.Items["DictionaryPhraseRepository.Current"] as IDictionaryPhraseRepository;
                if (repository != null)
                {
                    return(repository);
                }
            }
            IDictionaryPhraseRepository dictionaryPhraseRepository = ServiceLocator.ServiceProvider.GetService <IDictionaryPhraseRepository>();

            if (HttpContext.Current != null)
            {
                HttpContext.Current.Items.Add("DictionaryPhraseRepository.Current", dictionaryPhraseRepository);
            }
            return(dictionaryPhraseRepository);
        }
    public void Current_HttpContextHasDictionaryItem_TakeReposiotryFromCache([Content]DbItem item, HttpContext context, IDictionaryPhraseRepository dictionaryPhraseRepository)
    {
      //Arrange
      var siteContext = new FakeSiteContext(new StringDictionary()
      {
        ["dictionaryPath"] = item.FullPath,
        ["database"] = "master"
      });

      HttpContext.Current = context;
      HttpContext.Current.Items["DictionaryPhraseRepository.Current"] = dictionaryPhraseRepository;

      using (new SiteContextSwitcher(siteContext))
      {
        //Act
        var result = DictionaryPhraseRepository.Current;
        //Assert
        result.Should().Be(dictionaryPhraseRepository);
      }
    }
 public CommentController(IRenderingRepository renderingRepository, ICommentService commentService, IDictionaryPhraseRepository dictionaryPhraseRepository)
 {
     _renderingRepository        = renderingRepository;
     _commentService             = commentService;
     _dictionaryPhraseRepository = dictionaryPhraseRepository;
 }
        public void Current_HttpContextHasDictionaryItem_TakeReposiotryFromCache([Content] DbItem item, HttpContext context, IDictionaryPhraseRepository dictionaryPhraseRepository)
        {
            //Arrange
            var siteContext = new FakeSiteContext(new StringDictionary()
            {
                ["dictionaryPath"] = item.FullPath,
                ["database"]       = "master"
            });

            HttpContext.Current = context;
            HttpContext.Current.Items["DictionaryPhraseRepository.Current"] = dictionaryPhraseRepository;

            using (new SiteContextSwitcher(siteContext))
            {
                //Act
                var result = DictionaryPhraseRepository.Current;
                //Assert
                result.Should().Be(dictionaryPhraseRepository);
            }
        }
 public SitecoreExtensionsTests()
 {
     this.dictionaryPhraseRepository = Substitute.For <IDictionaryPhraseRepository>();
     HttpContext.Current             = HttpContextMockFactory.Create();
     HttpContext.Current.Items["DictionaryPhraseRepository.Current"] = this.dictionaryPhraseRepository;
 }
 public DictionaryPhraseRepositoryTestHarness()
 {
     _fixture = new Fixture();
     DictionaryPhraseRepository = new DictionaryPhraseRepository(SitecoreService);
 }
    public void EditProfileShouldReturnInfoMessageIfProfileDoesntMatch(string siteProfileId, string profileItemId, IUserProfileService userProfileService, HttpContext context, IDictionaryPhraseRepository phraseRepository)
    {
      var user = Substitute.For<User>("extranet/John", true);
      user.Profile.Returns(Substitute.For<UserProfile>());
      user.Profile.ProfileItemId = profileItemId;
      userProfileService.GetUserDefaultProfileId().Returns(siteProfileId);

      var fakeSite = new FakeSiteContext(new StringDictionary
      {
        {"displayMode", "normal"}
      }) as SiteContext;

      using (new SiteContextSwitcher(fakeSite))
      using (new UserSwitcher(user))
      {
        var accounController = new AccountsController(null, null, null, userProfileService, null);
        var result = accounController.EditProfile();
        result.Should().BeOfType<ViewResult>().Which.Model.Should().BeOfType<InfoMessage>().Which.Type.Should().Be(InfoMessage.MessageType.Error);
      }
    }
Пример #8
0
        public void EditProfileShouldReturnInfoMessageIfProfileDoesntMatch(string siteProfileId, string profileItemId, IUserProfileService userProfileService, HttpContext context, IDictionaryPhraseRepository phraseRepository)
        {
            var user = Substitute.For <User>("extranet/John", true);

            user.Profile.Returns(Substitute.For <UserProfile>());
            user.Profile.ProfileItemId = profileItemId;
            userProfileService.GetUserDefaultProfileId().Returns(siteProfileId);

            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "displayMode", "normal" }
            }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
                using (new UserSwitcher(user))
                {
                    var accounController = new AccountsController(null, null, null, userProfileService, null);
                    var result           = accounController.EditProfile();
                    result.Should().BeOfType <ViewResult>().Which.Model.Should().BeOfType <InfoMessage>().Which.Type.Should().Be(InfoMessage.MessageType.Error);
                }
        }
 public SitecoreExtensionsTests()
 {
   this.dictionaryPhraseRepository = Substitute.For<IDictionaryPhraseRepository>();
   HttpContext.Current = HttpContextMockFactory.Create();
   HttpContext.Current.Items["DictionaryPhraseRepository.Current"] = this.dictionaryPhraseRepository;
 }