コード例 #1
0
        public void ExportManagerAllExportersTest()
        {
            // Arrange
            var context = new ExportImportContext();

            context.SetupAutocompletes(1);
            context.SetupRelatedQueries(2);

            var exporters = new List<IExporter> { context.AutocompleteExporter, context.RelatedQueryExporter };
            var exportManager = new ExportManager(exporters, context.SiteIdentityLoaderMock.Object, context.Settings);
            MemoryStream stream = new MemoryStream();

            // Act
            exportManager.ExportToStream(new List<string> { context.AutocompleteExporter.EntityKey, context.RelatedQueryExporter.EntityKey }, Helpers.AllSitesId, Helpers.AllLanguages, stream);

            // Assert
            var outputStream = new MemoryStream(stream.ToArray());
            var streamReader = new StreamReader(outputStream);
            var exportedData = streamReader.ReadToEnd();
            Assert.NotNull(exportedData);
            Assert.Equal("[{\"$type\":\"Vro.FindExportImport.Models.EntitySet`1[[Vro.FindExportImport.Models.IOptimizationEntity, Vro.FindExportImport]], Vro.FindExportImport\"," +
                         "\"Key\":\"AutocompleteEntity\",\"Entities\":[" +
                         "{\"$type\":\"Vro.FindExportImport.Models.AutocompleteEntity, Vro.FindExportImport\",\"priority\":0,\"query\":\"testAQuery0\",\"id\":\"testAId0\",\"tags\":[\"siteid:84bfaf5c52a349a0bc61a9ffb6983a66\",\"language:7d2da0a9fc754533b091fa6886a51c0d\"]}]}," +
                         "{\"$type\":\"Vro.FindExportImport.Models.EntitySet`1[[Vro.FindExportImport.Models.IOptimizationEntity, Vro.FindExportImport]], Vro.FindExportImport\"," +
                         "\"Key\":\"RelatedQueryEntity\",\"Entities\":[" +
                         "{\"$type\":\"Vro.FindExportImport.Models.RelatedQueryEntity, Vro.FindExportImport\",\"priority\":0,\"query\":\"testRQQuery0\",\"suggestion\":\"testRQSuggestion0\",\"id\":\"testRQId0\",\"tags\":[\"siteid:84bfaf5c52a349a0bc61a9ffb6983a66\",\"language:7d2da0a9fc754533b091fa6886a51c0d\"]}," +
                         "{\"$type\":\"Vro.FindExportImport.Models.RelatedQueryEntity, Vro.FindExportImport\",\"priority\":1,\"query\":\"testRQQuery1\",\"suggestion\":\"testRQSuggestion1\",\"id\":\"testRQId1\",\"tags\":[\"siteid:84bfaf5c52a349a0bc61a9ffb6983a66\",\"language:7d2da0a9fc754533b091fa6886a51c0d\"]}" +
                         "]}]", exportedData);
        }
        public void ExportManagerAllExportersTest()
        {
            // Arrange
            var context = new ExportImportContext();

            context.SetupAutocompletes(1);
            context.SetupRelatedQueries(2);

            var exporters = new List <IExporter> {
                context.AutocompleteExporter, context.RelatedQueryExporter
            };
            var          exportManager = new ExportManager(exporters, context.SiteIdentityLoaderMock.Object, context.Settings);
            MemoryStream stream        = new MemoryStream();

            // Act
            exportManager.ExportToStream(new List <string> {
                context.AutocompleteExporter.EntityKey, context.RelatedQueryExporter.EntityKey
            }, Helpers.AllSitesId, Helpers.AllLanguages, stream);

            // Assert
            var outputStream = new MemoryStream(stream.ToArray());
            var streamReader = new StreamReader(outputStream);
            var exportedData = streamReader.ReadToEnd();

            Assert.NotNull(exportedData);
            Assert.Equal("[{\"$type\":\"Vro.FindExportImport.Models.EntitySet`1[[Vro.FindExportImport.Models.IOptimizationEntity, Vro.FindExportImport]], Vro.FindExportImport\"," +
                         "\"Key\":\"AutocompleteEntity\",\"Entities\":[" +
                         "{\"$type\":\"Vro.FindExportImport.Models.AutocompleteEntity, Vro.FindExportImport\",\"priority\":0,\"query\":\"testAQuery0\",\"id\":\"testAId0\",\"tags\":[\"siteid:84bfaf5c52a349a0bc61a9ffb6983a66\",\"language:7d2da0a9fc754533b091fa6886a51c0d\"]}]}," +
                         "{\"$type\":\"Vro.FindExportImport.Models.EntitySet`1[[Vro.FindExportImport.Models.IOptimizationEntity, Vro.FindExportImport]], Vro.FindExportImport\"," +
                         "\"Key\":\"RelatedQueryEntity\",\"Entities\":[" +
                         "{\"$type\":\"Vro.FindExportImport.Models.RelatedQueryEntity, Vro.FindExportImport\",\"priority\":0,\"query\":\"testRQQuery0\",\"suggestion\":\"testRQSuggestion0\",\"id\":\"testRQId0\",\"tags\":[\"siteid:84bfaf5c52a349a0bc61a9ffb6983a66\",\"language:7d2da0a9fc754533b091fa6886a51c0d\"]}," +
                         "{\"$type\":\"Vro.FindExportImport.Models.RelatedQueryEntity, Vro.FindExportImport\",\"priority\":1,\"query\":\"testRQQuery1\",\"suggestion\":\"testRQSuggestion1\",\"id\":\"testRQId1\",\"tags\":[\"siteid:84bfaf5c52a349a0bc61a9ffb6983a66\",\"language:7d2da0a9fc754533b091fa6886a51c0d\"]}" +
                         "]}]", exportedData);
        }
        public void ExportManagerSitesTest()
        {
            // Arrange
            var context          = new ExportImportContext();
            var testSiteIdentity = new SiteIdentity
            {
                Id        = Guid.NewGuid(),
                Name      = "TestSite",
                RootPage  = "123",
                StartPage = "456"
            };

            context.SiteIdentityLoaderMock.SetupGet(l => l.SiteIdentites).Returns(new List <SiteIdentity> {
                testSiteIdentity
            });

            var exportManager = new ExportManager(new List <IExporter>(), context.SiteIdentityLoaderMock.Object, context.Settings);
            // Act
            var sites = exportManager.GetSites();

            // Assert
            Assert.Equal(2, sites.Count);
            Assert.Equal(Helpers.AllSitesId, sites[0].Id);
            Assert.Equal(testSiteIdentity.Id.ToString(), sites[1].Id);
        }
