public void UpgradeReusedHelpUrls()
        {
            var dataStoreManager = new TestFixtureDataStoreManager();
            var reusedUrl        = "/Duplicate/URL";

            // Create starting content data.
            var firstHelp = Models.CreateFirstTimeHelp(matchUrls: "/ /Home /Home/*");

            _firstTimeHelpRepository.Create(firstHelp);
            var originalUrlHelp = Models.CreateFirstTimeHelp(matchUrls: reusedUrl);

            _firstTimeHelpRepository.Create(originalUrlHelp);

            // Generate starting content file.
            var startingContentFileName = Path.GetTempFileName();

            dataStoreManager.ExportContent(startingContentFileName);

            // Create upgrade content data.
            var noiseHelp = Models.CreateFirstTimeHelp();               // Need to bump table id so reusedUrlPage receives a different id.

            _firstTimeHelpRepository.Create(noiseHelp);
            _firstTimeHelpRepository.Delete(originalUrlHelp.Id);
            var reusedUrlHelp = Models.CreateFirstTimeHelp(matchUrls: reusedUrl);

            _firstTimeHelpRepository.Create(reusedUrlHelp);

            // Generate upgrade content file.
            var upgradeContentFileName = Path.GetTempFileName();

            dataStoreManager.ExportContent(upgradeContentFileName);

            // Reset the data store to the starting data.
            dataStoreManager.DeleteDataStore();
            dataStoreManager.CreateDataStore();
            dataStoreManager.ImportContent(startingContentFileName);

            // Try upgrading content using upgrade script.
            dataStoreManager.ImportContent(upgradeContentFileName);

            // Read data from updated data store.
            var newFirstHelp       = _firstTimeHelpRepository.Read(firstHelp.Id);
            var newOriginalUrlHelp = _firstTimeHelpRepository.Read(originalUrlHelp.Id);
            var newNoiseHelp       = _firstTimeHelpRepository.Read(noiseHelp.Id);
            var newReusedUrlHelp   = _firstTimeHelpRepository.Read(reusedUrlHelp.Id);

            // Validate data.
            Assert.That(originalUrlHelp.Id, Is.LessThan(reusedUrlHelp.Id), "The second help must have a higher id.");
            Assert.That(newFirstHelp, Is.Not.Null);
            Assert.That(newNoiseHelp, Is.Not.Null);
            Assert.That(newReusedUrlHelp, Is.Not.Null);
            Assert.That(newOriginalUrlHelp, Is.Null);
        }
Example #2
0
        public ResponseState Process(string data)
        {
            var serializer = new JavaScriptSerializer();
            var clientHelp = serializer.Deserialize <FirstTimeHelp>(data);

            if (clientHelp.Id > 0)              // For existing pages ...
            {
                _firstTimeHelpRepository.Update(clientHelp);

                var dataStoreBullets = _bulletRepository.ReadByPageId(clientHelp.Id);
                // Process incoming bullets. If they exist update, otherwise create.
                foreach (var clientBullet in clientHelp.Bullets)
                {
                    clientBullet.PageId = clientHelp.Id;
                    if (dataStoreBullets.Any(dataStoreBullet => dataStoreBullet.Id == clientBullet.Id))
                    {
                        _bulletRepository.Update(clientBullet);
                    }
                    else
                    {
                        _bulletRepository.Create(clientBullet);
                    }
                }
                // Delete any existing bullets not included with incoming bullets.
                foreach (var dataStoreBullet in dataStoreBullets)
                {
                    if (!clientHelp.Bullets.Any(clientBullet => clientBullet.Id == dataStoreBullet.Id))
                    {
                        _bulletRepository.Delete(dataStoreBullet.Id);
                    }
                }
            }
            else             // For new pages ...
            {
                _firstTimeHelpRepository.Create(clientHelp);
                foreach (var clientBullet in clientHelp.Bullets)
                {
                    clientBullet.PageId = clientHelp.Id;
                    _bulletRepository.Create(clientBullet);
                }
            }

            var pageJson = serializer.Serialize(clientHelp);

            return(new ResponseState
            {
                Content = pageJson,
                ContentType = ContentTypes.Json,
            });
        }