Skip to content

Commit

Permalink
Merge pull request #216 from digipost/datatype_redux
Browse files Browse the repository at this point in the history
Use Digipost DataTypes v.4.0.0
  • Loading branch information
eivinhb authored Nov 10, 2023
2 parents ce447f5 + a5949b6 commit 94ac9b1
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 256 deletions.
1 change: 0 additions & 1 deletion Digipost.Api.Client.Docs/Digipost.Api.Client.Docs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.DataTypes.Core" Version="3.1.2" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<ProjectReference Include="..\Digipost.Api.Client.Common\Digipost.Api.Client.Common.csproj">
<Project>{CD338E5A-1ED0-4331-B34E-8292FA8E387B}</Project>
Expand Down
89 changes: 25 additions & 64 deletions Digipost.Api.Client.Docs/SendExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
using Digipost.Api.Client.Common.Utilities;
using Digipost.Api.Client.DataTypes.Core;
using Digipost.Api.Client.Send;
using Address = Digipost.Api.Client.DataTypes.Core.Address;
using Address = Digipost.Api.Client.DataTypes.Core.Common.Address;
using Environment = Digipost.Api.Client.Common.Environment;
using Sender = Digipost.Api.Client.Common.Sender;

#pragma warning disable 0649

Expand Down Expand Up @@ -267,11 +266,10 @@ public void SendLetterThroughNorskHelsenett()

public void SendInvoice()
{
var invoice = new Invoice();
invoice.Kid = "123123123";
invoice.Sum = new decimal(100.21);
invoice.Creditor_Account = "2593143xxxx";
invoice.Due_Date = "2022-12-03T10:15:30+01:00 Europe/Paris"; // ISO-8601 zoned datetime
var invoice = new Invoice(dueDate: DateTime.Parse("2022-12-03T10:15:30+01:00 Europe/Paris"), sum: new decimal(100.21), creditorAccount: "2593143xxxx")
{
Kid = "123123123"
};

var message = new Message(
sender,
Expand All @@ -280,19 +278,20 @@ public void SendInvoice()
subject: "Invoice 1",
fileType: "pdf",
path: @"c:\...\invoice.pdf",
dataType: SerializeUtil.Serialize(invoice))
dataType: invoice)
);

var result = client.SendMessage(message);
}

public void SendInkasso()
{
var inkasso = new Inkasso();
inkasso.Kid = "123123123";
inkasso.Sum = new decimal(100.21);
inkasso.Account = "2593143xxxx";
inkasso.Due_Date = "2022-12-03T10:15:30+01:00 Europe/Paris"; // ISO-8601 zoned datetime
var inkasso = new Inkasso(dueDate: DateTime.Parse("2022-12-03T10:15:30+01:00 Europe/Paris"))
{
Kid = "123123123",
Sum = new decimal(100.21),
Account = "2593143xxxx"
};

var message = new Message(
sender,
Expand All @@ -301,7 +300,7 @@ public void SendInkasso()
subject: "Invoice 1",
fileType: "pdf",
path: @"c:\...\invoice.pdf",
dataType: SerializeUtil.Serialize(inkasso))
dataType: inkasso)
);

var result = client.SendMessage(message);
Expand Down Expand Up @@ -349,77 +348,39 @@ public void SendMessageWithDeliveryTime()

public void SendMessageWithAppointmentMetadata()
{
var startTime = DateTime.Parse("2017-11-24T13:00:00+0100");
var appointment = new Appointment
var appointment = new Appointment(startTime: DateTime.Parse("2017-11-24T13:00:00+0100"))
{
Start_Time = startTime.ToString("O"),
End_Time = startTime.AddMinutes(30).ToString("O"),
Address = new Address {Street_Address = "Storgata 1", Postal_Code = "0001", City = "Oslo"}
EndTime = DateTime.Parse("2017-11-24T13:00:00+0100").AddMinutes(30),
Address = new Address
{
StreetAddress = "Storgata 1",
PostalCode = "0001",
City = "Oslo"
}
};

string appointmentXml = SerializeUtil.Serialize(appointment);

var document = new Document(
subject: "Your appointment",
fileType: "pdf",
path: @"c:\...\document.pdf",
dataType: appointmentXml
);
}

