Skip to content

Instantly share code, notes, and snippets.

View viviandeveloper's full-sized avatar

Vivian viviandeveloper

View GitHub Profile
@viviandeveloper
viviandeveloper / Azure_Function_Test_With_Table_Binding.cs
Created February 14, 2021 01:00
A workaround for testing against CloudTable. Although CloudTable has a lot of virtual methods that can be easily mocked some examples don't work with dynamic mocking such as CreateQuery<T> with System.Linq, but there is a way!
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Cosmos.Table;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using RichardSzalay.MockHttp;
using System.Collections.Generic;
using System.Linq;
@viviandeveloper
viviandeveloper / ContentSearchTesting.cs
Last active October 20, 2023 10:33
Solution to the wretched "There is no method 'GetResults' on type 'Sitecore.ContentSearch.Linq.QueryableExtensions' that matches the specified arguments" error when unit testing search. Sitecore is tightly coupled to their own implemention of IQueryProvider which contains an 'Execute' method not found on standard .Net implementions.
namespace Testing
{
public class NewsController_LatestNews
{
[Theory]
[AutoData]
public void Should_be_news_items_ordered_by_date_descending(IEnumerable<NewsResultItem> newsResultItems)
{
var searchContext = Substitute.For<IProviderSearchContext>();
var queryable = new LuceneProviderQueryableStub(enumerable);