コード例 #4
0
        public void TestSetupRelatedQueriesExportImportContext()
        {
            var context = new ExportImportContext();

            context.SetupRelatedQueries(2);

            Assert.Equal(2, context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.RelatedQueryStoreMock.Object.Get("testRQId1"));

            var resRq = context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 1, 1);

            Assert.Equal(2, resRq.Total);
            Assert.Equal(1, resRq.Hits.Count);
            Assert.Equal("testRQId1", resRq.Hits.First().Id);

            context.RelatedQueryStoreMock.Object.Delete("testRQId1");
            Assert.Equal(1, context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.Null(context.RelatedQueryStoreMock.Object.Get("testRQId1"));

            context.RelatedQueryStoreMock.Object.Create(new RelatedQueryEntity
            {
                Id         = "myNewRQId",
                Priority   = 777,
                Query      = "myNewQuery",
                Suggestion = "myNewSuggestion"
            });
            Assert.Equal(2, context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.RelatedQueryStoreMock.Object.Get("myNewRQId"));
        }
コード例 #5
0
        public void TestSetupAutocompleteExportImportContext()
        {
            var context = new ExportImportContext();

            context.SetupAutocompletes(3);

            Assert.Equal(3, context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.AutocompleteStoreMock.Object.Get("testAId1"));

            var res = context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 2, 1);

            Assert.Equal(3, res.Total);
            Assert.Equal(1, res.Hits.Count);
            Assert.Equal("testAId2", res.Hits.First().Id);

            context.AutocompleteStoreMock.Object.Delete("testAId1");
            Assert.Equal(2, context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.Null(context.AutocompleteStoreMock.Object.Get("testAId1"));

            context.AutocompleteStoreMock.Object.Create(new AutocompleteEntity
            {
                Id       = "myNewAId",
                Priority = 999,
                Query    = "myNewQuery"
            });
            Assert.Equal(3, context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.AutocompleteStoreMock.Object.Get("myNewAId"));
        }
        public void ExportImportTest()
        {
            // Arrange
            var exportContext = new ExportImportContext();

            var autocompletesCount  = 25;
            var relatedQueriesCount = 49;

            exportContext.SetupAutocompletes(autocompletesCount);
            exportContext.SetupRelatedQueries(relatedQueriesCount);

            var exporters = new List <IExporter> {
                exportContext.AutocompleteExporter, exportContext.RelatedQueryExporter
            };
            var exportManager = new ExportManager(exporters, exportContext.SiteIdentityLoaderMock.Object, exportContext.Settings);


            var importContext = new ExportImportContext();

            importContext.SetupAutocompletes(0);
            importContext.SetupRelatedQueries(0);
            var importers = new List <IImporter> {
                importContext.AutocompleteImporter, importContext.RelatedQueryImporter
            };
            var importManager = new ImportManager(importers);

            // Act
            MemoryStream exportStream = new MemoryStream();

            exportManager.ExportToStream(new List <string> {
                exportContext.AutocompleteExporter.EntityKey, exportContext.RelatedQueryExporter.EntityKey
            }, Helpers.AllSitesId, Helpers.AllLanguages, exportStream);
            var importStream = new MemoryStream(exportStream.ToArray());

            importManager.ImportFromStream("MySite", importStream);

            // Assert
            Assert.Equal(autocompletesCount, importContext.Autocompletes.Count);
            Assert.Equal(relatedQueriesCount, importContext.RelatedQueries.Count);

            for (int i = 0; i < autocompletesCount; i++)
            {
                Assert.Equal(exportContext.Autocompletes[i].Id, importContext.Autocompletes[i].Id);
                Assert.Equal(exportContext.Autocompletes[i].Query, importContext.Autocompletes[i].Query);
                Assert.Equal(exportContext.Autocompletes[i].Priority, importContext.Autocompletes[i].Priority);
                Assert.NotEqual(exportContext.Autocompletes[i].Tags, importContext.Autocompletes[i].Tags);
                Assert.Equal("siteid:MySite", importContext.Autocompletes[i].Tags.First());
            }

            for (int i = 0; i < relatedQueriesCount; i++)
            {
                Assert.Equal(exportContext.RelatedQueries[i].Id, importContext.RelatedQueries[i].Id);
                Assert.Equal(exportContext.RelatedQueries[i].Query, importContext.RelatedQueries[i].Query);
                Assert.Equal(exportContext.RelatedQueries[i].Priority, importContext.RelatedQueries[i].Priority);
                Assert.Equal(exportContext.RelatedQueries[i].Suggestion, importContext.RelatedQueries[i].Suggestion);
                Assert.NotEqual(exportContext.RelatedQueries[i].Tags, importContext.RelatedQueries[i].Tags);
                Assert.Equal("siteid:MySite", importContext.RelatedQueries[i].Tags.First());
            }
        }
