Skip to content

Commit

Permalink
Merge pull request #8 from wedoit-io/mail-attachments
Browse files Browse the repository at this point in the history
Mail attachments
  • Loading branch information
exalted authored Dec 19, 2016
2 parents a61fc0e + b2a4549 commit 77d01c7
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Apexnet.Dispatch.Api.Client</id>
<version>0.6.0</version>
<version>0.7.0</version>
<authors>Ali Servet Donmez</authors>
<projectUrl>https://github.com/apex-net/hermes</projectUrl>
<projectUrl>https://github.com/wedoit-io/hermes</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Dispatch API Client Library</description>
<dependencies>
<dependency id="Apexnet.Dispatch.Api.Models" version="0.2.0" />
<dependency id="Apexnet.Dispatch.Api.Models" version="0.4.0" />
<dependency id="NextCommon.Http" version="0.0.1" />
</dependencies>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Apexnet.Dispatch.Api.Models</id>
<version>0.3.0</version>
<version>0.4.0</version>
<authors>Ali Servet Donmez</authors>
<projectUrl>https://github.com/apex-net/hermes</projectUrl>
<projectUrl>https://github.com/wedoit-io/hermes</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Dispatch API Models Library</description>
<dependencies>
<dependency id="Apexnet.JobQueue.Models" version="0.2.0" />
<dependency id="Apexnet.Messaging.Models" version="0.3.0" />
<dependency id="Apexnet.Messaging.Models" version="0.4.0" />
</dependencies>
</metadata>
<files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Apexnet.Messaging.Models</id>
<version>0.3.0</version>
<version>0.4.0</version>
<authors>Ali Servet Donmez</authors>
<projectUrl>https://github.com/apex-net/hermes</projectUrl>
<projectUrl>https://github.com/wedoit-io/hermes</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Messaging Models Library</description>
</metadata>
Expand Down
42 changes: 42 additions & 0 deletions src/Dispatch.Api.Client.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Dispatch.Api.Client.Tests
{
using System;
using System.IO;
using Apexnet.Dispatch.Api;
using Apexnet.Messaging.Http;
using Apexnet.Messaging.Mail;
Expand Down Expand Up @@ -62,6 +63,23 @@ public async void Test_Delete()
Assert.True(result);
}

[Fact]
[UsedImplicitly]
public async void Test_MailAttachments()
{
var schedule = new DateTimeOffset(DateTime.Now);

var request = new ScheduledBundleRequest(schedule);

request.MailMessages.Add(NewMailMessageWithAttachments());

var response = await this.client.ScheduleAsync(request)
.ConfigureAwait(false);

Assert.NotNull(response.Id);
Assert.Equal(schedule, response.Schedule);
}

#region /// internal ///////////////////////////////////////////////////

private static MailMessage NewMailMessage()
Expand All @@ -76,6 +94,30 @@ private static MailMessage NewMailMessage()
return new MailMessage(AddressBook.Ali, AddressBook.AgendaSviluppo, Subject, Body, IsBodyHtml);
}

private static MailMessage NewMailMessageWithAttachments()
{
const string Subject = "Hermes: test";
const string Body =
"<h1>Titolo</h1>" +
"<p>Questa è una prova di <a href=\"https://github.com/Apex-net/hermes\">Hermes</a>.</p>" +
"<p>Ignorare, grazie.</p>";
const bool IsBodyHtml = true;

var attachment1 = new Attachment(
Convert.ToBase64String(File.ReadAllBytes(@"C:\Users\a.donmez\Desktop\prove firme foto\ddd.jpg")),
"ddd.jpg",
System.Net.Mime.MediaTypeNames.Image.Jpeg);
var attachment2 = new Attachment(
Convert.ToBase64String(File.ReadAllBytes(@"C:\Users\a.donmez\Desktop\prove firme foto\Admissions.pdf")),
"Admissions.pdf",
System.Net.Mime.MediaTypeNames.Application.Pdf);

var mailMessage = new MailMessage(AddressBook.Ali, AddressBook.AgendaSviluppo, Subject, Body, IsBodyHtml);
mailMessage.Attachments.Add(attachment1);
mailMessage.Attachments.Add(attachment2);
return mailMessage;
}

private static HttpRequestMessage NewHttpRequestMessage()
{
return new HttpRequestMessage("HEAD", "http://requestb.in/188o2xj1");
Expand Down
4 changes: 2 additions & 2 deletions src/Dispatch.Api.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyVersion("0.7.0.0")]
[assembly: AssemblyFileVersion("0.7.0.0")]
2 changes: 1 addition & 1 deletion src/Dispatch.Api.Models/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
6 changes: 6 additions & 0 deletions src/Hermes.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dispatch.Api.Client.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dispatch.Api.Client.Configuration", "Dispatch.Api.Client.Configuration\Dispatch.Api.Client.Configuration.csproj", "{F75DA666-3792-4A09-AC97-D0B9FB666A4E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Messaging.Tests", "Messaging.Tests\Messaging.Tests.csproj", "{823D024F-B46C-472D-A7FF-2B17D4DF1389}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -81,6 +83,10 @@ Global
{F75DA666-3792-4A09-AC97-D0B9FB666A4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F75DA666-3792-4A09-AC97-D0B9FB666A4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F75DA666-3792-4A09-AC97-D0B9FB666A4E}.Release|Any CPU.Build.0 = Release|Any CPU
{823D024F-B46C-472D-A7FF-2B17D4DF1389}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{823D024F-B46C-472D-A7FF-2B17D4DF1389}.Debug|Any CPU.Build.0 = Debug|Any CPU
{823D024F-B46C-472D-A7FF-2B17D4DF1389}.Release|Any CPU.ActiveCfg = Release|Any CPU
{823D024F-B46C-472D-A7FF-2B17D4DF1389}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
30 changes: 30 additions & 0 deletions src/Messaging.Models/Mail/Attachment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Apexnet.Messaging.Mail
{
public class Attachment
{
public Attachment(string content, string fileName, string mediaType)
{
this.Content = content;
this.FileName = fileName;
this.MediaType = mediaType;
}

/// <summary>
/// Base64 encoded byte stream
/// </summary>
public string Content { get; private set; }

/// <summary>
/// Filename, including the extension
/// </summary>
public string FileName { get; private set; }

/// <summary>
/// Media type (some are defined in `System.Net.Mime.MediaTypeNames.*`,
/// or you can specify any other media type)
///
/// See: https://www.iana.org/assignments/media-types/media-types.xhtml
/// </summary>
public string MediaType { get; private set; }
}
}
5 changes: 4 additions & 1 deletion src/Messaging.Models/Mail/MailMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private MailMessage(
this.Subject = subject;
this.Body = body;
this.IsBodyHtml = isBodyHtml;
this.Attachments = new List<Attachment>();
}

#endregion
Expand All @@ -44,5 +45,7 @@ private MailMessage(
public string Body { get; private set; }

public bool IsBodyHtml { get; private set; }

public List<Attachment> Attachments { get; private set; }
}
}
}
1 change: 1 addition & 0 deletions src/Messaging.Models/Messaging.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Http\HttpRequestMessage.cs" />
<Compile Include="Mail\Attachment.cs" />
<Compile Include="Mail\MailAddress.cs" />
<Compile Include="Mail\MailMessage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Messaging.Models/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
10 changes: 10 additions & 0 deletions src/Messaging.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<mailSettings>
<smtp from="">
<network defaultCredentials="false" host="smtp.gmail.com" password="Afer6!122" port="587" userName="service@apexnet.it" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
</configuration>
119 changes: 119 additions & 0 deletions src/Messaging.Tests/Messaging.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0-beta3-build1069\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0-beta3-build1069\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.1.0-beta3-build3029\build\portable-net45+dnxcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.1.0-beta3-build3029\build\portable-net45+dnxcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{823D024F-B46C-472D-A7FF-2B17D4DF1389}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Messaging.Tests</RootNamespace>
<AssemblyName>Messaging.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>1bbe7439</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3029, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.1.0-beta3-build3029\lib\portable-net45+dnxcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3029, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.1.0-beta3-build3029\lib\portable-net45+dnxcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Messaging.Models\Messaging.Models.csproj">
<Project>{f83db7a9-df28-4c13-a437-fdd691ab0da9}</Project>
<Name>Messaging.Models</Name>
</ProjectReference>
<ProjectReference Include="..\Messaging\Messaging.csproj">
<Project>{14f1bdca-d398-489c-aa01-cbc59736403b}</Project>
<Name>Messaging</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.1.0-beta3-build3029\build\portable-net45+dnxcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.1.0-beta3-build3029\build\portable-net45+dnxcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0-beta3-build1069\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0-beta3-build1069\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions src/Messaging.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Messaging.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Messaging.Tests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("371dd073-008a-4659-8121-cc47353caebf")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 77d01c7

Please sign in to comment.