Exemplo n.º 1
0
        public void ConstructorThrowsGVFSDatabaseException()
        {
            GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => this.TestGVFSDatabase(null, throwException: true));

            ex.Message.ShouldEqual("GVFSDatabase constructor threw exception setting up connection pool and initializing");
            ex.InnerException.Message.ShouldEqual("Error");
        }
Exemplo n.º 2
0
        private void TestSparseTableAddOrRemove(bool isAdd, string pathToPass, string expectedPath, bool throwException = false)
        {
            this.TestTable(
                (sparseTable, mockCommand) =>
            {
                Mock <IDbDataParameter> mockParameter       = new Mock <IDbDataParameter>(MockBehavior.Strict);
                mockParameter.SetupSet(x => x.ParameterName = "@path");
                mockParameter.SetupSet(x => x.DbType        = DbType.String);
                mockParameter.SetupSet(x => x.Value         = expectedPath);

                Mock <IDataParameterCollection> mockParameters = new Mock <IDataParameterCollection>(MockBehavior.Strict);
                mockParameters.Setup(x => x.Add(mockParameter.Object)).Returns(0);

                mockCommand.Setup(x => x.CreateParameter()).Returns(mockParameter.Object);
                mockCommand.SetupGet(x => x.Parameters).Returns(mockParameters.Object);
                if (throwException)
                {
                    mockCommand.Setup(x => x.ExecuteNonQuery()).Throws(new Exception(DefaultExceptionMessage));
                }
                else
                {
                    mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(1);
                }

                if (isAdd)
                {
                    mockCommand.SetupSet(x => x.CommandText = AddCommandString);
                    if (throwException)
                    {
                        GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => sparseTable.Add(pathToPass));
                        ex.Message.ShouldContain($"SparseTable.Add({expectedPath}) Exception");
                        ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
                    }
                    else
                    {
                        sparseTable.Add(pathToPass);
                    }
                }
                else
                {
                    mockCommand.SetupSet(x => x.CommandText = RemoveCommandString);
                    if (throwException)
                    {
                        GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => sparseTable.Remove(pathToPass));
                        ex.Message.ShouldContain($"SparseTable.Remove({expectedPath}) Exception");
                        ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
                    }
                    else
                    {
                        sparseTable.Remove(pathToPass);
                    }
                }

                mockParameters.VerifyAll();
                mockParameter.VerifyAll();
            });
        }
Exemplo n.º 3
0
        public void AddFileWithNullShaThrowsException()
        {
            GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => this.TestPlaceholdersInsert(
                                                                                 placeholders => placeholders.AddFile(DefaultPath, sha: null),
                                                                                 DefaultPath,
                                                                                 PathTypeFile,
                                                                                 sha: null,
                                                                                 throwException: true));

            ex.Message.ShouldEqual($"Invalid SHA 'null' for file {DefaultPath}");
        }
Exemplo n.º 4
0
        public void RemoveThrowsGVFSDatabaseException()
        {
            this.TestTable(
                (placeholders, mockCommand) =>
            {
                mockCommand.SetupSet(x => x.CommandText = "DELETE FROM Placeholder WHERE path = @path;").Throws(new Exception(DefaultExceptionMessage));

                GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => placeholders.Remove(DefaultPath));
                ex.Message.ShouldEqual($"PlaceholderTable.Remove({DefaultPath}) Exception");
                ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
            });
        }
Exemplo n.º 5
0
        public void AddPossibleTombstoneFolderThrowsGVFSDatabaseException()
        {
            GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => this.TestPlaceholdersInsert(
                                                                                 placeholders => placeholders.AddPossibleTombstoneFolder(DefaultPath),
                                                                                 DefaultPath,
                                                                                 PathTypePossibleTombstoneFolder,
                                                                                 sha: null,
                                                                                 throwException: true));

            ex.Message.ShouldEqual($"PlaceholderTable.Insert({DefaultPath}, {PlaceholderTable.PlaceholderData.PlaceholderType.PossibleTombstoneFolder}, ) Exception");
            ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
        }
Exemplo n.º 6
0
        public void AddFileThrowsGVFSDatabaseException()
        {
            GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => this.TestPlaceholdersInsert(
                                                                                 placeholders => placeholders.AddFile(DefaultPath, DefaultSha),
                                                                                 DefaultPath,
                                                                                 PathTypeFile,
                                                                                 DefaultSha,
                                                                                 throwException: true));

            ex.Message.ShouldEqual($"PlaceholderTable.Insert({DefaultPath}, {PlaceholderTable.PlaceholderData.PlaceholderType.File}, {DefaultSha}) Exception");
            ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
        }
