Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ArchiveSmokeTestsHelper
{
public static readonly string ArchiveName = "SmokeTestArchive";
private readonly TestSender _testSender;
private readonly ArchiveApi _archiveApi;
private readonly IArchiveApi _archiveApi;
private Archive _archivesWithDocuments;
private Archive _archive;
private Archive _byAttribute;
Expand Down
4 changes: 2 additions & 2 deletions Digipost.Api.Client.Archive/ArchiveApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Digipost.Api.Client.Archive
{
internal interface IArchiveApi
public interface IArchiveApi
{
/// <summary>
/// List all the archives available to the current sender
Expand Down Expand Up @@ -52,7 +52,7 @@ internal interface IArchiveApi
Task<ArchiveDocumentContent> GetDocumentContent(ArchiveDocumentContentUri archiveDocumentContentUri);
}

public class ArchiveApi : IArchiveApi
internal class ArchiveApi : IArchiveApi
{
private readonly Root _root;
private readonly RequestHelper _requestHelper;
Expand Down
15 changes: 15 additions & 0 deletions Digipost.Api.Client.Common/DataTransferObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,20 @@ public static SearchDetailsResult FromDataTransferObject(Recipients recipients)
})
};
}

public static HashAlgoritm ToHashAlgoritm(this V8.Hash_Algorithm hashAlgorithm)
{
switch (hashAlgorithm)
{
case Hash_Algorithm.NONE:
return HashAlgoritm.NONE;
case Hash_Algorithm.MD5:
return HashAlgoritm.MD5;
case Hash_Algorithm.SHA256:
return HashAlgoritm.SHA256;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
5 changes: 5 additions & 0 deletions Digipost.Api.Client.Common/Entrypoint/Entrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public GetArchiveDocumentByUuidUri GetGetArchiveDocumentsByUuidUri(Guid guid)
{
return new GetArchiveDocumentByUuidUri(Links["GET_ARCHIVE_DOCUMENT_BY_UUID"], guid);
}

public DocumentStatusUri GetDocumentStatusUri(Guid guid)
{
return new DocumentStatusUri(Links["DOCUMENT_STATUS"], guid);
}
}

public class Link
Expand Down
9 changes: 9 additions & 0 deletions Digipost.Api.Client.Common/Enums/HashAlgoritm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Digipost.Api.Client.Common.Enums
{
public enum HashAlgoritm
{
NONE,
MD5,
SHA256
}
}
14 changes: 13 additions & 1 deletion Digipost.Api.Client.Common/Relations/ApiRelations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public ApiRootUri(Sender senderId = null)
}
}


public class SendMessageUri : Uri
{
public SendMessageUri(Link link)
Expand Down Expand Up @@ -160,4 +159,17 @@ public ArchiveDocumentDeleteUri(Link link)
{
}
}

public class DocumentStatusUri : Uri
{
public DocumentStatusUri(Link link, Guid guid)
: base($"{link.Uri}{guid.ToString()}", UriKind.Absolute)
{
}

public DocumentStatusUri(Link link)
: base(link.Uri, UriKind.Absolute)
{
}
}
}
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Docs/ArchiveExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private async Task ArchiveADocument()
new ArchiveDocument(Guid.NewGuid(), "attachment_123123.pdf", "pdf", "application/psd", readFileFromDisk("attachment_123123.pdf"))
});

var savedArchive = await client.GetArchive().ArchiveDocuments(archive);
var savedArchive = client.GetArchive().ArchiveDocuments(archive);
}

private async Task ArchiveADocumentWithAutoDelete()
Expand Down
23 changes: 23 additions & 0 deletions Digipost.Api.Client.Docs/DocumentsExamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Send;

namespace Digipost.Api.Client.Docs
{
public class DocumentsExamples
{
private static readonly DigipostClient client;
private static readonly Sender sender;

public void Hent_document_status()
{
DocumentStatus documentStatus = client.GetDocumentStatus(sender)
.GetDocumentStatus(Guid.Parse("10ff4c99-8560-4741-83f0-1093dc4deb1c"))
.Result;

// example information:
// documentStatus.DeliveryStatus => DELIVERED
// documentStatus.DeliveryMethod => PRINT
}
}
}
83 changes: 83 additions & 0 deletions Digipost.Api.Client.Send/DocumentStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Enums;

