Exemplo n.º 1
0
        public void AutocompleteStoreGetByIdTest()
        {
            // Arrange
            string    requestUrl         = "";
            HttpVerbs?httpVerb           = null;
            var       context            = new IndexStoreTestContext();
            var       mockRequestFactory = context.GetMockRequestFactory(
                @"{ 
                    'id':'testId',
                    'query':'testQuery',
                    'type':'editorial',
                    'priority':536870912,
                    'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                    'timestamp':'2015 - 10 - 30T17: 28:02Z'
                }",
                ((url, verbs, timeout) => {
                requestUrl = url;
                httpVerb = verbs;
            }));
            var autocompleteStore = context.StoreFactory.GetStore <AutocompleteEntity>() as IndexStore <AutocompleteEntity>;

            autocompleteStore.RequestFactory = mockRequestFactory.Object;

            // Act
            var entity = autocompleteStore.Get("testId");

            // Assert
            Assert.Equal("http://myfindurl/myindex/_autocomplete/testId", requestUrl);
            Assert.Equal(HttpVerbs.Get, httpVerb.Value);
            Assert.NotNull(entity);
            Assert.Equal("testId", entity.Id);
            Assert.Equal("testQuery", entity.Query);
            Assert.Equal(536870912, entity.Priority);
            Assert.Equal(2, entity.Tags.Count);
        }
Exemplo n.º 2
0
        public void AutocompleteExporterWriteToStream()
        {
            // Arrange
            var context    = new IndexStoreTestContext();
            var textWriter = new StringWriter();
            var writer     = new JsonTextWriter(textWriter);
            var exporter   = new AutocompleteExporter(context.StoreFactory);

            ((IndexStore <AutocompleteEntity>)exporter.Store).RequestFactory = context.GetMockRequestFactory(
                @"{ 
                    'total':2,
                    'status': 'ok',
                    'hits': [{
                            'id':'testId',
                            'query':'testQuery',
                            'type':'editorial',
                            'priority':536870912,
                            'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                            'timestamp':'2015 - 10 - 30T17: 28:02Z'
                        }, 
                        {
                            'id':'testId2',
                            'query':'testQuery2',
                            'type':'editorial',
                            'priority':123456,
                            'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                            'timestamp':'2015 - 10 - 30T17: 20:02Z'
                        }]
                }",
                (url, verbs, timeout) => {}).Object;

            // Act
            exporter.WriteToStream(Helpers.AllSitesId, Helpers.AllLanguages, writer);

            // Assert
            var exportResultsString = textWriter.ToString();

            Assert.NotNull(exportResultsString);

            var exportResults = exporter.DefaultSerializer.Deserialize <EntitySet <IOptimizationEntity> >(
                new JsonTextReader(new StringReader(exportResultsString)));

            Assert.Equal(typeof(AutocompleteEntity).Name, exportResults.Key);
            Assert.Equal(2, exportResults.Entities.Count);
            Assert.IsAssignableFrom(typeof(AutocompleteEntity), exportResults.Entities.First());

            var exportedEntity1 = exportResults.Entities[0] as AutocompleteEntity;

            Assert.NotNull(exportedEntity1);
            Assert.Equal("testId", exportedEntity1.Id);
            Assert.Equal("testQuery", exportedEntity1.Query);
            Assert.Equal(536870912, exportedEntity1.Priority);

            var exportedEntity2 = exportResults.Entities[1] as AutocompleteEntity;

            Assert.NotNull(exportedEntity2);
            Assert.Equal("testId2", exportedEntity2.Id);
            Assert.Equal("testQuery2", exportedEntity2.Query);
            Assert.Equal(123456, exportedEntity2.Priority);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void AutocompleteStoreListTest()
        {
            // Arrange
            string    requestUrl = "";
            HttpVerbs?httpVerb   = null;
            var       context    = new IndexStoreTestContext();

            var mockRequestFactory = context.GetMockRequestFactory(
                @"{ 
                    'total':2,
                    'status': 'ok',
                    'hits': [{
                        'id':'testId',
                        'query':'testQuery',
                        'type':'editorial',
                        'priority':536870912,
                        'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                        'timestamp':'2015 - 10 - 30T17: 28:02Z'
                        }, {
                        'id':'testId2',
                        'query':'testQuery2',
                        'type':'editorial',
                        'priority':123456,
                        'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                        'timestamp':'2015 - 10 - 30T17: 20:02Z'
                        }]
                }",
                ((url, verbs, timeout) => {
                requestUrl = url;
                httpVerb = verbs;
            }));
            var autocompleteStore = context.StoreFactory.GetStore <AutocompleteEntity>() as IndexStore <AutocompleteEntity>;

            autocompleteStore.RequestFactory = mockRequestFactory.Object;

            // Act
            var entityList = autocompleteStore.List("84bfaf5c52a349a0bc61a9ffb6983a66", "7d2da0a9fc754533b091fa6886a51c0d", 0, 5);

            // Assert
            Assert.Equal("http://myfindurl/myindex/_autocomplete/list?from=0&size=5&tags=siteid:84bfaf5c52a349a0bc61a9ffb6983a66,language:7d2da0a9fc754533b091fa6886a51c0d", requestUrl);
            Assert.Equal(HttpVerbs.Get, httpVerb.Value);
            Assert.NotNull(entityList);
            Assert.Equal(2, entityList.Hits.Count);
            Assert.Equal("testId", entityList.Hits[0].Id);
            Assert.Equal("testQuery", entityList.Hits[0].Query);
            Assert.Equal(536870912, entityList.Hits[0].Priority);
            Assert.Equal(2, entityList.Hits[0].Tags.Count);
        }