public void SendMessageWithEventMetadata()
{
var startTime = DateTime.Parse("2017-11-24T13:00:00+0100");

var timeInterval1 = new TimeInterval {Start_Time = DateTime.Today.ToString("O"), End_Time = DateTime.Today.AddHours(3).ToString("O")};
var timeInterval2 = new TimeInterval {Start_Time = DateTime.Today.AddDays(1).ToString("O"), End_Time = DateTime.Today.AddDays(1).AddHours(5).ToString("O")};

var barcode = new Barcode {Barcode_Value = "12345678", Barcode_Type = "insert type here", Barcode_Text = "this is a code", Show_Value_In_Barcode = true};
var address = new Address {Street_Address = "Gateveien 1", Postal_Code = "0001", City = "Oslo"};
var info = new Info {Title = "Title", Text = "Very important information"};
var link = new Link {Url = "https://www.test.no", Description = "This is a link"};

Event @event = new Event
{
Start_Time = {timeInterval1, timeInterval2},
Description = "Description here",
Address = address,
Info = {info},
Place = "Oslo City Røntgen",
PlaceLabel = "This is a place",
Sub_Title = "SubTitle",
Barcode = barcode,
BarcodeLabel = "Barcode Label",
Links = {link}
};

string eventXml = SerializeUtil.Serialize(@event);

Document document = new Document(
subject: "Your appointment",
fileType: "pdf",
path: @"c:\...\document.pdf",
dataType: eventXml
dataType: appointment
);
}