namespace Digipost.Api.Client.Send
{
public class DocumentStatus
{
public DocumentStatus(
string guid,
long senderId,
DateTime created,
DocumentDeliveryStatus documentDeliveryStatus,
Read? read,
DeliveryMethod deliveryMethod,
string contentHash,
DateTime? delivered,
Boolean? isPrimaryDocument,
HashAlgoritm? contentHashAlgoritm
)
{
Guid = guid;
Sender = new Sender(senderId);
Created = created;
DeliveryStatus = documentDeliveryStatus;
DocumentRead = read;
DeliveryMethod = deliveryMethod;
ContentHash = contentHash;
Delivered = delivered;
IsPrimaryDocument = isPrimaryDocument;
ContentHashAlgoritm = contentHashAlgoritm;
}

public string Guid { get; }

public Sender Sender { get; }

public DateTime Created { get; }

/**
* If DeliveryStatus is NOT_DELIVERED, Delivered will not have a value
*/
public DateTime? Delivered { get; }

public DocumentDeliveryStatus DeliveryStatus { get; }

public Read? DocumentRead { get; }

public DeliveryMethod DeliveryMethod { get; }

public String ContentHash { get; }

public HashAlgoritm? ContentHashAlgoritm { get; }

/**
* isPrimaryDocument has value only if you ask api are the actual sender asking for DocumentStatus.
* If you are, then this will be true for the primary document else false.
*/
public Boolean? IsPrimaryDocument { get; }

public enum DocumentDeliveryStatus
{
/**
* The document has been delivered
*/
DELIVERED,

/**
* The document is still being processed
*/
NOT_DELIVERED
}

/**
* Indicates whether the document is read or not
*/
public enum Read
{
YES,
NO
}
}
}
53 changes: 48 additions & 5 deletions Digipost.Api.Client.Send/SendDataTransferObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Xml;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.Common.Extensions;
using V8;

Expand Down Expand Up @@ -86,16 +87,16 @@ public static V8.Document ToDataTransferObject(IDocument document)
return documentDto;
}