コード例 #7
0
        public void ExportImportTest()
        {
            // Arrange
            var exportContext = new ExportImportContext();

            var autocompletesCount = 25;
            var relatedQueriesCount = 49;

            exportContext.SetupAutocompletes(autocompletesCount);
            exportContext.SetupRelatedQueries(relatedQueriesCount);

            var exporters = new List<IExporter> { exportContext.AutocompleteExporter, exportContext.RelatedQueryExporter };
            var exportManager = new ExportManager(exporters, exportContext.SiteIdentityLoaderMock.Object, exportContext.Settings);

            var importContext = new ExportImportContext();
            importContext.SetupAutocompletes(0);
            importContext.SetupRelatedQueries(0);
            var importers = new List<IImporter> { importContext.AutocompleteImporter, importContext.RelatedQueryImporter };
            var importManager = new ImportManager(importers);

            // Act
            MemoryStream exportStream = new MemoryStream();
            exportManager.ExportToStream(new List<string> { exportContext.AutocompleteExporter.EntityKey, exportContext.RelatedQueryExporter.EntityKey }, Helpers.AllSitesId, Helpers.AllLanguages, exportStream);
            var importStream = new MemoryStream(exportStream.ToArray());
            importManager.ImportFromStream("MySite", importStream);

            // Assert
            Assert.Equal(autocompletesCount, importContext.Autocompletes.Count);
            Assert.Equal(relatedQueriesCount, importContext.RelatedQueries.Count);

            for (int i = 0; i < autocompletesCount; i++)
            {
                Assert.Equal(exportContext.Autocompletes[i].Id, importContext.Autocompletes[i].Id);
                Assert.Equal(exportContext.Autocompletes[i].Query, importContext.Autocompletes[i].Query);
                Assert.Equal(exportContext.Autocompletes[i].Priority, importContext.Autocompletes[i].Priority);
                Assert.NotEqual(exportContext.Autocompletes[i].Tags, importContext.Autocompletes[i].Tags);
                Assert.Equal("siteid:MySite", importContext.Autocompletes[i].Tags.First());
            }

            for (int i = 0; i < relatedQueriesCount; i++)
            {
                Assert.Equal(exportContext.RelatedQueries[i].Id, importContext.RelatedQueries[i].Id);
                Assert.Equal(exportContext.RelatedQueries[i].Query, importContext.RelatedQueries[i].Query);
                Assert.Equal(exportContext.RelatedQueries[i].Priority, importContext.RelatedQueries[i].Priority);
                Assert.Equal(exportContext.RelatedQueries[i].Suggestion, importContext.RelatedQueries[i].Suggestion);
                Assert.NotEqual(exportContext.RelatedQueries[i].Tags, importContext.RelatedQueries[i].Tags);
                Assert.Equal("siteid:MySite", importContext.RelatedQueries[i].Tags.First());
            }
        }
        public void ExportManagerLanguagesTest()
        {
            // Arrange
            var context = new ExportImportContext();

            context.Settings.Languages = new Languages();
            context.Settings.Languages.Add("sv");
            var exportManager = new ExportManager(new List <IExporter>(), context.SiteIdentityLoaderMock.Object, context.Settings);
            // Act
            var languages = exportManager.GetLanguages();

            // Assert
            Assert.Equal(2, languages.Count);
            Assert.Equal(new Guid(Helpers.AllLanguages), new Guid(languages[0].Id));
            Assert.Equal("sv", languages[1].Id);
        }
        public void ExportManagerDeleteTest()
        {
            // Arrange
            var context = new ExportImportContext();

            context.SetupAutocompletes(23);
            context.SetupRelatedQueries(12);

            var exporters = new List <IExporter> {
                context.AutocompleteExporter, context.RelatedQueryExporter
            };
            var exportManager = new ExportManager(exporters, context.SiteIdentityLoaderMock.Object, context.Settings);

            // Act
            exportManager.Delete(new List <string> {
                context.AutocompleteExporter.EntityKey
            }, Helpers.AllSitesId, Helpers.AllLanguages);

            // Assert
            Assert.Equal(0, context.Autocompletes.Count);
            Assert.Equal(12, context.RelatedQueries.Count);
        }
