Ejemplo n.º 1
0
        public void create_and_save_test_collection_to_disk()
        {
            int numberOfCollectables        = 2;
            int numberOfItemsPerCollectable = 3;

            foreach (Type collectionType in CollectableBaseFactory.CollectableTypes)
            {
                // Initialize the collection
                string          collectionName = $"Test {collectionType.Name} Collection";
                ICollectionBase testCollection = GetTestCollection(collectionName, collectionType, numberOfCollectables, numberOfItemsPerCollectable);

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

                // Write file to disk
                string fullFilePath = Environment.CurrentDirectory + @"\";
                fullFilePath += collectionName + @"." + HomeCollectionRepository.FILE_EXTENSION;
                try
                {
                    repo.SaveCollection(fullFilePath, true);
                    Assert.IsTrue(true);
                }
                catch (Exception ex)
                {
                    Assert.Fail($"Should not have failed to write test collection file to disk: {collectionType.Name}", ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        public void savecollection_calls_writefile_with_overwrite_flag_set()
        {
            Mock <ICollectionBase>    mockCollection = new Mock <ICollectionBase>();
            IHomeCollectionRepository repo           = new HomeCollectionRepository(mockCollection.Object, _mockFileIO.Object);

            string path      = "filepath";
            string filename  = "filename";
            bool   overwrite = false;

            repo.SaveCollection(path, filename, overwrite);

            _mockFileIO.Verify(r => r.WriteFile(It.IsAny <string>(), It.IsAny <string>(), overwrite), Times.Once);
        }
Ejemplo n.º 3
0
        public void savecollection_fails_when_collection_is_null()
        {
            // initalize repository without a collection
            IHomeCollectionRepository repo = new HomeCollectionRepository(_mockFileIO.Object);
            string fullFilePath            = "fullfilepath";

            try
            {
                repo.SaveCollection(fullFilePath, false);
                Assert.Fail("Expected save to fail when the collection is null");
            }
            catch (CollectionException)
            {
                Assert.IsTrue(true);
            }
        }
Ejemplo n.º 4
0
        public void savecollection_calls_writefile_with_fullpath_set()
        {
            Mock <ICollectionBase>    mockCollection = new Mock <ICollectionBase>();
            IHomeCollectionRepository repo           = new HomeCollectionRepository(mockCollection.Object, _mockFileIO.Object);

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

            string path         = "filepath";
            string filename     = "filename";
            string fullFilePath = FileIO.GetFullFilePathString(path, filename);
            bool   overwrite    = false;

            repo.SaveCollection(path, filename, overwrite);

            _mockFileIO.Verify(r => r.WriteFile(fullFilePath, It.IsAny <string>(), It.IsAny <bool>()), Times.Once);
        }
Ejemplo n.º 5
0
        public void savecollection_fails_when_filename_is_blank()
        {
            Mock <ICollectionBase>    mockCollection = new Mock <ICollectionBase>();
            IHomeCollectionRepository repo           = new HomeCollectionRepository(mockCollection.Object, _mockFileIO.Object);

            string path     = "filepath";
            string filename = "";

            try
            {
                repo.SaveCollection(path, filename, false);
                Assert.Fail("Expected save to fail when the filename is blank");
            }
            catch (CollectionException)
            {
                Assert.IsTrue(true);
            }
        }