Inheritance: IDictionaryPhraseRepository
コード例 #1
0
    public void Get_AutocreateIsFalseEntryDoesntExists_ReturnDefaultValue(Db db,[Content]Item rootItem, string relativePath, string defaultValue)
    {
      //Arrange
      var repository = new DictionaryPhraseRepository(new Dictionary() {Root = rootItem, AutoCreate = false});

      //Act
      var result = repository.Get(relativePath, defaultValue);

      //Assert
      result.Should().Be(defaultValue);
    }
コード例 #2
0
    public void GetItem_AutocreateIsFalseEntryDoesntExists_ReturnNull(Db db, [Content]Item rootItem, string relativePath, string defaultValue)
    {
      //Arrange
      var repository = new DictionaryPhraseRepository(new Dictionary() { Root = rootItem, AutoCreate = false, Site = new FakeSiteContext("test")});

      //Act
      var result = repository.GetItem(relativePath, defaultValue);

      //Assert
      result.Should().BeNull();
    }
コード例 #3
0
    public void Get_DatabaseIsNull_ReturnDefaultValue(string relativePath, string defaultValue)
    {
      //Arrange
      Context.Database = null;
      var repository = new DictionaryPhraseRepository(new Dictionary());

      //Act
      var result = repository.Get(relativePath, defaultValue);

      //Assert
      result.Should().Be(defaultValue);
    }
コード例 #4
0
    public void Get_AutocreateIsTrueEntryDoesntExists_ShouldCreateItem(Db db, [Content]CreateDictionaryEntryServiceTests.DictionaryEntryTemplate entryTemplate, [Content]Item rootItem, IEnumerable<string> pathParts, string defaultValue)
    {
      //Arrange
      var relativePath = string.Join("/", pathParts.Select(ItemUtil.ProposeValidItemName));
      var repository = new DictionaryPhraseRepository(new Dictionary() { Root = rootItem, AutoCreate = true });

      //Act
      var result = repository.Get(relativePath, defaultValue);

      //Assert
      result.Should().Be(defaultValue);
      rootItem.Axes.GetItem(relativePath).Should().NotBeNull();
    }
コード例 #5
0
        private static IDictionaryPhraseRepository GetCurrentFromCacheOrCreate()
        {
            if (HttpContext.Current != null)
            {
                var repository = HttpContext.Current.Items["DictionaryPhraseRepository.Current"] as IDictionaryPhraseRepository;
                if (repository != null)
                {
                    return(repository);
                }
            }
            var returnValue = new DictionaryPhraseRepository(DictionaryRepository.Current);

            if (HttpContext.Current != null)
            {
                HttpContext.Current.Items.Add("DictionaryPhraseRepository.Current", returnValue);
            }
            return(returnValue);
        }
コード例 #6
0
    private static IDictionaryPhraseRepository GetCurrentFromCacheOrCreate()
    {
      if (HttpContext.Current != null)
      {
        var repository = HttpContext.Current.Items["DictionaryPhraseRepository.Current"] as IDictionaryPhraseRepository;
        if (repository != null)
        {
          return repository;
        }
      }
      var returnValue = new DictionaryPhraseRepository(DictionaryRepository.Current);

      if (HttpContext.Current != null)
      {
        HttpContext.Current.Items.Add("DictionaryPhraseRepository.Current", returnValue);
      }
      return returnValue;
    }
コード例 #7
0
 public void GetItem_NullRElativePath_ThrowArgumentNullException(string defaultValue)
 {
   var repository = new DictionaryPhraseRepository(new Dictionary());
   repository.Invoking(x => x.GetItem(null, defaultValue)).ShouldThrow<ArgumentNullException>();
 }
コード例 #8
0
    public void Get_IncorrectRelativePath_ThrowArgumentException(Db db, [Content]Item rootItem, string defaultValue)
    {
      //Arrange
      var relativePath = "/";
      var repository = new DictionaryPhraseRepository(new Dictionary() { Root = rootItem, AutoCreate = true });

      //Assert
      repository.Invoking(x=>x.Get(relativePath, defaultValue)).ShouldThrow<ArgumentException>();
    }
コード例 #9
0
    public void Get_AutocreateIsTrueEntryDoesntExists_ShouldreturnItem(Db db, [Content]CreateDictionaryEntryServiceTests.DictionaryEntryTemplate entryTemplate, [Content]Item rootItem, IEnumerable<string> pathParts, string defaultValue)
    {
      //Arrange
      var relativePath = string.Join("/", pathParts);
      var repository = new DictionaryPhraseRepository(new Dictionary() { Root = rootItem, AutoCreate = true });

      //Act
      var result = repository.GetItem(relativePath, defaultValue);

      //Assert
      result[Templates.DictionaryEntry.Fields.Phrase].Should().Be(defaultValue);
    }