public static JobStatusResponse FromDataTransferObject(directsignaturejobstatusresponse directsignaturejobstatusresponse, DateTime nextPermittedPollTime)
        {
            var jobStatus = directsignaturejobstatusresponse.signaturejobstatus.ToJobStatus();

            var signatures = new List <Signature>();

            foreach (var signerstatus in directsignaturejobstatusresponse.status)
            {
                var xadesurl = directsignaturejobstatusresponse.xadesurl?.SingleOrDefault(xades => xades.signer.Equals(signerstatus.signer));
                signatures.Add(new Signature(signerstatus, xadesurl));
            }

            var jobReferences = new JobReferences(
                directsignaturejobstatusresponse.confirmationurl == null ? null : new Uri(directsignaturejobstatusresponse.confirmationurl),
                directsignaturejobstatusresponse.padesurl == null ? null : new Uri(directsignaturejobstatusresponse.padesurl)
                );

            return(new JobStatusResponse(
                       directsignaturejobstatusresponse.signaturejobid,
                       directsignaturejobstatusresponse.reference,
                       jobStatus,
                       jobReferences,
                       signatures,
                       nextPermittedPollTime
                       ));
        }
            public void Converts_direct_job_status_with_multiple_signers_successfully()
            {
                //Arrange
                var now = DateTime.Now;

                var source = new directsignaturejobstatusresponse
                {
                    signaturejobid     = 77,
                    reference          = null,
                    signaturejobstatus = directsignaturejobstatus.FAILED,
                    status             = new[]
                    {
                        new signerstatus {
                            signer = "12345678910", Value = "REJECTED", since = now
                        },
                        new signerstatus {
                            signer = "10987654321", Value = "SIGNED", since = now
                        }
                    },
                    xadesurl = new[]
                    {
                        new signerspecificurl {
                            signer = "10987654321", Value = "https://example.com/xades-url"
                        }
                    },
                    confirmationurl = "https://example.com/confirmation-url"
                };

                var nextPermittedPollTime = DateTime.Now;

                var expected = new JobStatusResponse(
                    source.signaturejobid,
                    source.reference,
                    JobStatus.Failed,
                    new JobReferences(new Uri("https://example.com/confirmation-url"), null),
                    new List <Signature>
                {
                    new Signature("12345678910", null, SignatureStatus.Rejected, now),
                    new Signature("10987654321", new XadesReference(new Uri("https://example.com/xades-url")), SignatureStatus.Signed, now)
                },
                    nextPermittedPollTime
                    );

                //Act
                var result = DataTransferObjectConverter.FromDataTransferObject(source, nextPermittedPollTime);

                //Assert
                var comparator = new Comparator();
                IEnumerable <IDifference> differences;

                comparator.AreEqual(expected, result, out differences);
                Assert.Empty(differences);
            }
            public void Converts_signed_direct_job_status_successfully()
            {
                //Arrange
                var now = DateTime.Now;

                var source = new directsignaturejobstatusresponse
                {
                    signaturejobid     = 77,
                    reference          = "senders-reference",
                    signaturejobstatus = directsignaturejobstatus.COMPLETED_SUCCESSFULLY,
                    status             = new[] { new signerstatus {
                                                     signer = "12345678910", Value = "SIGNED", since = now
                                                 } },
                    confirmationurl = "http://signatureRoot.digipost.no/confirmation",
                    xadesurl        = new[] { new signerspecificurl {
                                                  signer = "12345678910", Value = "http://signatureRoot.digipost.no/xades"
                                              } },
                    padesurl = "http://signatureRoot.digipost.no/pades"
                };

                var nextPermittedPollTime = DateTime.Now;

                var expected = new JobStatusResponse(
                    source.signaturejobid,
                    source.reference,
                    JobStatus.CompletedSuccessfully,
                    new JobReferences(new Uri(source.confirmationurl), new Uri(source.padesurl)),
                    new List <Signature> {
                    new Signature("12345678910", new XadesReference(new Uri("http://signatureRoot.digipost.no/xades")), SignatureStatus.Signed, now)
                },
                    nextPermittedPollTime
                    );

                //Act
                var result = DataTransferObjectConverter.FromDataTransferObject(source, nextPermittedPollTime);

                //Assert
                var comparator = new Comparator();
                IEnumerable <IDifference> differences;

                comparator.AreEqual(expected, result, out differences);
                Assert.Empty(differences);
            }