コード例 #10
0
        public void ExportManagerSitesTest()
        {
            // Arrange
            var context = new ExportImportContext();
            var testSiteIdentity = new SiteIdentity
            {
                Id = Guid.NewGuid(),
                Name = "TestSite",
                RootPage = "123",
                StartPage = "456"
            };
            context.SiteIdentityLoaderMock.SetupGet(l => l.SiteIdentites).Returns(new List<SiteIdentity> { testSiteIdentity});

            var exportManager = new ExportManager(new List<IExporter>(), context.SiteIdentityLoaderMock.Object, context.Settings);
            // Act
            var sites = exportManager.GetSites();

            // Assert
            Assert.Equal(2, sites.Count);
            Assert.Equal(Helpers.AllSitesId, sites[0].Id);
            Assert.Equal(testSiteIdentity.Id.ToString(), sites[1].Id);
        }
コード例 #11
0
        public void ExportManagerLanguagesTest()
        {
            // Arrange
            var context = new ExportImportContext();
            context.Settings.Languages = new Languages();
            context.Settings.Languages.Add("sv");
            var exportManager = new ExportManager(new List<IExporter>(), context.SiteIdentityLoaderMock.Object, context.Settings);
            // Act
            var languages = exportManager.GetLanguages();

            // Assert
            Assert.Equal(2, languages.Count);
            Assert.Equal(new Guid(Helpers.AllLanguages), new Guid(languages[0].Id));
            Assert.Equal("sv", languages[1].Id);
        }
