Skip to content

Conversation

@DocSvartz
Copy link
Contributor

@DocSvartz DocSvartz commented Oct 23, 2023

Fix Issue:
#501 - test named OnlyInlineRecordWorked (regarding not filling the record with data in the given case)

Add

  1. (InlineExpression is Worked) Field Activation passing Field values not specified in the constructor when creating a new record instance
  2. Record Creation on Default Passing Field values not specified in the constructor when creating a new record instance (Activation)
  3. A special attribute to support custom classes (structures) that use the current record definition. description of spec record at the end of the page -
    [AdaptWith(AdaptDirectives.DestinationAsRecord)] - to be confirmed

Example:

 [TestMethod]
        public void MultiCtorAndInlineRecordWorked()
        {
            var _sourcePoco = new MultiCtorAndInlinePoco() { MyInt = 1, MyString = "Hello", MyEmail = "123@gmail.com", InitData="Test"};
            var _sourceMultiCtorAndInline = new MultiCtorAndInlineRecord(2, "Hello World") { InitData = "Worked", MyEmail = "243@gmail.com" };

            var _resultMultiCtorAndInline = _sourcePoco.Adapt<MultiCtorAndInlineRecord>();  // Activation 
            var _updateResult = _sourceMultiCtorAndInline.Adapt(_resultMultiCtorAndInline);  // Update

            _resultMultiCtorAndInline.MyInt.ShouldBe(1);
            _resultMultiCtorAndInline.MyString.ShouldBe("Hello");
            _resultMultiCtorAndInline.MyEmail.ShouldBe("123@gmail.com");
            _resultMultiCtorAndInline.InitData.ShouldBe("Test");
            _updateResult.MyInt.ShouldBe(2);
            _updateResult.MyString.ShouldBe("Hello World");
            _updateResult.MyEmail.ShouldBe("243@gmail.com");
            _updateResult.InitData.ShouldBe("Worked");
        }

    record MultiCtorAndInlineRecord
    {
        public MultiCtorAndInlineRecord(int myInt)
        {
            MyInt = myInt;
        }

        public MultiCtorAndInlineRecord(int myInt, string myString) : this(myInt) // default have been using this constructor
        {
            MyString = myString;
        }


        public int MyInt { get; private set; } // private set only constructor or using init 
        public string MyString { get; private set; } // private set only constructor or using init 
        public string MyEmail { get; set; } 
        public string InitData { get; init; } // init in Constructor or inline activation
    }

@DocSvartz DocSvartz changed the title FIx Issue #537 - Step 2 - Add Support Extended Record Function + Attibute from support used legasy record definitions FIx Issue #537 - Step 2 - Add Support Extended Record Function + Attribute from support used legasy record definitions Oct 23, 2023
@DocSvartz
Copy link
Contributor Author

DocSvartz commented Oct 23, 2023

Explanations regarding tests marked Ignore
I don’t understand what exactly wanted to check in them?

  1. If it is possible to map non-public fields to the record constructor, then the Source should have had them
  2. If mapping fields from the Source to hidden fields in the record, then this should not work at all. The record is always activated through the constructor and they would have gotten there anyway. Because the sources are public.

Tests have been rewritten to test what the test name states

@DocSvartz DocSvartz changed the title FIx Issue #537 - Step 2 - Add Support Extended Record Function + Attribute from support used legasy record definitions FIx Issue #537 - Step 2 - Add Support Extended Record Function + Attribute from support used legacy record definitions Oct 23, 2023
@DocSvartz DocSvartz changed the title FIx Issue #537 - Step 2 - Add Support Extended Record Function + Attribute from support used legacy record definitions FIx Issue #537 - Step 2 - Add Support Extended Record Function + Attribute from support used current record definitions Oct 23, 2023
@andrerav
Copy link
Contributor

andrerav commented Jan 2, 2025

Closed and reopened to re-run the workflow.

@andrerav andrerav closed this Jan 2, 2025
@andrerav andrerav reopened this Jan 2, 2025
@andrerav andrerav changed the title FIx Issue #537 - Step 2 - Add Support Extended Record Function + Attribute from support used current record definitions Fix issue #537 - Step 2 - Add support Extended Record Function + Attribute from support used current record definitions Jan 2, 2025
@andrerav andrerav merged commit bdfe266 into MapsterMapper:development Jan 2, 2025
1 check passed
@andrerav
Copy link
Contributor

andrerav commented Jan 2, 2025

Thank you @DocSvartz!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants