Exemplo n.º 1
0
        public void CheckTableScheme_TableSchemeHasAttributeWithNotUniqueName_ThrowsInvalidTableAttributesException()
        {
            // Arrange
            string attributeName = "someAttribute";
            string attributeType = this._dbValidationSettings.DataTypes.Keys.First();

            TableScheme tableScheme = new TableScheme("testTable",
                                                      new List <Models.Attribute>
            {
                new Models.Attribute {
                    Name = attributeName, Type = attributeType
                },
                new Models.Attribute {
                    Name = attributeName, Type = attributeType
                }
            });

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            InvalidTableAttributesException ex =
                Assert.Throws <InvalidTableAttributesException>(() => target.CheckTableScheme(tableScheme));

            Assert.NotNull(ex.InnerException);
            Assert.AreSame(ex.InnerException.GetType(), typeof(InvalidAttributeException));
        }
Exemplo n.º 2
0
        public void CheckTableScheme_TableSchemeHasAttributeWithUnknownType_ThrowsInvalidAttributeException()
        {
            // Arrange
            string tableName     = "testTable";
            string attributeName = "testAttribute";

            string[] attributeTypes = { null, "testType" };

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            foreach (string attributeType in attributeTypes)
            {
                Models.Attribute attribute = new Models.Attribute {
                    Name = attributeName, Type = attributeType
                };

                TableScheme tableScheme = new TableScheme(tableName, new List <Models.Attribute> {
                    attribute
                });

                InvalidTableAttributesException ex =
                    Assert.Throws <InvalidTableAttributesException>(() => target.CheckTableScheme(tableScheme));

                Assert.NotNull(ex.InnerException);
                Assert.AreSame(ex.InnerException.GetType(), typeof(InvalidAttributeException));
            }
        }
Exemplo n.º 3
0
        public void DoesRowFitTable_RowFitsTable_ReturnsTrue()
        {
            // Arrange
            Table table = new Table
            {
                Name       = "testTable",
                Attributes =
                    new List <Models.Attribute>
                {
                    new Models.Attribute
                    {
                        Name = "testAttribute", Type = this._dbValidationSettings.DataTypes.Keys.First()
                    }
                }
            };
            Row row = new Row {
                Value = new List <string> {
                    "1"
                }
            };

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            Assert.IsTrue(target.DoesRowFitTable(table, row));

            this._dataTypeMock.Verify(r => r.IsValidValue(row.Value.First()), Times.Once);
        }
Exemplo n.º 4
0
        public void DoesRowFitTable_RowDoesNotFitTableSize_ReturnsFalse()
        {
            // Arrange
            Table table = new Table
            {
                Name       = "testTable",
                Attributes =
                    new List <Models.Attribute>
                {
                    new Models.Attribute
                    {
                        Name = "testAttribute", Type = this._dbValidationSettings.DataTypes.Keys.First()
                    }
                }
            };
            List <Row> rows = new List <Row>
            {
                new Row {
                    Value = new List <string> {
                        "1", "2"
                    }
                }, new Row {
                    Value = new List <string>()
                }
            };

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            foreach (Row row in rows)
            {
                Assert.IsFalse(target.DoesRowFitTable(table, row));
            }
        }
Exemplo n.º 5
0
        public void CheckTableScheme_TableSchemeIsNull_ThrowsArgumentNullException()
        {
            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => target.CheckTableScheme(null));
        }
Exemplo n.º 6
0
        public void IsValidDatabaseName_DatabaseNameIsValid_ReturnsTrue()
        {
            // Arrange
            string dbName = "testDatabase";

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            Assert.IsTrue(target.IsValidDatabaseName(dbName));
        }
Exemplo n.º 7
0
        public void CheckTableScheme_TableSchemeHasNoAttributes_ThrowsInvalidTableAttributesException()
        {
            // Arrange
            TableScheme tableScheme = new TableScheme("testTable", new List <Models.Attribute>());

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            Assert.Throws <InvalidTableAttributesException>(() => target.CheckTableScheme(tableScheme));
        }
Exemplo n.º 8
0
        public void DoesRowFitTable_ArgumentsAreNull_ThrowsArgumentNullException()
        {
            // Arrange
            Table table = new Table();
            Row   row   = new Row();

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => target.DoesRowFitTable(null, row));
            Assert.Throws <ArgumentNullException>(() => target.DoesRowFitTable(table, null));
        }