Exemplo n.º 7
0
        public void AddFileWithInvalidLengthShaThrowsException()
        {
            string badSha            = "BAD SHA";
            GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => this.TestPlaceholdersInsert(
                                                                                 placeholders => placeholders.AddFile(DefaultPath, badSha),
                                                                                 DefaultPath,
                                                                                 PathTypeFile,
                                                                                 badSha,
                                                                                 throwException: true));

            ex.Message.ShouldEqual($"Invalid SHA '{badSha}' for file {DefaultPath}");
        }
Exemplo n.º 8
0
 public void GetCountThrowsGVFSDatabaseException()
 {
     this.TestTable(
         (placeholders, mockCommand) =>
     {
         mockCommand.SetupSet(x => x.CommandText = "SELECT count(path) FROM Placeholder;");
         mockCommand.Setup(x => x.ExecuteScalar()).Throws(new Exception(DefaultExceptionMessage));
         GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => placeholders.GetCount());
         ex.Message.ShouldEqual("PlaceholderTable.GetCount Exception");
         ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
     });
 }
Exemplo n.º 9
0
        public void AddFileWithEmptyShaThrowsException()
        {
            string emptySha          = string.Empty;
            GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => this.TestPlaceholdersInsert(
                                                                                 placeholders => placeholders.AddFile(DefaultPath, emptySha),
                                                                                 DefaultPath,
                                                                                 PathTypeFile,
                                                                                 emptySha,
                                                                                 throwException: true));

            ex.Message.ShouldEqual($"Invalid SHA '' for file {DefaultPath}");
        }
Exemplo n.º 10
0
 public void GetAllThrowsGVFSDatabaseException()
 {
     this.TestTableWithReader(
         (sparseTable, mockCommand, mockReader) =>
     {
         mockCommand.SetupSet(x => x.CommandText = GetAllCommandString);
         mockReader.Setup(x => x.Read()).Throws(new Exception(DefaultExceptionMessage));
         GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => sparseTable.GetAll());
         ex.Message.ShouldContain("SparseTable.GetAll Exception:");
         ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
     });
 }
Exemplo n.º 11
0
        public void RemoveAllEntriesForFolderThrowsGVFSDatabaseException()
        {
            this.TestTable(
                (placeholders, mockCommand) =>
            {
                mockCommand.SetupSet(x => x.CommandText = "SELECT path, pathType, sha FROM Placeholder WHERE path = @path OR path LIKE @pathWithDirectorySeparator;").Throws(new Exception(DefaultExceptionMessage));

                GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => placeholders.RemoveAllEntriesForFolder(DefaultPath));
                ex.Message.ShouldEqual($"PlaceholderTable.RemoveAllEntriesForFolder({DefaultPath}) Exception");
                ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
            });
        }
Exemplo n.º 12
0
        public void GetAllFilePathsThrowsGVFSDatabaseException()
        {
            this.TestTableWithReader(
                (placeholders, mockCommand, mockReader) =>
            {
                mockReader.Setup(x => x.Read()).Throws(new Exception(DefaultExceptionMessage));
                mockCommand.SetupSet(x => x.CommandText = "SELECT path FROM Placeholder WHERE pathType = 0;");

                GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => placeholders.GetAllFilePaths());
                ex.Message.ShouldEqual("PlaceholderTable.GetAllFilePaths Exception");
                ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
            });
        }
Exemplo n.º 13
0
        public void GetAllEntriesThrowsGVFSDatabaseException()
        {
            List <PlaceholderTable.PlaceholderData> expectedPlacholders = new List <PlaceholderTable.PlaceholderData>();

            this.TestTableWithReader(
                (placeholders, mockCommand, mockReader) =>
            {
                mockCommand.SetupSet(x => x.CommandText = "SELECT path, pathType, sha FROM Placeholder;");
                mockReader.Setup(x => x.Read()).Throws(new Exception(DefaultExceptionMessage));

                GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => placeholders.GetAllEntries(out List <IPlaceholderData> filePlaceholders, out List <IPlaceholderData> folderPlaceholders));
                ex.Message.ShouldEqual("PlaceholderTable.GetAllEntries Exception");
                ex.InnerException.Message.ShouldEqual(DefaultExceptionMessage);
            });
        }
Exemplo n.º 14
0
        public void AddFilePlaceholderDataWithNullShaThrowsException()
        {
            PlaceholderTable.PlaceholderData placeholderData = new PlaceholderTable.PlaceholderData()
            {
                Path     = DefaultPath,
                PathType = PlaceholderTable.PlaceholderData.PlaceholderType.File,
                Sha      = null
            };

            GVFSDatabaseException ex = Assert.Throws <GVFSDatabaseException>(() => this.TestPlaceholdersInsert(
                                                                                 placeholders => placeholders.AddPlaceholderData(placeholderData),
                                                                                 DefaultPath,
                                                                                 PathTypeFile,
                                                                                 sha: null,
                                                                                 throwException: true));

            ex.Message.ShouldEqual($"Invalid SHA 'null' for file {DefaultPath}");
        }