Ejemplo n.º 1
0
        public void GetByName_DatabaseFileIsCorrupted_ThrowsDbRepositoryException()
        {
            // Arrange
            string dbName = "testDatabase";

            File.WriteAllText(this.GetDbFilePath(dbName), "some text");

            // Arrange - create target
            IDbRepository target = new DbRepository(this._dbRepositorySettings);

            // Act and Assert
            DbRepositoryException ex = Assert.Throws <DbRepositoryException>(() => target.GetByName(dbName));

            Assert.IsNotNull(ex.InnerException);
            Assert.IsInstanceOf(typeof(JsonException), ex.InnerException);
        }
Ejemplo n.º 2
0
        public void GetDatabaseNames_DbRepositoryThrowsDbRepositoryException_ThrowsDbServiceException()
        {
            // Arrange
            DbRepositoryException innerException = new DbRepositoryException();

            // Arrange - mock dbRepository
            this._dbRepositoryMock.Setup(r => r.GetAllNames())
            .Throws(innerException);

            // Arrange - create target
            IDatabaseService target = new DatabaseService(this._dbRepositoryMock.Object, this._dbValidationMock.Object);

            // Act and Assert
            DbServiceException ex = Assert.Throws <DbServiceException>(() => target.GetDatabaseNames());

            Assert.AreSame(innerException, ex.InnerException);
        }
Ejemplo n.º 3
0
        public void DropDatabase_DbRepositoryThrowsDbRepositoryException_ThrowsDbServiceException()
        {
            // Arrange
            string dbName = this._testDb.Name;
            DbRepositoryException innerException = new DbRepositoryException();

            // Arrange - mock dbRepository
            this._dbRepositoryMock.Setup(r => r.Delete(dbName))
            .Throws(innerException);

            // Arrange - create target
            IDatabaseService target = new DatabaseService(this._dbRepositoryMock.Object, this._dbValidationMock.Object);

            // Act and Assert
            DbServiceException ex = Assert.Throws <DbServiceException>(() => target.DropDatabase(dbName));

            Assert.AreSame(innerException, ex.InnerException);
        }
Ejemplo n.º 4
0
        public void GetTable_DbRepositoryThrowsDbRepositoryException_ThrowsDbServiceException()
        {
            // Arrange
            string dbName    = "testDatabase";
            string tableName = "testTable";

            DbRepositoryException innerException = new DbRepositoryException();

            // Arrange - mock dbRepository
            this._dbRepositoryMock.Setup(r => r.GetByName(dbName))
            .Throws(innerException);

            // Arrange - create target
            IDatabaseService target = new DatabaseService(this._dbRepositoryMock.Object, this._dbValidationMock.Object);

            // Act and Assert
            DbServiceException ex = Assert.Throws <DbServiceException>(() => target.GetTable(dbName, tableName));

            Assert.AreSame(innerException, ex.InnerException);
        }
Ejemplo n.º 5
0
        public void CreateTable_DbRepositoryThrowsDbRepositoryException_ThrowsDbServiceException()
        {
            // Arrange
            string      dbName      = this._testDb.Name;
            TableScheme tableScheme = new TableScheme("testTable", new List <Models.Attribute>());

            DbRepositoryException innerException = new DbRepositoryException();

            // Arrange - mock dbRepository
            this._dbRepositoryMock.Setup(r => r.Update(It.IsAny <Database>()))
            .Throws(innerException);

            // Arrange - create target
            IDatabaseService target = new DatabaseService(this._dbRepositoryMock.Object, this._dbValidationMock.Object);

            // Act and Assert
            DbServiceException ex = Assert.Throws <DbServiceException>(() => target.CreateTable(dbName, tableScheme));

            Assert.AreSame(innerException, ex.InnerException);
        }
Ejemplo n.º 6
0
        public void CreateDatabase_DbRepositoryThrowsDbRepositoryException_ThrowsDbServiceException()
        {
            // Arrange
            Database database = new Database {
                Name = "testDatabase"
            };
            DbRepositoryException innerException = new DbRepositoryException();

            // Arrange - mock dbRepository
            this._dbRepositoryMock.Setup(r => r.Create(database))
            .Throws(innerException);

            // Arrange - create target
            IDatabaseService target = new DatabaseService(this._dbRepositoryMock.Object, this._dbValidationMock.Object);

            // Act and Assert
            DbServiceException ex = Assert.Throws <DbServiceException>(() => target.CreateDatabase(database.Name));

            Assert.AreSame(innerException, ex.InnerException);
        }