Example #1
0
        public void ShouldMigrateExistingData()
        {
            var          aboutRepository = new AboutRepository(_mongoDbProvider);
            const string dataBaseDir     = "C:/dev/Phillip Buttrose/Guitars/Web/assets/about";

            Console.WriteLine("MigrateAbout - purge");

            aboutRepository.Purge();

            Console.WriteLine("MigrateAbout - load");

            var jsonData       = File.ReadAllText(Path.Combine(dataBaseDir, "data.json"));
            var aboutViewModel = JsonConvert.DeserializeObject <AboutViewModel>(jsonData);
            var adoutDataModel = new AboutDataModel
            {
                _id         = new ObjectId(),
                Title       = aboutViewModel.Title,
                SubTitle    = aboutViewModel.SubTitle,
                Description = aboutViewModel.Description,
                Image       = aboutRepository.UploadFiles(dataBaseDir, new List <string> {
                    aboutViewModel.Image
                }).FirstOrDefault(),
                FacebookUrl   = aboutViewModel.FacebookUrl,
                GooglePlusUrl = aboutViewModel.GooglePlusUrl,
                LinkedInUrl   = aboutViewModel.LinkedInUrl,
                TwitterUrl    = aboutViewModel.TwitterUrl
            };

            Console.WriteLine("MigrateAbout - save");

            aboutRepository.Save(adoutDataModel);
        }
Example #2
0
        private static void MigrateAbout()
        {
            var aboutRepository = new AboutRepository(_mongoDbProvider);
            var dataBaseDir     = "C:\\dev\\Phillip Buttrose\\Guitars\\Web\\assets\\about";

            var jsonData       = File.ReadAllText(Path.Combine(dataBaseDir, "data.json"));
            var aboutViewModel = JsonConvert.DeserializeObject <AboutViewModel>(jsonData);
            var adoutDataModel = new AboutDataModel
            {
                _id         = new ObjectId(),
                Title       = aboutViewModel.Title,
                SubTitle    = aboutViewModel.SubTitle,
                Description = aboutViewModel.Description,
                Image       =
                    _imageConverter.Convert(
                        Image.FromFile(Path.Combine(dataBaseDir, aboutViewModel.Image))),
                FacebookUrl   = aboutViewModel.FacebookUrl,
                GooglePlusUrl = aboutViewModel.GooglePlusUrl,
                LinkedInUrl   = aboutViewModel.LinkedInUrl,
                TwitterUrl    = aboutViewModel.TwitterUrl
            };

            aboutRepository.Purge();
            aboutRepository.Save(adoutDataModel);
        }
        public void ShouldSaveDataModelToMongoLab()
        {
            // Arrage
            var bsonBinaryData = new BsonBinaryData(_imageConverter.Convert(Image.FromFile("C:\\dev\\Phillip Buttrose\\Guitars\\Web\\assets\\about\\images\\DSC_0168.JPG")));
            var dataModel      = new AboutDataModel
            {
                Title       = "Phillip J Buttrose Pty Ltd",
                SubTitle    = "Phillip Buttrose - Luthier",
                Image       = bsonBinaryData,
                Description = new List <string>
                {
                    "Phillip has recently retired from a working life of farming, the military and the construction industry.",
                    "He has settled in the hills above Perth in Western Australia, and working alone in his small workshop builds just a handful of handcrafted classical guitars a year.",
                    "Inspired by the Ignacio Feta\u2019s 1962-67 guitars and handcrafted from Australian native tone woods, these guitars have brilliant bell like trebles and balanced clear deep base tones.  The guitars require a gentle action to achieve excellent volume with exceptional sustain."
                },
                TwitterUrl  = "https://twitter.com/PhillipButtrose",
                FacebookUrl = "https://www.facebook.com/pages/Phillip-J-Buttrose/355734807900191",
                LinkedInUrl =
                    "http://www.linkedin.com/profile/view?id=327250818&locale=en_US&trk=tyah&trkInfo=tas%3Aphillip%2Cidx%3A2-3-4",
                GooglePlusUrl = "https://plus.google.com/113144916347440280117/posts"
            };
            var savedDataModel = dataModel.Clone();

            savedDataModel._id = new ObjectId();
            _mongoDbProvider.Update("about", dataModel).Returns(dataModel);

            // Act
            var updatedModel = _repositoryUnderTest.Save(dataModel);

            // Assert
            Assert.That(updatedModel._id, Is.EqualTo(savedDataModel._id));
            Assert.That(updatedModel.Title, Is.EqualTo(dataModel.Title));
        }