private static IProgramMetadata CreateXmlRomInformationMetadata() { var builder = new ProgramMetadataBuilder(); builder.WithLongNames(new[] { XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.title] }); builder.WithShortNames(new[] { XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.short_name] }); builder.WithPublishers(new[] { XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.vendor] }); builder.WithVersions(new[] { XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.name] }); builder.WithDescriptions(new[] { XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.description] }); builder.WithProgrammers(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.program].Split(new[] { '|' })); builder.WithDesigners(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.concept].Split(new[] { '|' })); builder.WithGraphics(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.game_graphics].Split(new[] { '|' })); builder.WithMusic(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.music].Split(new[] { '|' })); builder.WithSoundEffects(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.soundfx].Split(new[] { '|' })); builder.WithVoices(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.voices].Split(new[] { '|' })); builder.WithDocumentation(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.game_docs].Split(new[] { '|' })); builder.WithArtwork(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.box_art].Split(new[] { '|' })); builder.WithReleaseDates(new[] { new MetadataDateTimeBuilder(1998).WithMonth(6).WithDay(12).Build() }); builder.WithLicenses(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.license].Split(new[] { '|' })); builder.WithContactInformation(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.contact_info].Split(new[] { '|' })); builder.WithAdditionalInformation(new List <string>(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.source].Split(new[] { '|' })).Concat(XmlRomInformationColumnValues[XmlRomInformationDatabaseColumnName.other].Split(new[] { '|' }))); builder.WithBuildDates(new[] { new MetadataDateTimeBuilder(2012).WithMonth(12).WithDay(12).Build() }); return(builder.Build()); }
public void XmlRomInformationToProgramRomInformationConverter_CreateDefaultAndConvertXmlInfoWithMultipleCorruptions_ProducesValidConversion() { var converter = XmlRomInformationToProgramRomInformationConverter.Create(); var columnsToCorrupt = new[] { XmlRomInformationDatabaseColumnName.vendor, XmlRomInformationDatabaseColumnName.short_name, XmlRomInformationDatabaseColumnName.release_date, XmlRomInformationDatabaseColumnName.soundfx, XmlRomInformationDatabaseColumnName.game_docs }; var xmlRomInformation = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated, columnsToCorrupt); xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.build_date).Value = "2020"; // corrupted because it's not YYYY-MM-DD var convertedInformation = converter.Convert(xmlRomInformation); var builder = new ProgramMetadataBuilder().WithInitialMetadata(XmlProgramMetadata.Value); builder.WithPublishers(null).WithShortNames(null).WithReleaseDates(null).WithSoundEffects(null).WithDocumentation(null).WithBuildDates(null); var expectedMetadata = builder.Build(); var expectedProgramInformation = new TestProgramInformation(XmlProgramInformation) { Vendor = null, ShortName = null, Year = null }; var expectedProgramDescription = new TestProgramDescription(XmlProgramDescription) { Vendor = null, ShortName = null, Year = null }; ValidateInformation(expectedProgramInformation, convertedInformation); ValidateDescription(expectedProgramDescription, convertedInformation); ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features); ValidateMetadata(expectedMetadata, convertedInformation.Metadata); }
public void ProgramRomInformationBuilder_BuildWithMetadata_ResultsInExpectedMetadata() { var builder = CreateBuilderWithRequiredFields("Testing Metadata"); var expectedMetadata = new ProgramMetadataBuilder().WithDescriptions(new[] { "Itza kool game" }).Build(); var programRomInformation = builder.WithMetadata(expectedMetadata).Build(); Assert.Equal(expectedMetadata, programRomInformation.Metadata); }
public void XmlRomInformationToProgramRomInformationConverter_CreateDefaultAndConvertXmlInfoWithStringMetadataCorruption_ProducesValidConversion() { var converter = XmlRomInformationToProgramRomInformationConverter.Create(); var xmlRomInformation = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated); xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.program).Value = "| |\n|\t|\r | "; // corruption results in empty metadata var convertedInformation = converter.Convert(xmlRomInformation); var builder = new ProgramMetadataBuilder().WithInitialMetadata(XmlProgramMetadata.Value); var expectedMetadata = builder.WithProgrammers(null).Build(); ValidateInformation(XmlProgramInformation, convertedInformation); ValidateDescription(XmlProgramDescription, convertedInformation); ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features); ValidateMetadata(expectedMetadata, convertedInformation.Metadata); }
public void XmlRomInformationToProgramRomInformationConverter_CreateDefaultAndConvertXmlInfoWithZeroReleaseDate_ProducesValidConversion() { var converter = XmlRomInformationToProgramRomInformationConverter.Create(); var xmlRomInformation = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated); xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.release_date).Value = "0000-00-00"; // corrupted because it's not valid, but is correct format var convertedInformation = converter.Convert(xmlRomInformation); var builder = new ProgramMetadataBuilder().WithInitialMetadata(XmlProgramMetadata.Value); var expectedMetadata = builder.WithReleaseDates(null).Build(); var expectedProgramInformation = new TestProgramInformation(XmlProgramInformation) { Year = null }; var expectedProgramDescription = new TestProgramDescription(XmlProgramDescription) { Year = null }; ValidateInformation(expectedProgramInformation, convertedInformation); ValidateDescription(expectedProgramDescription, convertedInformation); ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features); ValidateMetadata(expectedMetadata, convertedInformation.Metadata); }
private static IEnumerable <Tuple <IProgramMetadata, XmlRomInformationDatabaseColumnName, string> > GetTestMetadataForColumn(XmlRomInformationDatabaseColumnName column, int numValues) { var strings = Enumerable.Repeat(string.Empty, 1); var suffixes = Enumerable.Range(0, numValues); var htmlEncode = true; var includeFirstOnly = false; string expectedString = null; for (int i = 0; i < 2; ++i) { var programMetadataBuilder = new ProgramMetadataBuilder(); expectedString = null; switch (column) { case XmlRomInformationDatabaseColumnName.title: programMetadataBuilder.WithLongNames(strings); includeFirstOnly = true; break; case XmlRomInformationDatabaseColumnName.short_name: programMetadataBuilder.WithShortNames(strings); includeFirstOnly = true; break; case XmlRomInformationDatabaseColumnName.vendor: programMetadataBuilder.WithPublishers(strings); includeFirstOnly = true; break; case XmlRomInformationDatabaseColumnName.description: programMetadataBuilder.WithDescriptions(strings); includeFirstOnly = true; break; case XmlRomInformationDatabaseColumnName.release_date: if (i == 0) { var date = new MetadataDateTimeBuilder(1981).WithMonth(12).WithDay(25).Build(); programMetadataBuilder.WithReleaseDates(new[] { date }); expectedString = "1981-12-25"; } else { var dates = suffixes.Select(d => new MetadataDateTimeBuilder(1982).WithMonth(8).WithDay(d + 1).Build()); programMetadataBuilder.WithReleaseDates(dates); expectedString = "1982-08-01"; } includeFirstOnly = true; break; case XmlRomInformationDatabaseColumnName.program: programMetadataBuilder.WithProgrammers(strings); break; case XmlRomInformationDatabaseColumnName.concept: programMetadataBuilder.WithDesigners(strings); break; case XmlRomInformationDatabaseColumnName.game_graphics: programMetadataBuilder.WithGraphics(strings); break; case XmlRomInformationDatabaseColumnName.soundfx: programMetadataBuilder.WithSoundEffects(strings); break; case XmlRomInformationDatabaseColumnName.music: programMetadataBuilder.WithMusic(strings); break; case XmlRomInformationDatabaseColumnName.voices: programMetadataBuilder.WithVoices(strings); break; case XmlRomInformationDatabaseColumnName.game_docs: programMetadataBuilder.WithDocumentation(strings); break; case XmlRomInformationDatabaseColumnName.box_art: programMetadataBuilder.WithArtwork(strings); break; case XmlRomInformationDatabaseColumnName.name: programMetadataBuilder.WithVersions(strings); includeFirstOnly = true; break; case XmlRomInformationDatabaseColumnName.build_date: if (i == 0) { var date = new MetadataDateTimeBuilder(1980).WithMonth(8).WithDay(4).Build(); programMetadataBuilder.WithBuildDates(new[] { date }); expectedString = "1980-08-04"; } else { var dates = suffixes.Select(d => new MetadataDateTimeBuilder(1984).WithMonth(6).WithDay(d + 12).Build()); programMetadataBuilder.WithBuildDates(dates); expectedString = "1984-06-12"; } includeFirstOnly = true; break; case XmlRomInformationDatabaseColumnName.other: programMetadataBuilder.WithAdditionalInformation(strings); break; case XmlRomInformationDatabaseColumnName.license: programMetadataBuilder.WithLicenses(strings); break; case XmlRomInformationDatabaseColumnName.contact_info: programMetadataBuilder.WithContactInformation(strings); htmlEncode = false; break; default: throw new InvalidOperationException(); } if (string.IsNullOrEmpty(expectedString)) { if (includeFirstOnly) { strings = new[] { strings.First() }; } if (htmlEncode) { expectedString = string.Join("|", strings.Select(s => HtmlEncode(s))); } else { expectedString = string.Join("|", strings); } } yield return(new Tuple <IProgramMetadata, XmlRomInformationDatabaseColumnName, string>(programMetadataBuilder.Build(), column, expectedString)); strings = suffixes.Select(s => "Abbott & Costello Part " + s.ToString(CultureInfo.InvariantCulture)); } yield return(new Tuple <IProgramMetadata, XmlRomInformationDatabaseColumnName, string>(new ProgramMetadata(), column, includeFirstOnly ? null : string.Empty)); }