public void SendMessageWithExternalLinkMetadata()
{
var externalLink = new ExternalLink
var externalLink = new ExternalLink(absoluteUri: new Uri("https://example.org/loan-offer/uniqueCustomerId/"))
{
Url = "https://example.org/loan-offer/uniqueCustomerId/",
Description = "Please read the terms, and use the button above to accept them. The offer expires at 23/10-2018 10:00.",
Button_Text = "Accept offer",
ButtonText = "Accept offer",
Deadline = DateTime.Parse("2018-10-23T10:00:00+0200")
};

string linkXml = SerializeUtil.Serialize(externalLink);

var document = new Document(
subject: "Your appointment",
fileType: "pdf",
path: @"c:\...\document.pdf",
dataType: linkXml
dataType: externalLink
);

// Create Message and send using the client as specified in other examples.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.DataTypes.Core" Version="3.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
Expand Down
8 changes: 4 additions & 4 deletions Digipost.Api.Client.Send.Tests/MessageActionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Digipost.Api.Client.Common.Utilities;
using System;
using Digipost.Api.Client.Common.Utilities;
using Digipost.Api.Client.DataTypes.Core;
using Digipost.Api.Client.Send.Actions;
using Digipost.Api.Client.Tests;
Expand Down Expand Up @@ -28,10 +29,9 @@ public void ReturnsCorrectDataForMessage()
[Fact]
public void SerializedXmlContainsDataType()
{
ExternalLink externalLink = new ExternalLink {Url = "https://digipost.no"};
string linkXml = SerializeUtil.Serialize(externalLink);
ExternalLink externalLink = new ExternalLink(new Uri("https://digipost.no"));

var message = DomainUtility.GetSimpleMessageWithRecipientById(DomainUtility.GetDocument(linkXml));
var message = DomainUtility.GetSimpleMessageWithRecipientById(DomainUtility.GetDocument(externalLink));

var action = new MessageAction(message);
var content = action.RequestContent;
Expand Down
1 change: 1 addition & 0 deletions Digipost.Api.Client.Send/Digipost.Api.Client.Send.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.DataTypes.Core" Version="4.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<ProjectReference Include="..\Digipost.Api.Client.Common\Digipost.Api.Client.Common.csproj">
<Project>{CD338E5A-1ED0-4331-B34E-8292FA8E387B}</Project>
Expand Down
11 changes: 6 additions & 5 deletions Digipost.Api.Client.Send/Document.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.DataTypes.Core;

namespace Digipost.Api.Client.Send
{
Expand All @@ -14,7 +15,7 @@ public class Document : IDocument
/// <param name="smsNotification">Optional notification to receiver of message via SMS. </param>
/// <param name="dataType">Optional metadata for enriching the document when viewed in Digipost</param>
public Document(string subject, string fileType, byte[] contentBytes, AuthenticationLevel authenticationLevel = AuthenticationLevel.Password,
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, string dataType = null)
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, IDigipostDataType dataType = null)
{
Guid = System.Guid.NewGuid().ToString();
Subject = subject;
Expand All @@ -34,7 +35,7 @@ public Document(string subject, string fileType, byte[] contentBytes, Authentica
/// <param name="smsNotification">Optional notification to receiver of message via SMS. </param>
/// <param name="dataType">Optional metadata for enriching the document when viewed in Digipost</param>
public Document(string subject, string fileType, Stream documentStream, AuthenticationLevel authenticationLevel = AuthenticationLevel.Password,
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, string dataType = null)
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, IDigipostDataType dataType = null)
: this(subject, fileType, new byte[] { }, authenticationLevel, sensitivityLevel, smsNotification, dataType)
{
ContentBytes = ExtractBytesFromStream(documentStream);
Expand All @@ -48,7 +49,7 @@ public Document(string subject, string fileType, Stream documentStream, Authenti
/// <param name="smsNotification">Optional notification to receiver of message via SMS. </param>
/// <param name="dataType">Optional metadata for enriching the document when viewed in Digipost</param>
public Document(string subject, string fileType, string path, AuthenticationLevel authenticationLevel = AuthenticationLevel.Password,
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, string dataType = null)
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, IDigipostDataType dataType = null)
: this(subject, fileType, new byte[] { }, authenticationLevel, sensitivityLevel, smsNotification, dataType)
{
ContentBytes = ExtractBytesFromPath(path);
Expand All @@ -61,7 +62,7 @@ public Document(string subject, string fileType, string path, AuthenticationLeve
/// <param name="smsNotification">Optional notification to receiver of message via SMS. </param>
/// <param name="dataType">Optional metadata for enriching the document when viewed in Digipost</param>
internal Document(string subject, string fileType, AuthenticationLevel authenticationLevel = AuthenticationLevel.Password,
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, string dataType = null)
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, IDigipostDataType dataType = null)
: this(subject, fileType, new byte[] { }, authenticationLevel, sensitivityLevel, smsNotification, dataType)
{
}
Expand All @@ -82,7 +83,7 @@ internal Document(string subject, string fileType, AuthenticationLevel authentic

public byte[] ContentBytes { get; set; }

public string DataType { get; set; }
public IDigipostDataType DataType { get; set; }

private static byte[] ExtractBytesFromPath(string path)
{
Expand Down
6 changes: 3 additions & 3 deletions Digipost.Api.Client.Send/IDocument.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.DataTypes.Core;

namespace Digipost.Api.Client.Send
{
Expand Down Expand Up @@ -45,6 +45,6 @@ public interface IDocument
/// <summary>
/// Optional metadata to enrich the document in Digipost. See https://github.com/digipost/digipost-data-types for valid data-types.
/// </summary>
string DataType { get; set; }
IDigipostDataType DataType { get; set; }
}
}
5 changes: 1 addition & 4 deletions Digipost.Api.Client.Send/SendDataTransferObjectConverter.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.Xml;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.Common.Extensions;
Expand Down Expand Up @@ -76,11 +75,9 @@ internal static V8.Document ToDataTransferObject(this IDocument document)

if (document.DataType != null)
{
var xmldoc = new XmlDocument();
xmldoc.LoadXml(document.DataType);
documentDto.Data_Type = new Data_Type()
{
Any = xmldoc.DocumentElement
Any = document.DataType.ToXmlDocument().DocumentElement
};
}

Expand Down
1 change: 0 additions & 1 deletion Digipost.Api.Client.Tests/Digipost.Api.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="CompareNETObjects" Version="4.66.0" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.DataTypes.Core" Version="3.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
Expand Down
3 changes: 2 additions & 1 deletion Digipost.Api.Client.Tests/DomainUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Digipost.Api.Client.Common.Identify;
using Digipost.Api.Client.Common.Print;
using Digipost.Api.Client.Common.Recipient;
using Digipost.Api.Client.DataTypes.Core;
using Digipost.Api.Client.Resources.Content;
using Digipost.Api.Client.Send;
using V8;
Expand Down Expand Up @@ -101,7 +102,7 @@ public static IMessage GetSimpleMessageWithRecipientByNameAndAddress()
return new Send.Message(GetSender(), GetRecipientByNameAndAddress(), GetDocument());
}

public static IDocument GetDocument(string dataType = null)
public static IDocument GetDocument(IDigipostDataType dataType = null)
{
return new Document("simple-document-dotnet", "pdf", ContentResource.Hoveddokument.Pdf())
{
Expand Down
4 changes: 2 additions & 2 deletions 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.Tasks;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Entrypoint;
using Digipost.Api.Client.Common.Enums;
Expand All @@ -12,6 +11,7 @@
using Digipost.Api.Client.Common.Search;
using Digipost.Api.Client.Common.SenderInfo;
using Digipost.Api.Client.Common.Utilities;
using Digipost.Api.Client.DataTypes.Core;
using Digipost.Api.Client.Send;
using Digipost.Api.Client.Tests.Utilities;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -76,7 +76,7 @@ public ClientSmokeTestHelper Create_message_with_primary_document()
return this;
}

public ClientSmokeTestHelper CreateMessageWithPrimaryDataTypeDocument(string dataType)
public ClientSmokeTestHelper CreateMessageWithPrimaryDataTypeDocument(IDigipostDataType dataType)
{
_primary = DomainUtility.GetDocument(dataType);
return this;
Expand Down
35 changes: 20 additions & 15 deletions Digipost.Api.Client.Tests/Smoke/ClientSmokeTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.Common.Utilities;
using Digipost.Api.Client.DataTypes.Core;
using Digipost.Api.Client.Send;
using Digipost.Api.Client.Tests.Utilities;
Expand Down Expand Up @@ -66,6 +65,21 @@ public void Can_send_document_digipost_user()
.Expect_message_to_have_status(MessageStatus.Delivered);
}

[Fact(Skip = "SmokeTest")]
public void Can_send_invoice_digipost_user()
{
var invoice = new Invoice(dueDate: DateTime.Today.AddDays(14), sum: new decimal(100.21), creditorAccount: "2593143xxxx")
{
Kid = "123123123"
};

_client
.CreateMessageWithPrimaryDataTypeDocument(invoice)
.To_Digital_Recipient()
.SendMessage()
.Expect_message_to_have_status(MessageStatus.Delivered);
}

[Fact(Skip = "SmokeTest")]
public void Can_send_direct_to_print()
{
Expand All @@ -91,23 +105,14 @@ public void Can_send_request_for_registration()
.Expect_document_events();
}

[Fact(Skip = "SmokeTest")]
public void Can_send_document_with_raw_datatype_to_digipost_user()
{
const string raw = "<?xml version=\"1.0\" encoding=\"utf-8\"?><externalLink xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://api.digipost.no/schema/datatypes\"><url>https://www.test.no</url><description>This was raw string</description></externalLink>";

_clientWithoutDataTypes
.CreateMessageWithPrimaryDataTypeDocument(raw)
.To_Digital_Recipient()
.SendMessage()
.Expect_message_to_have_status(MessageStatus.Delivered);
}

[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);
var externalLink = new ExternalLink(new Uri("https://www.test.no", UriKind.Absolute))
{
Description = "This is a link"
};
var linkXml = externalLink;

_client
.CreateMessageWithPrimaryDataTypeDocument(linkXml)
Expand Down
Loading

0 comments on commit 94ac9b1

Please sign in to comment.