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 XmlRomInformationToProgramRomInformationConverter_CreateDefaultAndConvertXmlInfoWithAllEmptyColumns_ThrowsInvalidOperationException()
        {
            var converter = XmlRomInformationToProgramRomInformationConverter.Create();

            var xmlRomInformation = CreateTestInformationForConversion(XmlInformationKind.EmptyColumns);

            Assert.Throws <InvalidOperationException>(() => converter.Convert(xmlRomInformation));
        }
        public void XmlRomInformationToProgramRomInformationConverter_CreateDefaultAndConvertNullXmlInfo_ThrowsNullReferenceException()
        {
            var converter = XmlRomInformationToProgramRomInformationConverter.Create();

            var xmlRomInformation = CreateTestInformationForConversion(XmlInformationKind.None);

            Assert.Throws <NullReferenceException>(() => converter.Convert(xmlRomInformation));
        }
        public void XmlRomInformationToProgramRomInformationConverter_CreateWithNullDescriptionsSourceAndConvertNullXmlInfo_ThrowsNullReferenceException()
        {
            IEnumerable <ProgramDescription> descriptionsSource = null;
            var converter = XmlRomInformationToProgramRomInformationConverter.Create(descriptionsSource);

            var xmlRomInformation = CreateTestInformationForConversion(XmlInformationKind.None);

            Assert.Throws <NullReferenceException>(() => converter.Convert(xmlRomInformation));
        }
        public void XmlRomInformationToProgramRomInformationConverter_CreateWithNullDatabaseAndConvertNullXmlInfo_ThrowsNullReferenceException()
        {
            XmlRomInformationToProgramRomInformationConverterTestProgramDatabase database = null;
            var converter = XmlRomInformationToProgramRomInformationConverter.Create(database);

            var xmlRomInformation = CreateTestInformationForConversion(XmlInformationKind.None);

            Assert.Throws <NullReferenceException>(() => converter.Convert(xmlRomInformation));
        }
        public void XmlRomInformationToProgramRomInformationConverter_CreateDefaultAndConvertXmlInfo_ProducesValidConversion()
        {
            var converter = XmlRomInformationToProgramRomInformationConverter.Create();

            var xmlRomInformation    = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated);
            var convertedInformation = converter.Convert(xmlRomInformation);

            ValidateInformation(XmlProgramInformation, convertedInformation);
            ValidateDescription(XmlProgramDescription, convertedInformation);
            ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features);
            ValidateMetadata(XmlProgramMetadata.Value, convertedInformation.Metadata);
        }
        public void XmlRomInformationToProgramRomInformationConverter_CreateWithEmptyDescriptionsSourceAndConvertXmlInfo_ProducesValidConversion()
        {
            var descriptionsSource = Enumerable.Empty <ProgramDescription>();
            var converter          = XmlRomInformationToProgramRomInformationConverter.Create(descriptionsSource);

            var xmlRomInformation    = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated);
            var convertedInformation = converter.Convert(xmlRomInformation);

            ValidateInformation(XmlProgramInformation, convertedInformation);
            ValidateDescription(XmlProgramDescription, convertedInformation);
            ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features);
            ValidateMetadata(XmlProgramMetadata.Value, convertedInformation.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_CreateWithDatabaseContaingMatchAndConvertXmlInfo_ProducesValidConversion()
        {
            var database = new XmlRomInformationToProgramRomInformationConverterTestProgramDatabase();
            var testProgramInformation = new TestProgramInformation();

            database.AddProgram(testProgramInformation);
            var converter = XmlRomInformationToProgramRomInformationConverter.Create(database);

            var xmlRomInformation    = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated);
            var convertedInformation = converter.Convert(xmlRomInformation);

            ValidateInformation(testProgramInformation, convertedInformation);
            ValidateDescription(testProgramInformation.ToDescription(), convertedInformation);
            ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features);
            ValidateMetadata(XmlProgramMetadata.Value, convertedInformation.Metadata);
        }
        public void XmlRomInformationToProgramRomInformationConverter_CreateWithDescriptionsSourceContainingMatchAndConvertXmlInfo_ProducesValidConversion()
        {
            var testProgramDescription = new TestProgramDescription();
            var descriptionsSource     = new List <IProgramDescription>()
            {
                testProgramDescription
            };
            var converter = XmlRomInformationToProgramRomInformationConverter.Create(descriptionsSource);

            var xmlRomInformation    = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated);
            var convertedInformation = converter.Convert(xmlRomInformation);

            ValidateInformation(testProgramDescription.ToInformation(), convertedInformation);
            ValidateDescription(testProgramDescription, convertedInformation);
            ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features);
            ValidateMetadata(XmlProgramMetadata.Value, convertedInformation.Metadata);
        }
        public void XmlRomInformationToProgramRomInformationConverter_CreateWithDescriptionsSourceContainingMatchWithRomWithMetadatdaAndConvertXmlInfo_ProducesValidConversion()
        {
            var romPaths = XmlRomInformationToProgramRomInformationConverterTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgMetadataPath);
            var rom      = Rom.Create(romPaths[0], romPaths[1]);

            Assert.NotNull(rom);
            var testProgramDescription = new TestProgramDescription(rom);
            var descriptionsSource     = new List <IProgramDescription>()
            {
                testProgramDescription
            };
            var converter = XmlRomInformationToProgramRomInformationConverter.Create(descriptionsSource);

            var xmlRomInformation    = CreateTestInformationForConversion(XmlInformationKind.FullyPopulated);
            var convertedInformation = converter.Convert(xmlRomInformation);

            ValidateInformation(testProgramDescription.ToInformation(), convertedInformation);
            ValidateDescription(testProgramDescription, convertedInformation);
            ValidateFeatures(XmlProgramFeatures.Value, convertedInformation.Features);
            ValidateMetadata(XmlProgramMetadata.Value, 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);
        }