public static V8.Sms_Notification ToDataTransferObject(ISmsNotification smsNotification)
public static Sms_Notification ToDataTransferObject(ISmsNotification smsNotification)
{
if (smsNotification == null)
return null;

var smsNotificationDto = new V8.Sms_Notification();
var smsNotificationDto = new Sms_Notification();

if (smsNotification.NotifyAtTimes.Count > 0)
{
var timesAsListedTimes = smsNotification.NotifyAtTimes.Select(dateTime => new V8.Listed_Time {Time = dateTime, TimeSpecified = true});
var timesAsListedTimes = smsNotification.NotifyAtTimes.Select(dateTime => new Listed_Time {Time = dateTime, TimeSpecified = true});
foreach (var timesAsListedTime in timesAsListedTimes)
{
smsNotificationDto.At.Add(timesAsListedTime);
Expand All @@ -113,7 +114,7 @@ public static V8.Sms_Notification ToDataTransferObject(ISmsNotification smsNotif
return smsNotificationDto;
}

public static IMessageDeliveryResult FromDataTransferObject(V8.Message_Delivery messageDeliveryDto)
public static IMessageDeliveryResult FromDataTransferObject(Message_Delivery messageDeliveryDto)
{
IMessageDeliveryResult messageDeliveryResult = new MessageDeliveryResult
{
Expand All @@ -138,7 +139,7 @@ public static IDocument FromDataTransferObject(V8.Document documentDto)
};
}

public static ISmsNotification FromDataTransferObject(V8.Sms_Notification smsNotificationDto)
public static ISmsNotification FromDataTransferObject(Sms_Notification smsNotificationDto)
{
if (smsNotificationDto == null)
return null;
Expand All @@ -151,5 +152,47 @@ public static ISmsNotification FromDataTransferObject(V8.Sms_Notification smsNot

return smsNotification;
}

public static DocumentStatus FromDataTransferObject(Document_Status dto)
{
return new DocumentStatus(
dto.Uuid,
dto.Sender_Id,
dto.Created,
dto.Status.ToDeliveryStatus(),
dto.ReadSpecified ? dto.Read.ToRead() : (DocumentStatus.Read?) null,
dto.Channel.ToDeliveryMethod(),
dto.Content_Hash,
dto.DeliveredSpecified ? dto.Delivered : (DateTime?) null,
dto.Is_Primary_DocumentSpecified ? dto.Is_Primary_Document : (bool?) null,
dto.Content_Hash_AlgorithmSpecified ? dto.Content_Hash_Algorithm.ToHashAlgoritm() : (HashAlgoritm?) null
);
}

private static DocumentStatus.DocumentDeliveryStatus ToDeliveryStatus(this Delivery_Status deliveryStatus)
{
switch (deliveryStatus)
{
case Delivery_Status.DELIVERED:
return DocumentStatus.DocumentDeliveryStatus.DELIVERED;
case Delivery_Status.NOT_DELIVERED:
return DocumentStatus.DocumentDeliveryStatus.NOT_DELIVERED;
default:
throw new ArgumentOutOfRangeException();
}
}

private static DocumentStatus.Read ToRead(this Read read)
{
switch (read)
{
case Read.Y:
return DocumentStatus.Read.YES;
case Read.N:
return DocumentStatus.Read.NO;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
24 changes: 23 additions & 1 deletion Digipost.Api.Client.Tests/Smoke/ClientSmokeTestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Entrypoint;
using Digipost.Api.Client.Common.Enums;
Expand Down Expand Up @@ -47,6 +46,8 @@ internal class ClientSmokeTestHelper
//Gradually built state, requestForRegistration
private RequestForRegistration _requestForRegistration;

private DocumentStatus _documentStatus;

public ClientSmokeTestHelper(TestSender testSender, bool withoutDataTypesProject = false)
{
var broker = new Broker(testSender.Id);
Expand Down Expand Up @@ -222,5 +223,26 @@ public void Expect_search_to_have_result()

Assert.InRange(_searchResult.PersonDetails.ToList().Count, 1, 11);
}

public ClientSmokeTestHelper FetchDocumentStatus()
{
Assert_state(_messageDeliveryResult);
Assert_state(_primary);

_documentStatus = _digipostClient.GetDocumentStatus(new Sender(_testSender.Id)).GetDocumentStatus(Guid.Parse(_primary.Guid)).Result;
return this;
}
public ClientSmokeTestHelper FetchDocumentStatus(Guid guid)
{
_documentStatus = _digipostClient.GetDocumentStatus(new Sender(_testSender.Id)).GetDocumentStatus(guid).Result;
return this;
}

public void Expect_document_status_to_be(DocumentStatus.DocumentDeliveryStatus deliveryStatus, DeliveryMethod deliveryMethod)
{
Assert_state(_documentStatus);
Assert.Equal(_documentStatus.DeliveryMethod, deliveryMethod);
Assert.Equal(_documentStatus.DeliveryStatus, deliveryStatus);
}
}
}
27 changes: 26 additions & 1 deletion Digipost.Api.Client.Tests/Smoke/ClientSmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public void Can_send_document_with_raw_datatype_to_digipost_user()
[Fact(Skip = "SmokeTest")]
public void Can_send_document_with_object_datatype_to_digipost_user()
{

var externalLink = new ExternalLink {Url = "https://www.test.no", Description = "This is a link"};
var linkXml = SerializeUtil.Serialize(externalLink);

Expand All @@ -94,5 +93,31 @@ public void Can_send_document_with_object_datatype_to_digipost_user()
.SendMessage()
.Expect_message_to_have_status(MessageStatus.Delivered);
}

[Fact(Skip = "SmokeTest")]
public void Can_send_document_share_request_to_user()
{
_client
.Create_message_with_primary_document()
.To_Digital_Recipient()
.SendMessage()
.Expect_message_to_have_status(MessageStatus.Delivered);

_client.FetchDocumentStatus()
.Expect_document_status_to_be(
DocumentStatus.DocumentDeliveryStatus.DELIVERED,
DeliveryMethod.Digipost
);
}

[Fact(Skip = "SmokeTest")]
public void Check_document_status()
{
_client.FetchDocumentStatus(Guid.Parse("92c95fa4-dc74-4196-95e9-4dc580017588")) //Use a guid that you know of. This is just a random one.
.Expect_document_status_to_be(
DocumentStatus.DocumentDeliveryStatus.NOT_DELIVERED,
DeliveryMethod.PENDING
);
}
}
}
Loading