Exemplo n.º 1
0
        public void WhenRegeneratingDefaultMembersOnlyUntouchedAreAdded()
        {
            var test = PreClassBoilerplate + @"
                var test = new ExpressionMapper<Src, Trg>(
                    new ExpressionMappingComponents<Src, Trg>(
                        (source) => new Trg()
                        {
                        },
                        customMappings: (source) => new Trg()
                        {
                            B = 10,
                            C = 15
                        },
                        sourceIgnoredProperties: new IgnoreList<Src>(
                            x => x.Ignore1,
                            x => x.B
                        ),
                        targetIgnoredProperties: new IgnoreList<Trg>(
                            (x) => x.Ignore2
                        )));"
                       + PostClassBoilerplate
                       + ClassDefinitions;

            VerifyCSharpDiagnostic(test,
                                   MappingProblem("Source member A is not mapped.", 17, 21, (26, 50)),
                                   MappingProblem("Target member A is not mapped.", 17, 21, (30, 50)),
                                   MappingProblem("Some membmers with identical names are not mapped. Please choose 'Regenerate defaultMappings.'" +
                                                  " or manually handle missing members: A.", 18, 25));

            var fixTest = PreClassBoilerplate + @"
                var test = new ExpressionMapper<Src, Trg>(
                    new ExpressionMappingComponents<Src, Trg>(
(source) => new Trg()
{
    A = source.A,
},
                        customMappings: (source) => new Trg()
                        {
                            B = 10,
                            C = 15
                        },
                        sourceIgnoredProperties: new IgnoreList<Src>(
                            x => x.Ignore1,
                            x => x.B
                        ),
                        targetIgnoredProperties: new IgnoreList<Trg>(
                            (x) => x.Ignore2
                        )));"
                          + PostClassBoilerplate
                          + ClassDefinitions;

            VerifyCSharpFix(test, fixTest, diagnosticsIndex: 2);
        }
Exemplo n.º 2
0
        public void WhenMissingMappingsFoundAFixWillBeProposedForCompatibleMembers()
        {
            var test = PreClassBoilerplate + @"
                var test = new ExpressionMapper<Src, Trg>(
                    new ExpressionMappingComponents<Src, Trg>(
                        (source) => new Trg()
                        {
                        },
                        customMappings: (source) => new Trg()
                        {
                            C = 15
                        },
                        sourceIgnoredProperties: new IgnoreList<Src>(
                            x => x.Ignore1
                        ),
                        targetIgnoredProperties: new IgnoreList<Trg>(
                            (x) => x.Ignore2
                        )));"
                       + PostClassBoilerplate
                       + ClassDefinitions;

            VerifyCSharpDiagnostic(test,
                                   MappingProblem("Source member A;B are not mapped.", 17, 21, (25, 50)),
                                   MappingProblem("Target member A;B are not mapped.", 17, 21, (28, 50)),
                                   MappingProblem("Some membmers with identical names are not mapped. Please choose 'Regenerate defaultMappings.'" +
                                                  " or manually handle missing members: A;B.", 18, 25));

            var fixTest = PreClassBoilerplate + @"
                var test = new ExpressionMapper<Src, Trg>(
                    new ExpressionMappingComponents<Src, Trg>(
(source) => new Trg()
{
    A = source.A,
    B = source.B,
},
                        customMappings: (source) => new Trg()
                        {
                            C = 15
                        },
                        sourceIgnoredProperties: new IgnoreList<Src>(
                            x => x.Ignore1
                        ),
                        targetIgnoredProperties: new IgnoreList<Trg>(
                            (x) => x.Ignore2
                        )));"
                          + PostClassBoilerplate
                          + ClassDefinitions;

            VerifyCSharpFix(test, fixTest, diagnosticsIndex: 2);
        }
Exemplo n.º 3
0
        public void WhenMembersAreMissingFromIgnoreACodeFixWillBeOfferedToAddThem_AddToNonEmptyIgnoreListCase()
        {
            var test = PreClassBoilerplate + @"
                var test = new ExpressionMapper<Src, Trg>(
                    new ExpressionMappingComponents<Src, Trg>(
                        (source) => new Trg()
                        {
                            A = source.A,
                        },
                        (source) => new Trg()
                        {
                            C = 10
                        },
                        sourceIgnoredProperties: new IgnoreList<Src>(
                            x => x.Ignore1,
                            x => x.B
                        ),
                        targetIgnoredProperties: new IgnoreList<Trg>(
x => x.B));"
                       + PostClassBoilerplate
                       + ClassDefinitions;

            VerifyCSharpDiagnostic(test,
                                   MappingProblem("Target member Ignore2 is not mapped.", 17, 21, (30, 50)));

            var fixTest = PreClassBoilerplate + @"
                var test = new ExpressionMapper<Src, Trg>(
                    new ExpressionMappingComponents<Src, Trg>(
                        (source) => new Trg()
                        {
                            A = source.A,
                        },
                        (source) => new Trg()
                        {
                            C = 10
                        },
                        sourceIgnoredProperties: new IgnoreList<Src>(
                            x => x.Ignore1,
                            x => x.B
                        ),
                        targetIgnoredProperties: new IgnoreList<Trg>(
x => x.B,
(target) => target.Ignore2));"
                          + PostClassBoilerplate
                          + ClassDefinitions;

            VerifyCSharpFix(test, fixTest);
        }
        public void ValidateMapping()
        {
            invalidateErrorUnit();

            _mappingProblem = _importer.CheckWhetherAllDataColumnsAreMapped(_columnInfos, _mappings.Select(m => m.Source));
            setStatuses();
            if (_mappingProblem.MissingMapping.Count != 0 || _mappingProblem.MissingUnit.Count != 0)
            {
                OnMissingMapping(this,
                                 new MissingMappingEventArgs
                {
                    Message = _mappingProblem.MissingMapping.FirstOrDefault() ?? _mappingProblem.MissingUnit.FirstOrDefault()
                });
            }
            else
            {
                OnMappingCompleted(this, new EventArgs());
            }

            //at the end refresh the data in the columnMappingView grid, to ensure consistency
            View.RefreshData();
        }