public async Task TestDataExport()
        {
            string expectedJson;

            using (var resourceStream = ReadEmbeddedResource("Resources.SerializedSitemapsData.json"))
                using (var textReader = new StreamReader(resourceStream))
                {
                    expectedJson = await textReader.ReadToEndAsync();
                }

            // Act
            string actualJson;

            using (var targetStream = new MemoryStream())
            {
                await _sitemapExportImport.DoExportAsync(targetStream, IgnoreProgressInfo, _cancellationToken.Object);

                var targetStreamContents = targetStream.ToArray();
                using (var copiedStream = new MemoryStream(targetStreamContents))
                    using (var textReader = new StreamReader(copiedStream))
                    {
                        actualJson = textReader.ReadToEnd();
                    }
            }

            // Assert
            var expectedJObject = JsonConvert.DeserializeObject <JObject>(expectedJson);
            var actualJObject   = JsonConvert.DeserializeObject <JObject>(actualJson);

            Assert.True(JToken.DeepEquals(expectedJObject, actualJObject));
        }
Exemple #2
0
        public async Task TestDataExport()
        {
            // Arrange
            var sitemapSearchCriteria = new SitemapSearchCriteria
            {
                Skip = 0,
                Take = int.MaxValue
            };
            var sitemapSearchResult = new GenericSearchResult <Sitemap>
            {
                TotalCount = TestSitemaps.Count,
                Results    = TestSitemaps
            };

            _sitemapService.Setup(service => service.SearchAsync(sitemapSearchCriteria))
            .ReturnsAsync(sitemapSearchResult);

            var sitemapItemSearchCriteria = new SitemapItemSearchCriteria
            {
                Skip = 0,
                Take = int.MaxValue
            };
            var sitemapItemsSearchResult = new GenericSearchResult <SitemapItem>
            {
                TotalCount = TestSitemapItems.Count,
                Results    = TestSitemapItems
            };

            _sitemapItemService.Setup(service => service.SearchAsync(sitemapItemSearchCriteria))
            .ReturnsAsync(sitemapItemsSearchResult);

            string expectedJson;

            using (var resourceStream = ReadEmbeddedResource("Resources.SerializedSitemapsData.json"))
                using (var textReader = new StreamReader(resourceStream))
                {
                    expectedJson = await textReader.ReadToEndAsync();
                }

            // Act
            string actualJson;

            using (var targetStream = new MemoryStream())
            {
                await _sitemapExportImport.DoExportAsync(targetStream, IgnoreProgressInfo, _cancellationToken.Object);

                var targetStreamContents = targetStream.ToArray();
                using (var copiedStream = new MemoryStream(targetStreamContents))
                    using (var textReader = new StreamReader(copiedStream))
                    {
                        actualJson = textReader.ReadToEnd();
                    }
            }

            // Assert
            var expectedJObject = JsonConvert.DeserializeObject <JObject>(expectedJson);
            var actualJObject   = JsonConvert.DeserializeObject <JObject>(actualJson);

            Assert.True(JToken.DeepEquals(expectedJObject, actualJObject));
        }