Exemplo n.º 9
0
        public void IsValidDatabaseName_DatabaseNameIsInvalid_ReturnsFalse()
        {
            // Arrange
            string[] dbNames = { null, "", " ", new string(Path.GetInvalidFileNameChars()) };

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            foreach (string dbName  in dbNames)
            {
                Assert.IsFalse(target.IsValidDatabaseName(dbName));
            }
        }
Exemplo n.º 10
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.Guid == null)
            {
                Properties.Settings.Default.Guid = Guid.NewGuid().ToString();
                DatabaseOperations.AddNewUserGuid(Properties.Settings.Default.Guid);
            }
            else
            {
                _isSaveNeeded = DatabaseValidation.CheckUserGuid(Properties.Settings.Default.Guid);
                downloadHistoryDGV.DataSource = DatabaseOperations.FillDataGridView(Properties.Settings.Default.Guid);
            }

            MessageBox.Show(Properties.Settings.Default.Guid);
        }
Exemplo n.º 11
0
        public void CheckTableScheme_TableSchemeIsValid_DoesNotThrowAnyException()
        {
            // Arrange
            TableScheme tableScheme = new TableScheme("testTable",
                                                      new List <Models.Attribute>
            {
                new Models.Attribute {
                    Name = "testAttribute", Type = this._dbValidationSettings.DataTypes.Keys.First()
                }
            });

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            Assert.DoesNotThrow(() => target.CheckTableScheme(tableScheme));
        }
Exemplo n.º 12
0
        public void CheckTableScheme_TableSchemeHasInvalidName_ThrowsInvalidTableNameException()
        {
            // Arrange
            string[]           tableNames = { "", " ", new string(Path.GetInvalidFileNameChars()) };
            Models.Attribute[] attributes =
            {
                new Models.Attribute {
                    Name = "testAttribute", Type = this._dbValidationSettings.DataTypes.Keys.First()
                }
            };

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            foreach (string tableName in tableNames)
            {
                TableScheme tableScheme = new TableScheme(tableName, attributes);

                Assert.Throws <InvalidTableNameException>(() => target.CheckTableScheme(tableScheme));
            }
        }
        protected override bool Run(object parameters)
        {
            try
            {
                DatabaseConnection connection = (DatabaseConnection)parameters;

                DatabaseObjects dbObjects = DatabaseValidation.Validate(connection.MasterDatabase, connection.ChildDatabase, false, true);

                foreach (DatabaseObject dbObject in dbObjects)
                {
                    if (ValidationError != null)
                    {
                        if (dbObject.ObjectParameter1 == "REPLICATE$HASH")
                        {
                            continue;
                        }

                        ValidationError(this, new SchemaValidationArgs(dbObject.ObjectType.ToString(),
                                                                       dbObject.ObjectName, dbObject.ObjectParameter1, dbObject.Status.ToString(),
                                                                       dbObject.SQL, dbObject.ExistsWithDifferentName));
                    }
                }
            }
            catch
            {
                return(false);
            }
            finally
            {
                if (ValidationComplete != null)
                {
                    ValidationComplete(this, EventArgs.Empty);
                }
            }

            return(false);
        }
Exemplo n.º 14
0
        public void DoesRowFitTable_RowHasInvalidValue_ReturnsFalse()
        {
            // Arrange
            string typeName = "testType";

            Table table = new Table
            {
                Name       = "testTable",
                Attributes = new List <Models.Attribute> {
                    new Models.Attribute {
                        Name = "testAttribute", Type = typeName
                    }
                }
            };
            Row row = new Row {
                Value = new List <string> {
                    "1234sometext"
                }
            };

            // Arrange - mock dataType
            this._dataTypeMock.Setup(t => t.IsValidValue(row.Value.First()))
            .Returns(false);

            DatabaseValidationSettings dbValidationSettings =
                new DatabaseValidationSettings(dataTypes:
                                               new Dictionary <string, IDataType> {
                { typeName, this._dataTypeMock.Object }
            });

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(dbValidationSettings);

            // Act and Assert
            Assert.IsFalse(target.DoesRowFitTable(table, row));
        }
 public override void CancelThread(int timeout = 10000, bool isUnResponsive = false)
 {
     DatabaseValidation.Cancel();
     base.CancelThread(timeout, isUnResponsive);
 }