Exemplo n.º 6
0
        public void AutocompleteStoreDeleteTest()
        {
            // Arrange
            string    requestUrl = "";
            HttpVerbs?httpVerb   = null;
            var       context    = new IndexStoreTestContext();

            var mockRequestFactory = context.GetMockRequestFactory(
                @"{'status':'ok','id':'testId'}",
                ((url, verbs, timeout) => {
                requestUrl = url;
                httpVerb = verbs;
            }));
            var autocompleteStore = context.StoreFactory.GetStore <AutocompleteEntity>() as IndexStore <AutocompleteEntity>;

            autocompleteStore.RequestFactory = mockRequestFactory.Object;

            // Act
            autocompleteStore.Delete("testId");

            // Assert
            Assert.Equal("http://myfindurl/myindex/_autocomplete/testId", requestUrl);
            Assert.Equal(HttpVerbs.Delete, httpVerb.Value);
        }
Exemplo n.º 7
0
        public void AutocompleteExporterWriteToStream()
        {
            // Arrange
            var context = new IndexStoreTestContext();
            var textWriter = new StringWriter();
            var writer = new JsonTextWriter(textWriter);
            var exporter = new AutocompleteExporter(context.StoreFactory);
            ((IndexStore<AutocompleteEntity>) exporter.Store).RequestFactory = context.GetMockRequestFactory(
                @"{
                    'total':2,
                    'status': 'ok',
                    'hits': [{
                            'id':'testId',
                            'query':'testQuery',
                            'type':'editorial',
                            'priority':536870912,
                            'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                            'timestamp':'2015 - 10 - 30T17: 28:02Z'
                        },
                        {
                            'id':'testId2',
                            'query':'testQuery2',
                            'type':'editorial',
                            'priority':123456,
                            'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                            'timestamp':'2015 - 10 - 30T17: 20:02Z'
                        }]
                }",
                (url, verbs, timeout) => {}).Object;

            // Act
            exporter.WriteToStream(Helpers.AllSitesId, Helpers.AllLanguages, writer);

            // Assert
            var exportResultsString = textWriter.ToString();
            Assert.NotNull(exportResultsString);

            var exportResults = exporter.DefaultSerializer.Deserialize<EntitySet<IOptimizationEntity>>(
                new JsonTextReader(new StringReader(exportResultsString)));
            Assert.Equal(typeof(AutocompleteEntity).Name, exportResults.Key);
            Assert.Equal(2, exportResults.Entities.Count);
            Assert.IsAssignableFrom(typeof(AutocompleteEntity), exportResults.Entities.First());

            var exportedEntity1 = exportResults.Entities[0] as AutocompleteEntity;
            Assert.NotNull(exportedEntity1);
            Assert.Equal("testId", exportedEntity1.Id);
            Assert.Equal("testQuery", exportedEntity1.Query);
            Assert.Equal(536870912, exportedEntity1.Priority);

            var exportedEntity2 = exportResults.Entities[1] as AutocompleteEntity;
            Assert.NotNull(exportedEntity2);
            Assert.Equal("testId2", exportedEntity2.Id);
            Assert.Equal("testQuery2", exportedEntity2.Query);
            Assert.Equal(123456, exportedEntity2.Priority);
        }
