public void Validate_GivenInvalidModelWithCsvFile_ValidIsFalse()
        {
            //Arrange
            CreateNewDatasetModel model = CreateModel();

            model.Filename = "filename.csv";

            CreateNewDatasetModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should().Be(1);

            result
            .Errors[0]
            .ErrorMessage
            .Should().Contain("Check you have the right file format");
        }
        public void Validate_GivenNameAlreadyExists_ValidIsFalse()
        {
            //Arrange
            CreateNewDatasetModel model = CreateModel();

            IEnumerable <Dataset> datasets = new[]
            {
                new Dataset()
            };

            IDatasetRepository repository = CreateDatasetsRepository(true, true);

            repository
            .GetDatasetsByQuery(Arg.Any <Expression <Func <DocumentEntity <Dataset>, bool> > >())
            .Returns(datasets);

            CreateNewDatasetModelValidator validator = CreateValidator(repository);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);
        }
        public void Validate_GivenvalidModelWithXlsxFile_ValidIsTrue()
        {
            //Arrange
            CreateNewDatasetModel model = CreateModel();

            model.Filename = "filename.XLSX";

            CreateNewDatasetModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeTrue();
        }
        public void Validate_GivenDefinitionNotFoundForFundingStreamId_ValidIsFalse()
        {
            //Arrange
            CreateNewDatasetModel model = CreateModel();

            IDatasetRepository             datasetRepository = CreateDatasetsRepository(false, false);
            CreateNewDatasetModelValidator validator         = CreateValidator(datasetRepository);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);
        }
        public void Validate_GivenEmptyFundingStreamId_ValidIsFalse()
        {
            //Arrange
            CreateNewDatasetModel model = CreateModel();

            model.FundingStreamId = string.Empty;

            CreateNewDatasetModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);
        }
        public void Validate_GivenFilenameWithIncorrectExtension_ValidIsFalse()
        {
            //Arrange
            CreateNewDatasetModel model = CreateModel();

            model.Filename = "Filename.docx";

            CreateNewDatasetModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);
        }
        public void Validate_GivenInvalidFundingStreamId_ValidIsFalse()
        {
            //Arrange
            CreateNewDatasetModel model = CreateModel();

            model.FundingStreamId = "test-invalid-funding-stream-id";

            CreateNewDatasetModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(2);
        }