Beispiel #1
0
        public void doi_with_valid_formats([Values(null, "", "12.3456/ABC123", "12.3456789/ABC123", "00.1234/long.string+which-is:still_valid/123")] string doi)
        {
            var record = SimpleRecord().With(r => r.DigitalObjectIdentifier = doi).With(r => r.Citation = "Record has a citation");
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Should().BeEmpty();
        }
Beispiel #2
0
        public void topic_category_may_be_blank([Values("", null)] string blank)
        {
            var record = SimpleRecord().With(r => r.Gemini.TopicCategory = blank);
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Should().BeEmpty();
        }
Beispiel #3
0
        public List <RecordError> Validate(List <string> content)
        {
            List <RecordError> list = new List <RecordError>();

            foreach (string record in content)
            {
                try
                {
                    if (record.Length < 95 || record.Length > 95)
                    {
                        RecordError model = new RecordError();
                        model.Error = "Tamanho do registro inválido.";
                        model.Line  = content.IndexOf(record);
                        model.Field = "Linha";
                        list.Add(model);
                    }

                    RecordConverter recordConverter = new RecordConverter();
                    InvoiceData     separeteContent = recordConverter.ToInvoiceData(record);

                    RecordValidator recordValidator = new RecordValidator();
                    recordValidator.Validate(separeteContent, content.IndexOf(record));
                }
                catch (Exception.RecordValidatorException ex)
                {
                    list.AddRange(ex.Model);
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(list);
        }
        public void blank_lineage_is_not_allowed([Values("", " ", null)] string blank)
        {
            var record = GeminiRecord().With(r => r.Gemini.Lineage = blank);
            var result = new RecordValidator().Validate(record);

            result.Errors.Any(e => e.Fields.Contains("gemini.lineage")).Should().BeTrue();
        }
        public void blank_use_constraints_are_not_allowed([Values("", " ", null)] string blank)
        {
            var record = GeminiRecord().With(r => r.Gemini.UseConstraints = blank);
            var result = new RecordValidator().Validate(record);

            result.Errors.Any(e => e.Fields.Contains("gemini.useConstraints")).Should().BeTrue();
        }
 public RecordService(IRecordRepository recordRepository, LogAppContext logAppContext, IHubContext <NotifyHub, IMesageHubClient> hubContext)
 {
     _recordRepository = recordRepository;
     _context          = logAppContext;
     _recordsValidator = new RecordValidator();
     _hubContext       = hubContext;
 }
        public void topic_category_must_not_be_blank([Values("", " ", null)] string blank)
        {
            var record = GeminiRecord().With(r => r.Gemini.TopicCategory = blank);
            var result = new RecordValidator().Validate(record);

            result.Errors.Any(e => e.Fields.Contains("gemini.topicCategory")).Should().BeTrue();
        }
Beispiel #8
0
 public void should_validate_valid_dates()
 {
     RecordValidator.IsValidDate("2017").Should().BeTrue();
     RecordValidator.IsValidDate("2017-01").Should().BeTrue();
     RecordValidator.IsValidDate("2017-01-01").Should().BeTrue();
     RecordValidator.IsValidDate("2012-02-29").Should().BeTrue(); //leap year
 }
        public void should_validate_valid_gemini_record()
        {
            var record = GeminiRecord();

            var result = new RecordValidator().Validate(record);

            result.Errors.Count.Should().Be(0);
        }
Beispiel #10
0
        public void topic_category_must_be_valid()
        {
            var record = SimpleRecord().With(r => r.Gemini.TopicCategory = "anInvalidTopicCategory");
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Single().Message.Should().Contain("Topic Category 'anInvalidTopicCategory' is not valid");
            result.Errors.Single().Fields.Single().Should().Be("gemini.topicCategory");
        }
Beispiel #11
0
        public void jncc_keywords_must_be_provided()
        {
            // should not validate on empty list
            var r1 =
                new RecordValidator(vocabQueryer).Validate(SimpleRecord().With(r => r.Gemini.Keywords = new List <MetadataKeyword>()));

            r1.Errors.First().Message.Should().StartWith("Must specify a JNCC Domain");
        }
Beispiel #12
0
        public void doi_with_invalid_formats([Values(" ", "a bad doi", "baddoi", "104124/ABC-123", "10./ABC-123", "10.4124/ABC-123?", "AB.1234/ABC-123")] string doi)
        {
            var record = SimpleRecord().With(r => r.DigitalObjectIdentifier = doi).With(r => r.Citation = "Record has a citation");
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Single().Message.Should().Contain("Digital Object Identifier is not in a valid format");
            result.Errors.Single().Fields.Single().Should().Be("digitalObjectIdentifier");
        }
Beispiel #13
0
        public void title_must_not_be_longer_then_200([Values("", " ", null)] string blank)
        {
            var result =
                new RecordValidator(vocabQueryer).Validate(SimpleRecord().With(r => r.Gemini.Title = new String('x', 201)));

            result.Errors.Single().Message.Should().StartWith("Title is too long. 200 characters or less, please");
            result.Errors.Single().Fields.Single().Should().Be("gemini.title");
        }
Beispiel #14
0
        public void title_must_not_be_blank([Values("", " ", null)] string blank)
        {
            var result =
                new RecordValidator(vocabQueryer).Validate(SimpleRecord().With(r => r.Gemini.Title = blank));

            result.Errors.Single().Message.Should().StartWith("Title must not be blank");
            result.Errors.Single().Fields.Single().Should().Be("gemini.title");
        }
Beispiel #15
0
        public void resource_locator_must_be_a_well_formed_http_url(
            [Values(@"Z:\some\path", "utter rubbish")] string nonHttpUrl)
        {
            var record = SimpleRecord().With(r => r.Gemini.ResourceLocator = nonHttpUrl);
            var result = new RecordValidator().Validate(record);

            result.Errors.Single().Fields.Should().Contain("gemini.resourceLocator");
        }
Beispiel #16
0
        public void should_produce_no_warnings_by_default()
        {
            // the basic level of validation shouldn't produce warnings - that would be too annoying

            var result = new RecordValidator(vocabQueryer).Validate(SimpleRecord() /* no Level argument */);

            result.Warnings.Should().BeEmpty();
        }
Beispiel #17
0
        public void resource_locator_may_be_set(
            [Values(@"http://www.example.org/resource/locator", @"https://www.example.org/resource/locator")] string httpUrl)
        {
            var record = SimpleRecord().With(r => r.Gemini.ResourceLocator = httpUrl);
            var result = new RecordValidator().Validate(record);

            result.Errors.Should().BeEmpty();
        }
Beispiel #18
0
        public void doi_with_no_citation()
        {
            var record = SimpleRecord().With(r => r.DigitalObjectIdentifier = "12.3456789/ABC123");
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Single().Message.Should().Contain("Citation must be provided for DOI record");
            result.Errors.Single().Fields.Single().Should().Be("citation");
        }
Beispiel #19
0
        public void image_url_with_valid_formats([Values(null, "", "http://example.com/here/is/an/image.png", "https://example.com/here/is/another/image.jpeg")] string imageUrl)
        {
            var record = SimpleRecord().With(r => r.Image = new Image {
                Url = imageUrl
            });
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Should().BeEmpty();
        }
Beispiel #20
0
        public void mesh_gui_keywords_must_be_of_valid_form()
        {
            var record = SimpleRecord().With(r => r.Gemini.Keywords.Add(new MetadataKeyword {
                Vocab = "http://vocab.jncc.gov.uk/mesh-gui", Value = "blah"
            }));
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Single().Fields.Should().Contain("gemini.keywords");
        }
Beispiel #21
0
        public void image_url_with_invalid_formats([Values("a bad image url", "imageurl.png", "file://C:\\a\\file\\path.png", "C:\\a\\file\\path.png")] string imageUrl)
        {
            var record = SimpleRecord().With(r => r.Image = new Image {
                Url = imageUrl
            });
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Single().Message.Should().Contain("Must use a URL for images");
            result.Errors.Single().Fields.Single().Should().Be("image.url");
        }
        public void Validate_WhenDataIsNotValid_Error(string account, string description, string currencyCode, int?value, string expectedError)
        {
            // Arrange
            var v = RecordValidator.CreateInstance();

            // Act
            var result = v.Validate(account, description, currencyCode, value);

            // Assert
            Assert.AreEqual(expectedError, result[0]);
        }
Beispiel #23
0
        public void publication_title_must_not_be_longer_then_250([Values("", " ", null)] string blank)
        {
            var result =
                new RecordValidator().Validate(SimpleRecord().With(r => {
                r.Gemini.Title        = new String('x', 251);
                r.Gemini.ResourceType = "publication";
            }));

            result.Errors.Single().Message.Should().StartWith("Title is too long. 250 characters or less, please");
            result.Errors.Single().Fields.Single().Should().Be("gemini.title");
        }
Beispiel #24
0
        public void publication_title_can_be_longer_then_150([Values("", " ", null)] string blank)
        {
            var result =
                new RecordValidator(vocabQueryer).Validate(SimpleRecord().With(r =>
            {
                r.Gemini.Title        = new String('x', 155);
                r.Gemini.ResourceType = "publication";
            }));

            result.Errors.Count().Should().Be(0);
        }
Beispiel #25
0
        public void responsible_organisation_role_must_be_an_allowed_role()
        {
            var record = SimpleRecord().With(r => r.Gemini.ResponsibleOrganisation = new ResponsibleParty
            {
                Email = "*****@*****.**",
                Name  = "A. Mann",
                Role  = "some role that isn't allowed",
            });
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Single().Fields.Should().Contain("gemini.responsibleOrganisation.role");
        }
        public void responsible_organisation_role_must_not_be_blank()
        {
            var record = GeminiRecord().With(r => r.Gemini.ResponsibleOrganisation = new ResponsibleParty
            {
                Email = "*****@*****.**",
                Name  = "A. Mann",
                Role  = "",
            });
            var result = new RecordValidator().Validate(record);

            result.Errors.Single().Fields.Should().Contain("gemini.responsibleOrganisation.role");
        }
Beispiel #27
0
        public void metadata_point_of_contact_role_must_be_an_allowed_role()
        {
            var record = SimpleRecord().With(r => r.Gemini.MetadataPointOfContact = new ResponsibleParty
            {
                Email = "*****@*****.**",
                Name  = "A. Mann",
                Role  = "some role that isn't allowed",
            });
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Single().Fields.Should().Contain("gemini.metadataPointOfContact.role");
        }
Beispiel #28
0
        public void blank_bbox_for_datasets_is_not_allowed()
        {
            var record = GeminiRecord().With(r =>
            {
                r.Gemini.ResourceType = "dataset";
                r.Gemini.BoundingBox  = null;
            });
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Count.Should().Be(1);
            result.Errors.Any(e => e.Fields.Contains("gemini.boundingBox")).Should().BeTrue();
        }
Beispiel #29
0
        public void blank_temporal_extent_for_datasets_is_not_allowed()
        {
            var record = GeminiRecord().With(r =>
            {
                r.Gemini.ResourceType   = "dataset";
                r.Gemini.TemporalExtent = new TemporalExtent();
            });
            var result = new RecordValidator(vocabQueryer).Validate(record);

            result.Errors.Count.Should().Be(1);
            result.Errors.Any(e => e.Fields.Contains("gemini.temporalExtent.begin")).Should().BeTrue();
        }
Beispiel #30
0
        public void path_must_be_an_acceptable_kind([Values(
                                                         @"X:\some\path",
                                                         "PG:\"host=spatial-store dbname=spatial layer=SSSI_England_Units\"",
                                                         @"\\jncc-corpfile\jncc corporate data\my_dataset.xlsx",
                                                         @"http://www.example.com",
                                                         @"https://www.example.com"
                                                         //@"postgres://username@hostname/databasename"
                                                         )] string path)
        {
            var result = new RecordValidator(vocabQueryer).Validate(SimpleRecord().With(r => r.Path = path));

            result.Errors.Should().BeEmpty();
        }
        public HttpResponseMessage Put(Record record)
        {
            // Validate
            var instanceValidator = new RecordValidator(documentSession);
            var results = instanceValidator.Validate(record);
            if (!results.IsValid)
            {
                BadRequest(results);
            }

            // Store and return resource response
            var isCreate = record.IsTransient;
            if (BeforeSave(record, isCreate))
            {
                documentSession.Store(record, record.Etag);
            }

            var pathToResource = string.Format("instance/getbyid?id={0}", record.Id);
            var responseMessage = SaveChanges(record, pathToResource);

            AfterSave(record, isCreate);

            return responseMessage;
        }