Skip to content

Commit

Permalink
Added skeleton test project (xUnit)
Browse files Browse the repository at this point in the history
  • Loading branch information
Psypher9 committed Oct 8, 2018
1 parent e1ede58 commit e053b85
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 547 deletions.
519 changes: 0 additions & 519 deletions HubSpot.NET.Examples/ContactExample.txt

This file was deleted.

5 changes: 0 additions & 5 deletions HubSpot.NET.Examples/HubSpot.NET.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,5 @@
<Name>HubSpot.NET</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="ContactExample.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
13 changes: 13 additions & 0 deletions HubSpot.NET.Tests/Core/Abstracts/ApiRoutableTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HubSpot.NET.Tests.Core.Abstracts
{
public class ApiRoutableTests
{

}
}
20 changes: 20 additions & 0 deletions HubSpot.NET.Tests/HubSpot.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Api\" />
<Folder Include="Core\" />
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion HubSpot.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HubSpot.NET", "HubSpot.NET\HubSpot.NET.csproj", "{2D45B6F1-77AE-427E-846B-75BB380BE93B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HubSpot.NET", "HubSpot.NET\HubSpot.NET.csproj", "{2D45B6F1-77AE-427E-846B-75BB380BE93B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HubSpot.NET.Examples", "HubSpot.NET.Examples\HubSpot.NET.Examples.csproj", "{AE1AABCC-388E-43A3-B58D-5BD566C3438B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HubSpot.NET.Tests", "HubSpot.NET.Tests\HubSpot.NET.Tests.csproj", "{20F8999E-C5C4-4A76-9836-86A34DAA7224}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{AE1AABCC-388E-43A3-B58D-5BD566C3438B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE1AABCC-388E-43A3-B58D-5BD566C3438B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE1AABCC-388E-43A3-B58D-5BD566C3438B}.Release|Any CPU.Build.0 = Release|Any CPU
{20F8999E-C5C4-4A76-9836-86A34DAA7224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20F8999E-C5C4-4A76-9836-86A34DAA7224}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20F8999E-C5C4-4A76-9836-86A34DAA7224}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20F8999E-C5C4-4A76-9836-86A34DAA7224}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 0 additions & 2 deletions HubSpot.NET/Api/Company/CompanyListRequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ public class CompanySearchRequestOptions
[DataContract]
public class CompanySearchOffset
{

[DataMember(Name = "isPrimary")]
public bool IsPrimary { get; set; } = true;

[DataMember(Name = "companyId")]
public long CompanyId { get; set; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ public class SubscriptionStatusDetailHubSpotModel : IHubSpotModel
{
public SubscriptionStatusDetailHubSpotModel() { }

public SubscriptionStatusDetailHubSpotModel(long id, bool subscribed)
public SubscriptionStatusDetailHubSpotModel(long id, bool subscribed) : this()
{
Id = id;
Subscribed = subscribed;
}

/// <summary>
/// The basic SubscriptionStatusDetail, for use when GDPR compliance is not enabled on portal
/// The basic SubscriptionStatusDetail, for use when GDPR compliance is not enabled on portal
/// </summary>
/// <param name="id">The target subscription's ID</param>
/// <param name="subscribed">Whether or not the contact is subscribing (if false, they are unsubscribing)</param>
public SubscriptionStatusDetailHubSpotModel(long id, bool subscribed, OptState optState)
/// <param name="optState">The OptState of the contact for this subscription</param>
public SubscriptionStatusDetailHubSpotModel(long id, bool subscribed, OptState optState) : this(id, subscribed)
{
OptInState = OptStates.GetState(optState);
}
Expand All @@ -37,6 +38,7 @@ public SubscriptionStatusDetailHubSpotModel(long id, bool subscribed, OptState o
/// </summary>
/// <param name="id">The target subscription's ID</param>
/// <param name="subscribed">Whether or not the contact is subscribing (if false, they are unsubscribing)</param>
/// <param name="optState">The OptState of the contact for this subscription</param>
/// <param name="legalBasis">The legal basis on which the contact can be added to this subscription</param>
/// <param name="explanation">A brief explanation of why they should be subscribed</param>
public SubscriptionStatusDetailHubSpotModel(long id, bool subscribed, OptState optState, GDPRLegalBasis legalBasis, string explanation) : this(id, subscribed, optState)
Expand Down
17 changes: 6 additions & 11 deletions HubSpot.NET/Api/EmailSubscriptions/HubSpotEmailSubcriptionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public HubSpotEmailSubscriptionsApi(IHubSpotClient client)
/// Gets the available email subscription types available in the portal
/// </summary>
public SubscriptionTypeListHubSpotModel GetEmailSubscriptionTypes()
=> _client.Execute<SubscriptionTypeListHubSpotModel>(GetRoute<SubscriptionTypeListHubSpotModel>());
=> _client.Execute<SubscriptionTypeListHubSpotModel>(GetRoute());

/// <summary>
/// Gets a single subscription type filtered from the list of all subscriptions
Expand All @@ -39,24 +39,23 @@ public SubscriptionTypeHubSpotModel GetEmailSubscription(long id)
/// </summary>
/// <param name="email"></param>
public SubscriptionStatusHubSpotModel GetStatus(string email)
=> _client.Execute<SubscriptionStatusHubSpotModel>(GetRoute<SubscriptionTypeListHubSpotModel>(email));
=> _client.Execute<SubscriptionStatusHubSpotModel>(GetRoute(email));


/// <summary>
/// Gets the timeline of subscription events for the portal
/// Gets the timeline of subscription events for the portal
/// </summary>
/// <returns>An offset-based list of subscription change events.</returns>
public SubscriptionTimelineHubSpotModel GetChangesTimeline()
=> _client.Execute<SubscriptionTimelineHubSpotModel>(GetRoute<SubscriptionTimelineHubSpotModel>());

=> _client.Execute<SubscriptionTimelineHubSpotModel>(GetRoute<SubscriptionTimelineHubSpotModel>());

/// <summary>
/// Unsubscribe the given email address from ALL email
/// WARNING: There is no UNDO for this operation
/// </summary>
/// <param name="email"></param>
public void UnsubscribeAll(string email)
=> _client.ExecuteOnly(GetRoute<SubscriptionTypeListHubSpotModel>(email), new { unsubscribeFromAll = true }, Method.PUT);
=> _client.ExecuteOnly(GetRoute(email), new { unsubscribeFromAll = true }, Method.PUT);

/// <summary>
/// Unsubscribe the given email address from the given subscription type
Expand All @@ -66,12 +65,10 @@ public void UnsubscribeAll(string email)
/// <param name="id">The ID of the subscription type</param>
public void UnsubscribeFrom(string email, long id)
{
string path = GetRoute<SubscriptionTypeListHubSpotModel>(email);

SubscriptionStatusHubSpotModel model = new SubscriptionStatusHubSpotModel();
model.SubscriptionStatuses.Add(new SubscriptionStatusDetailHubSpotModel(id, false));

_client.ExecuteOnly(path, model, Method.PUT);
_client.ExecuteOnly(GetRoute(email), model, Method.PUT);
}

/// <summary>
Expand Down Expand Up @@ -115,8 +112,6 @@ public void SubscribeAll(string email, GDPRLegalBasis legalBasis, string explana
SendSubscriptionRequest(GetRoute(email), subRequest);
}



/// <summary>
/// Subscribes a contact to one subscription type by email. Can only be used when portal's GDPR compliance setting is turned off.
/// </summary>
Expand Down
23 changes: 17 additions & 6 deletions HubSpot.NET/Core/Abstracts/ApiRoutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ namespace HubSpot.NET.Core.Abstracts
public abstract class ApiRoutable
{
/// <summary>
/// The route to the HubSpot API appended directly after the base URI
/// The route to the HubSpot API appended directly after the base URI
/// </summary>
public virtual string MidRoute { get; protected set; } = string.Empty;

/// <summary>
/// Dictionary of Entity specific routes to be accessed by entity type
/// Dictionary of Entity specific routes to be accessed by entity type
/// </summary>
protected virtual Dictionary<Type, string> Routes { get; set; } = new Dictionary<Type, string>();

/// <summary>
/// Provides the route to an endpoint relative to the specified type key.
/// Provides the route to an endpoint relative to the specified type key.
/// </summary>
/// <typeparam name="T">The IHubSpotModel-based type key used for the route.</typeparam>
/// <returns></returns>
/// <returns>The full route for the DTO without parameters</returns>
public virtual string GetRoute<T>() where T : IHubSpotModel
{
string routeValue = TryGetRouteValue<T>();
Expand All @@ -35,13 +35,13 @@ public virtual string GetRoute<T>() where T : IHubSpotModel
/// Provides the route to the midroute endpoint for the DTO group.
/// This should be used when there is no need to add any parameters
/// </summary>
/// <returns>The midroute</returns>
/// <returns>The cleaned midroute</returns>
public virtual string GetRoute()
=> $"{MidRoute.TrimEnd('/')}";

/// <summary>
/// Provides the route to the midroute endpoint for the DTO group,
/// including the
/// including the route parameters
/// </summary>
/// <param name="param"></param>
/// <returns>The full route for the request</returns>
Expand All @@ -65,6 +65,12 @@ public virtual string GetRoute<T>(params string[] orderedRouteValues) where T: I
return $"{GetRoute<T>().TrimEnd('/')}/{combinedParams}";
}

/// <summary>
/// Maps a specialized route to a target type and adds the mapping
/// the consuming API's route dictionary
/// </summary>
/// <typeparam name="T">The target type to be used on this route</typeparam>
/// <param name="newRoute">The specialized route to be mapped</param>
public void AddRoute<T>(string newRoute) where T : IHubSpotModel
=> Routes.Add(typeof(T), newRoute);

Expand All @@ -76,6 +82,11 @@ public void AddRoute<T>(string newRoute) where T : IHubSpotModel
private string[] FilterRouteValues(string[] values)
=> values.Select(x => x.Trim('/')).ToArray();

/// <summary>
/// Reads through the DTO's route table to see if there is a specialized route for the target type
/// </summary>
/// <typeparam name="T">Target DTO type</typeparam>
/// <returns>The specialized route for the DTO type or <see cref="string.Empty"/></returns>
private string TryGetRouteValue<T>() where T : IHubSpotModel
=> Routes.ContainsKey(typeof(T)) ? Routes[typeof(T)] : string.Empty;
}
Expand Down
1 change: 1 addition & 0 deletions HubSpot.NET/HubSpot.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageTags>hubspot api wrapper c# contact company deal engagement properties crm</PackageTags>
<PackageReleaseNotes>0.5.1</PackageReleaseNotes>
<PackageId>SquaredUp.HubSpot.NET</PackageId>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>7.1</LangVersion>
Expand Down
7 changes: 7 additions & 0 deletions HubSpot.NET/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"HubSpot.NET": {
"commandName": "Project"
}
}
}

0 comments on commit e053b85

Please sign in to comment.