public override void HandleAttach()

in src/Proton.TestPeer/Expectations/AttachExpectation.cs [387:485]


      public override void HandleAttach(uint frameSize, Attach attach, byte[] payload, ushort channel, AMQPTestDriver context)
      {
         base.HandleAttach(frameSize, attach, payload, channel, context);

         SessionTracker session = driver.Sessions.SessionFromRemoteChannel(channel);

         if (session == null)
         {
            throw new AssertionError(string.Format(
                "Received Attach on channel [{0}] that has no matching Session for that remote channel. ", channel));
         }

         LinkTracker link = session.HandleRemoteAttach(attach);

         if (response != null)
         {
            // Input was validated now populate response with auto values where not configured
            // to say otherwise by the test.
            if (response.OnChannel() == null)
            {
               response.OnChannel((ushort)link.Session.LocalChannel);
            }

            // Populate the fields of the response with defaults if non set by the test script
            if (response.Performative.Handle == null)
            {
               response.WithHandle(session.FindFreeLocalHandle());
            }
            if (response.Performative.Name == null)
            {
               response.WithName(attach.Name);
            }
            if (response.Performative.Role == null)
            {
               response.WithRole(attach.Role?.ReverseOf() ?? Role.Sender);
            }
            if (response.Performative.SenderSettleMode == null)
            {
               response.WithSndSettleMode(attach.SenderSettleMode ?? SenderSettleMode.Mixed);
            }
            if (response.Performative.ReceiverSettleMode == null)
            {
               response.WithRcvSettleMode(attach.ReceiverSettleMode ?? ReceiverSettleMode.First);
            }
            if (response.Performative.Source == null && !response.IsNullSourceRequired)
            {
               response.WithSource(attach.Source);
               if (attach.Source != null && (attach.Source.Dynamic ?? false))
               {
                  attach.Source.Address = Guid.NewGuid().ToString();
               }
            }

            if (rejecting)
            {
               if ((attach.Role ?? Role.Sender) == Role.Sender)
               {
                  // Sender attach so response should have null target
                  response.WithNullTarget();
               }
               else
               {
                  // Receiver attach so response should have null source
                  response.WithNullSource();
               }
            }

            if (response.Performative.Target == null && !response.IsNullTargetRequired)
            {
               if (attach.Target != null)
               {
                  if (attach.Target is Target target)
                  {
                     response.WithTarget(target);
                     if (target != null && (target.Dynamic ?? false))
                     {
                        target.Address = Guid.NewGuid().ToString();
                     }
                  }
                  else
                  {
                     Coordinator coordinator = (Coordinator)attach.Target;
                     response.WithTarget(coordinator);
                  }
               }
            }

            if (response.Performative.InitialDeliveryCount == null)
            {
               Role role = response.Performative.Role ?? Role.Receiver;
               if (role == Role.Sender)
               {
                  response.WithInitialDeliveryCount(0);
               }
            }

            // Other fields are left not set for now unless test script configured
         }
      }