public void Items_NotLatestItemVersionExists_ReturnsOnlyLatestItems([Content] DbItem[] contentItems, ISearchIndex index, [Frozen] SearchProvider searchProvider, Switcher<SearchProvider> searchProviderSwitcher, [Content] Item renderingItem, IRenderingPropertiesRepository renderingPropertiesRepository)
    {
      //arrange
      var results = GetResults(contentItems).ToArray();
      results.First().IsLatestVersion = false;
      renderingPropertiesRepository.Get<QueryableDatasourceRenderingSettings>()
        .Returns(new QueryableDatasourceRenderingSettings
        {
          SearchResultsLimit = 10
        });

      InitIndexes(index, searchProvider, results.AsQueryable());
      var renderingModel = new QueryableDatasourceRenderingModel(renderingPropertiesRepository)
      {
        DatasourceString = "notEmpty"
      };

      //act
      var items = renderingModel.Items;

      //assert
      items.Count().Should().Be(contentItems.Length - 1);
      index.CreateSearchContext().ReceivedWithAnyArgs(1);
    }
 public void SutInstantiatesCustomCorePipelineWrapper(
   IRenderingPropertiesRepository renderingRepository,
   ICorePipeline corePipeline)
 {
   var sut = new QueryableDatasourceRenderingModel(renderingRepository, corePipeline);
   sut.CorePipeline.Should().BeSameAs(corePipeline);
 }
    public void Items_EmptyDatasource_ReturnsEmptyCollection(List<DbItem> indexedItems, SearchProvider searchProvider, ISearchIndex index, string indexName, [Content] Item renderingItem)
    {
      //arrange

      InitIndexes(index, searchProvider, new List<SearchResultItem>().AsQueryable());
      var renderingModel = new QueryableDatasourceRenderingModel();

      //act
      var items = renderingModel.Items;

      //assert
      items.Count().Should().Be(0);
      index.CreateSearchContext().DidNotReceiveWithAnyArgs();
    }
 public void SutInstantiatesDefaultCorePipelineWrapper()
 {
   var sut = new QueryableDatasourceRenderingModel();
   sut.CorePipeline.Should().BeOfType<CorePipelineWrapper>();
 }
    public void Items_IndexEmpty_ReturnsEmptyCollection(List<DbItem> indexedItems, ISearchIndex index, string indexName, [Frozen] SearchProvider searchProvider, Switcher<SearchProvider> searchProviderSwitcher, [Content] Item renderingItem, IRenderingPropertiesRepository renderingPropertiesRepository)
    {
      //arrange
      InitIndexes(index, searchProvider, new List<SearchResultItem>().AsQueryable());
      renderingPropertiesRepository.Get<QueryableDatasourceRenderingSettings>()
        .Returns(new QueryableDatasourceRenderingSettings
        {
          SearchResultsLimit = 10
        });

      var renderingModel = new QueryableDatasourceRenderingModel(renderingPropertiesRepository)
      {
        DatasourceString = "notEmpty"
      };

      //act
      var items = renderingModel.Items;

      //assert
      items.Count().Should().Be(0);
      index.CreateSearchContext().ReceivedWithAnyArgs(1);
    }
    public void Items_StandardValuesExists_IgnoresItemsUnderTemplates(Db db, ISearchIndex index,
      [Frozen] SearchProvider searchProvider, Switcher<SearchProvider> searchProviderSwitcher,
      [Content] Item renderingItem, IRenderingPropertiesRepository renderingPropertiesRepository)
    {
      //arrange
      var templateID = ID.NewID;
      db.Add(new DbTemplate("Sample", templateID));
      var stdValues = db.GetItem("/sitecore/templates/Sample").Add(Sitecore.Constants.StandardValuesItemName, new TemplateID(templateID));

      renderingPropertiesRepository.Get<QueryableDatasourceRenderingSettings>()
        .Returns(new QueryableDatasourceRenderingSettings
        {
          SearchResultsLimit = 10
        });

      var results = GetResults(new List<DbItem>
      {
        new DbItem(Sitecore.Constants.StandardValuesItemName, stdValues.ID)
      });

      InitIndexes(index, searchProvider, results);
      var renderingModel = new QueryableDatasourceRenderingModel(renderingPropertiesRepository)
      {
        DatasourceString = "notEmpty"
      };

      //act
      var items = renderingModel.Items.ToArray();


      //assert
      items.Count().Should().Be(0);
    }
    public void Items_IndexHaveNonexistentItems_ReturnsExistentItems([Content] DbItem[] contentItems, DbItem brokenItem,
      List<DbItem> indexedItems, ISearchIndex index, string indexName,
      [Frozen] SearchProvider searchProvider, Switcher<SearchProvider> searchProviderSwitcher,
      [Content] Item renderingItem, IRenderingPropertiesRepository renderingPropertiesRepository)
    {
      //arrange
      indexedItems.AddRange(contentItems);
      indexedItems.Add(brokenItem);
      renderingPropertiesRepository.Get<QueryableDatasourceRenderingSettings>()
        .Returns(new QueryableDatasourceRenderingSettings
        {
          SearchResultsLimit = 10
        });

      var results = GetResults(indexedItems);

      InitIndexes(index, searchProvider, results);
      var renderingModel = new QueryableDatasourceRenderingModel(renderingPropertiesRepository)
      {
        DatasourceString = "notEmpty"
      };

      //act
      var items = renderingModel.Items.ToArray();


      //assert
      items.Count().Should().Be(contentItems.Length);
      index.CreateSearchContext().ReceivedWithAnyArgs(1);
    }
    public void Items_ItemTemplateSet_FiltersByTemplateId(Db db, [Content] DbTemplate templateItem, [Content] DbItem[] contentItems, ISearchIndex index, [Frozen] SearchProvider searchProvider, Switcher<SearchProvider> searchProviderSwitcher, string indexName, [Content] Item renderingItem, IRenderingPropertiesRepository renderingPropertiesRepository)
    {
      //arrange
      var dbItem = new DbItem("templated", ID.NewID, templateItem.ID);
      db.Add(dbItem);
      var dbItems = contentItems.ToList();
      dbItems.Add(dbItem);
      var results = GetResults(dbItems);
      renderingPropertiesRepository.Get<QueryableDatasourceRenderingSettings>()
        .Returns(new QueryableDatasourceRenderingSettings
        {
          SearchResultsLimit = 10
        });

      InitIndexes(index, searchProvider, results);


      var renderingModel = new QueryableDatasourceRenderingModel(renderingPropertiesRepository)
      {
        Rendering = new Rendering(),
        DatasourceString = "notEmpty",
        DatasourceTemplate = db.GetItem(templateItem.ID)
      };

      //act
      var items = renderingModel.Items;

      //assert
      items.Count().Should().Be(1);
      index.CreateSearchContext().ReceivedWithAnyArgs(1);
    }
    public void Items_StandardValuesExistsInContentTree_IgnoresStandartValueByName(Db db, ISearchIndex index, [Frozen] SearchProvider searchProvider, Switcher<SearchProvider> searchProviderSwitcher, IRenderingPropertiesRepository renderingPropertiesRepository)
    {
      //arrange
      var id = ID.NewID;
      var dbItem = new DbItem(Sitecore.Constants.StandardValuesItemName, id);
      db.Add(dbItem);

      renderingPropertiesRepository.Get<QueryableDatasourceRenderingSettings>().Returns(new QueryableDatasourceRenderingSettings
      {
        SearchResultsLimit = 10
      });

      var results = GetResults(new List<DbItem>
      {
        dbItem
      });

      InitIndexes(index, searchProvider, results);
      var renderingModel = new QueryableDatasourceRenderingModel(renderingPropertiesRepository)
      {
        DatasourceString = "notEmpty"
      };

      //act
      var items = renderingModel.Items.ToArray();


      //assert
      items.Count().Should().Be(0);
    }