public void Convert_v0_1_0alpha3Nulls_ConvertsProperly()
        {
            Models.v0_1_0alpha3.Metadata input =
                new Models.v0_1_0alpha3.Metadata();
            input.File.CreationDate = "2020-01-01";

            var sut = new MetadataConverter();

            var actual = sut.Convert(input);

            Assert.IsType <Models.v0_2.Metadata>(actual);
        }
Ejemplo n.º 2
0
        public Models.v0_2.Metadata Convert(
            Models.v0_1_0alpha3.Metadata metadata)
        {
            Models.v0_2.Metadata result =
                new Models.v0_2.Metadata
            {
                CreationDate = DateTime.Parse(
                    metadata.File.CreationDate),
                ModifiedDate = DateTime.UtcNow
            };

            Models.v0_2.Dataset d;
            if (metadata.Dataset != null)
            {
                d = new Models.v0_2.Dataset()
                {
                    Zone               = metadata.Dataset.Zone.ToString(),
                    Project            = metadata.Dataset.Project,
                    Name               = metadata.Dataset.Name,
                    Description        = metadata.Dataset.Description,
                    Format             = metadata.Dataset.Format,
                    FilePathTemplate   = metadata.Dataset.FilePathTemplate,
                    FilePathDescriptor = metadata.Dataset.FilePathDescriptor,
                    Structure          = metadata.Dataset.Structure,
                    Tags               = metadata.Dataset.Tags,
                    Contacts           = ConvertContacts(metadata.Dataset.Contacts),
                    Geometry           = metadata.Dataset.Geometry,
                    Methods            = metadata.Dataset.Methods,
                    TemporalResolution = metadata.Dataset.TemporalResolution,
                    TemporalExtent     =
                        $"{metadata.Dataset.StartDate}/{metadata.Dataset.EndDate}",
                    SpatialRepeats = metadata.Dataset.SpatialRepeats,
                    Variables      = ConvertVariables(metadata.Dataset.Variables)
                };
            }
            else
            {
                d = new Models.v0_2.Dataset();
            }


            result.Dataset = d;


            return(result);
        }
Ejemplo n.º 3
0
        private Models.v0_1.Metadata Deserialize_v0_1_0alpha3(
            string json)
        {
            JsonSerializerOptions options = new JsonSerializerOptions()
            {
                IgnoreNullValues = true,
                WriteIndented    = true,
                Converters       = { new JsonStringEnumConverter() },
                Encoder          = System.Text.Encodings.Web
                                   .JavaScriptEncoder
                                   .UnsafeRelaxedJsonEscaping
            };

            Models.v0_1_0alpha3.Metadata m =
                JsonSerializer.Deserialize <Models.v0_1_0alpha3.Metadata>(
                    json, options);
            Models.v0_1.Metadata result =
                converter.Convert(m);

            return(result);
        }
        public void Convert_v0_1_0alpha3WithVals_ConvertsProperly()
        {
            var           creationDate = "2020-12-20";
            var           contactName  = "TestUser";
            var           startDate    = "1999-20-01";
            var           tempExtent   = $"{startDate}/{startDate}";
            List <string> expectedQC   = new List <string>()
            {
                "Assurance",
                "Point",
                "Review"
            };

            Models.v0_1_0alpha3.Metadata input =
                new Models.v0_1_0alpha3.Metadata()
            {
                File = new Models.v0_1_0alpha3.File()
                {
                    CreationDate = creationDate
                },
                Dataset = new Models.v0_1_0alpha3.Dataset()
                {
                    Zone        = Models.v0_1_0alpha3.Zones.Production,
                    Project     = "UnitTest",
                    Name        = "Convert_v0_1_0alpha3WithVals_ConvertsProperly",
                    Description = "Pleh",
                    Format      = "geotiff",
                    Contacts    = new List <Models.v0_1_0alpha3.Person>()
                    {
                        new Models.v0_1_0alpha3.Person()
                        {
                            Name  = contactName,
                            Email = "*****@*****.**",
                            Role  = "Tool"
                        }
                    },
                    StartDate = startDate,
                    EndDate   = startDate,
                    Variables = new List <Models.v0_1_0alpha3.Variable>()
                    {
                        new Models.v0_1_0alpha3.Variable()
                        {
                            Name            = "value",
                            IsQCSpecified   = false,
                            ProcessingLevel = Models.v0_1_0alpha3.ProcessingLevels.Calculated
                        },
                        new Models.v0_1_0alpha3.Variable()
                        {
                            Name          = "value2",
                            IsQCSpecified = true,
                            QCApplied     = new Models.v0_1_0alpha3.QCApplied()
                            {
                                Assurance = true,
                                Point     = true,
                                Review    = true
                            },
                            StartDate = startDate,
                            EndDate   = startDate
                        }
                    }
                }
            };

            var sut = new MetadataConverter();

            Models.v0_2.Metadata actual = sut.Convert(input);

            Assert.Equal(creationDate, actual.CreationDate.ToString());
            Assert.Equal(contactName, actual.Dataset.Contacts[0].Name);
            Assert.Equal(tempExtent, actual.Dataset.TemporalExtent);
            Assert.False(actual.Dataset.Variables[0].IsQCSpecified);
            Assert.Equal("Calculated", actual.Dataset.Variables[0].ProcessingLevel);
            Assert.Equal(expectedQC, actual.Dataset.Variables[1].QCApplied);
            Assert.Equal(tempExtent, actual.Dataset.Variables[1].TemporalExtent);
        }