public void AutocompleteStoreCreateTest() { // Arrange string requestUrl = ""; HttpVerbs? httpVerb = null; var context = new IndexStoreTestContext(); var mockRequestFactory = context.GetMockRequestFactory( @"{'status':'ok','id':'testAId'}", ((url, verbs, timeout) => { requestUrl = url; httpVerb = verbs; })); var autocompleteStore = context.StoreFactory.GetStore<AutocompleteEntity>() as IndexStore<AutocompleteEntity>; autocompleteStore.RequestFactory = mockRequestFactory.Object; var entity = new AutocompleteEntity { Id = "testAId", Priority = 223, Query = "testAQuery", Tags = new List<string>() }; // Act var result = autocompleteStore.Create(entity); // Assert Assert.Equal("http://myfindurl/myindex/_autocomplete", requestUrl); Assert.Equal(HttpVerbs.Put, httpVerb.Value); Assert.Equal("testAId", result); }
public void SetupAutocompletes(int count) { Autocompletes = new List<AutocompleteEntity>(); for (int i = 0; i < count; i++) { var autocompleteEntity = new AutocompleteEntity { Id = "testAId"+i, Priority = i, Query = "testAQuery"+i, Tags = new List<string> { "siteid:" + Helpers.AllSitesId, "language:" + Helpers.AllLanguages } }; Autocompletes.Add(autocompleteEntity); } AutocompleteStoreMock.Setup(s => s.Get(It.IsAny<string>())).Returns<string>(id => Autocompletes.FirstOrDefault(a => a.Id.Equals(id))); AutocompleteStoreMock.Setup(s => s.Create(It.IsAny<AutocompleteEntity>())) .Callback<AutocompleteEntity>(e => Autocompletes.Add(e)); AutocompleteStoreMock.Setup(s => s.Delete(It.IsAny<string>())) .Callback<string>(id => Autocompletes.RemoveAll(a => a.Id.Equals(id))); AutocompleteStoreMock.Setup(s => s.List(Helpers.AllSitesId, Helpers.AllLanguages, It.IsAny<int>(), It.IsAny<int>())) .Returns<string, string, int,int>((site, language, from, size) => new ListResult<AutocompleteEntity> { Status = "ok", Total = Autocompletes.Count, Hits = Autocompletes.Skip(from).Take(size).ToList() }); }