Exemplo n.º 8
0
        public void AutocompleteStoreDeleteTest()
        {
            // Arrange
            string requestUrl = "";
            HttpVerbs? httpVerb = null;
            var context = new IndexStoreTestContext();

            var mockRequestFactory = context.GetMockRequestFactory(
                @"{'status':'ok','id':'testId'}",
                ((url, verbs, timeout) => {
                    requestUrl = url;
                    httpVerb = verbs;
                }));
            var autocompleteStore = context.StoreFactory.GetStore<AutocompleteEntity>() as IndexStore<AutocompleteEntity>;
            autocompleteStore.RequestFactory = mockRequestFactory.Object;

            // Act
            autocompleteStore.Delete("testId");

            // Assert
            Assert.Equal("http://myfindurl/myindex/_autocomplete/testId", requestUrl);
            Assert.Equal(HttpVerbs.Delete, httpVerb.Value);
        }
Exemplo n.º 9
0
        public void AutocompleteStoreListTest()
        {
            // Arrange
            string requestUrl = "";
            HttpVerbs? httpVerb = null;
            var context = new IndexStoreTestContext();

            var mockRequestFactory = context.GetMockRequestFactory(
                @"{
                    'total':2,
                    'status': 'ok',
                    'hits': [{
                        'id':'testId',
                        'query':'testQuery',
                        'type':'editorial',
                        'priority':536870912,
                        'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                        'timestamp':'2015 - 10 - 30T17: 28:02Z'
                        }, {
                        'id':'testId2',
                        'query':'testQuery2',
                        'type':'editorial',
                        'priority':123456,
                        'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                        'timestamp':'2015 - 10 - 30T17: 20:02Z'
                        }]
                }",
                ((url, verbs, timeout) => {
                    requestUrl = url;
                    httpVerb = verbs;
                }));
            var autocompleteStore = context.StoreFactory.GetStore<AutocompleteEntity>() as IndexStore<AutocompleteEntity>;
            autocompleteStore.RequestFactory = mockRequestFactory.Object;

            // Act
            var entityList = autocompleteStore.List("84bfaf5c52a349a0bc61a9ffb6983a66", "7d2da0a9fc754533b091fa6886a51c0d", 0, 5);

            // Assert
            Assert.Equal("http://myfindurl/myindex/_autocomplete/list?from=0&size=5&tags=siteid:84bfaf5c52a349a0bc61a9ffb6983a66,language:7d2da0a9fc754533b091fa6886a51c0d", requestUrl);
            Assert.Equal(HttpVerbs.Get, httpVerb.Value);
            Assert.NotNull(entityList);
            Assert.Equal(2, entityList.Hits.Count);
            Assert.Equal("testId", entityList.Hits[0].Id);
            Assert.Equal("testQuery", entityList.Hits[0].Query);
            Assert.Equal(536870912, entityList.Hits[0].Priority);
            Assert.Equal(2, entityList.Hits[0].Tags.Count);
        }
Exemplo n.º 10
0
        public void AutocompleteStoreGetByIdTest()
        {
            // Arrange
            string requestUrl = "";
            HttpVerbs? httpVerb = null;
            var context = new IndexStoreTestContext();
            var mockRequestFactory = context.GetMockRequestFactory(
                @"{
                    'id':'testId',
                    'query':'testQuery',
                    'type':'editorial',
                    'priority':536870912,
                    'tags':['siteid: 84bfaf5c52a349a0bc61a9ffb6983a66','language: 7d2da0a9fc754533b091fa6886a51c0d'],
                    'timestamp':'2015 - 10 - 30T17: 28:02Z'
                }",
                ((url, verbs, timeout) => {
                    requestUrl = url;
                    httpVerb = verbs;
                }));
            var autocompleteStore = context.StoreFactory.GetStore<AutocompleteEntity>() as IndexStore<AutocompleteEntity>;
            autocompleteStore.RequestFactory = mockRequestFactory.Object;

            // Act
            var entity = autocompleteStore.Get("testId");

            // Assert
            Assert.Equal("http://myfindurl/myindex/_autocomplete/testId", requestUrl);
            Assert.Equal(HttpVerbs.Get, httpVerb.Value);
            Assert.NotNull(entity);
            Assert.Equal("testId", entity.Id);
            Assert.Equal("testQuery", entity.Query);
            Assert.Equal(536870912, entity.Priority);
            Assert.Equal(2, entity.Tags.Count);
        }