Ejemplo n.º 1
0
        public void loadcollection_fileio_not_found_throws_exception()
        {
            IHomeCollectionRepository repo = new HomeCollectionRepository(_mockFileIO.Object);

            _mockFileIO.Setup(i => i.ReadFile(It.IsAny <string>())).Throws(new CollectionException());
            string fullFilePath = "badfilepath";

            ICollectionBase collection = repo.LoadCollection(fullFilePath);

            Assert.Fail($"Expected exception to be thrown when the file is not found: {fullFilePath}");
        }
Ejemplo n.º 2
0
        public void loadcollection_file_invalid_json_content_throws_exception()
        {
            IHomeCollectionRepository repo = new HomeCollectionRepository(_mockFileIO.Object);
            string mockFileContent         = "this is some invalid Json content";

            _mockFileIO.Setup(i => i.ReadFile(It.IsAny <string>())).Returns(mockFileContent);
            string fullFilePath = "filepath";

            ICollectionBase collection = repo.LoadCollection(fullFilePath);

            Assert.Fail($"Expected exception to be thrown when the file content cannot be parsed into a collection: {fullFilePath}");
        }
Ejemplo n.º 3
0
        public void load_test_book_collection_from_disk()
        {
            string collectionName = "Star Trek Books - YTH";

            // Initialize a repository
            IFileIO fileIO = new FileIO();
            HomeCollectionRepository repo = new HomeCollectionRepository(fileIO);

            string fullFilePath = Environment.CurrentDirectory + @"\";

            fullFilePath += collectionName + @"." + HomeCollectionRepository.FILE_EXTENSION;

            ICollectionBase books = repo.LoadCollection(fullFilePath);
        }
Ejemplo n.º 4
0
        public void load_test_stamp_collection_from_disk()
        {
            string collectionName = "USA Stamps - Special";
            //string collectionName = "Test StampBase Collection_formatted";

            // Initialize a repository
            IFileIO fileIO = new FileIO();
            HomeCollectionRepository repo = new HomeCollectionRepository(fileIO);

            string fullFilePath = Environment.CurrentDirectory + @"\";

            fullFilePath += collectionName + @"." + HomeCollectionRepository.FILE_EXTENSION;

            ICollectionBase stamps = repo.LoadCollection(fullFilePath);
        }
Ejemplo n.º 5
0
        public void loadcollection_file_valid_json_content_returns_collection()
        {
            IHomeCollectionRepository repo = new HomeCollectionRepository(_mockFileIO.Object);

            foreach (Type collectionType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectionBase testCollection  = GetTestCollection("test collection", collectionType, 1);
                string          testFileContent = HomeCollectionRepository.ConvertCollectionToJson(testCollection);
                _mockFileIO.Setup(i => i.ReadFile(It.IsAny <string>())).Returns(testFileContent);
                string fullFilePath = "filepath";

                ICollectionBase collection = repo.LoadCollection(fullFilePath);

                Assert.IsNotNull(collection);
            }
        }
Ejemplo n.º 6
0
        public void loadcollection_with_path_filename_calls_getfullfilepath()
        {
            IHomeCollectionRepository repo = new HomeCollectionRepository(_mockFileIO.Object);

            _mockFileIO.Setup(f => f.GetFullFilePath(It.IsAny <string>(), It.IsAny <string>()))
            .Returns((string p, string f) => p + @"\" + f);

            foreach (Type collectionType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectionBase testCollection  = GetTestCollection("test collection", collectionType, 1);
                string          testFileContent = HomeCollectionRepository.ConvertCollectionToJson(testCollection);
                _mockFileIO.Setup(i => i.ReadFile(It.IsAny <string>())).Returns(testFileContent);
                string path     = "path";
                string filename = "filename";

                ICollectionBase collection = repo.LoadCollection(path, filename);
            }
            _mockFileIO.Verify(r => r.GetFullFilePath(It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(CollectableBaseFactory.CollectableTypes.Count));
        }