コード例 #12
0
        public void ExportManagerDeleteTest()
        {
            // Arrange
            var context = new ExportImportContext();

            context.SetupAutocompletes(23);
            context.SetupRelatedQueries(12);

            var exporters = new List<IExporter> { context.AutocompleteExporter, context.RelatedQueryExporter };
            var exportManager = new ExportManager(exporters, context.SiteIdentityLoaderMock.Object, context.Settings);

            // Act
            exportManager.Delete(new List<string> { context.AutocompleteExporter.EntityKey }, Helpers.AllSitesId, Helpers.AllLanguages);

            // Assert
            Assert.Equal(0, context.Autocompletes.Count);
            Assert.Equal(12, context.RelatedQueries.Count);
        }
コード例 #13
0
        public void TestSetupRelatedQueriesExportImportContext()
        {
            var context = new ExportImportContext();

            context.SetupRelatedQueries(2);

            Assert.Equal(2, context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.RelatedQueryStoreMock.Object.Get("testRQId1"));

            var resRq = context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 1, 1);
            Assert.Equal(2, resRq.Total);
            Assert.Equal(1, resRq.Hits.Count);
            Assert.Equal("testRQId1", resRq.Hits.First().Id);

            context.RelatedQueryStoreMock.Object.Delete("testRQId1");
            Assert.Equal(1, context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.Null(context.RelatedQueryStoreMock.Object.Get("testRQId1"));

            context.RelatedQueryStoreMock.Object.Create(new RelatedQueryEntity
            {
                Id = "myNewRQId",
                Priority = 777,
                Query = "myNewQuery",
                Suggestion = "myNewSuggestion"
            });
            Assert.Equal(2, context.RelatedQueryStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.RelatedQueryStoreMock.Object.Get("myNewRQId"));
        }
コード例 #14
0
        public void TestSetupAutocompleteExportImportContext()
        {
            var context = new ExportImportContext();
            context.SetupAutocompletes(3);

            Assert.Equal(3, context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.AutocompleteStoreMock.Object.Get("testAId1"));

            var res = context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 2, 1);
            Assert.Equal(3, res.Total);
            Assert.Equal(1, res.Hits.Count);
            Assert.Equal("testAId2", res.Hits.First().Id);

            context.AutocompleteStoreMock.Object.Delete("testAId1");
            Assert.Equal(2, context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.Null(context.AutocompleteStoreMock.Object.Get("testAId1"));

            context.AutocompleteStoreMock.Object.Create(new AutocompleteEntity
            {
                Id = "myNewAId",
                Priority = 999,
                Query = "myNewQuery"
            });
            Assert.Equal(3, context.AutocompleteStoreMock.Object.List(Helpers.AllSitesId, Helpers.AllLanguages, 0, 20).Total);
            Assert.NotNull(context.AutocompleteStoreMock.Object.Get("myNewAId"));
        }