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
89 changes: 79 additions & 10 deletions src/ServiceControl.UnitTests/API/APIApprovals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Web.Http.Controllers;
using System.Web.Http.Hosting;
using System.Web.Http.Routing;
Expand All @@ -20,16 +22,6 @@
[TestFixture]
class APIApprovals
{
[Test]
public void PublicClr()
{
var publicApi = typeof(Bootstrapper).Assembly.GeneratePublicApi(new ApiGeneratorOptions
{
ExcludeAttributes = new[] { "System.Reflection.AssemblyMetadataAttribute" }
});
Approver.Verify(publicApi);
}

[Test]
public void RootPathValue()
{
Expand All @@ -46,6 +38,83 @@ public void RootPathValue()
Approver.Verify(result.Content);
}

[Test]
public void HttpApiRoutes()
{
var httpApiMethods = GetControllerRoutes()
.Select(pair =>
{
var type = pair.Method.DeclaringType;
var httpMethods = pair.Method.GetCustomAttributes(true)
.OfType<IActionHttpMethodProvider>()
.SelectMany(att => att.HttpMethods.Select(m => m.Method))
.Distinct()
.OrderBy(httpMethod => httpMethod);

if (!httpMethods.Any())
{
throw new Exception($"Method {type.FullName}:{pair.Method.Name} has Route attribute but no method attribute like HttpGet.");
}

var parametersString = string.Join(", ", pair.Method.GetParameters().Select(p => $"{PrettyTypeName(p.ParameterType)} {p.Name}"));
var methodSignature = $"{type.FullName}:{pair.Method.Name}({parametersString})";

return new
{
MethodSignature = methodSignature,
HttpMethods = string.Join("/", httpMethods),
Route = pair.Route.Template
};
})
.OrderBy(x => x.Route).ThenBy(x => x.HttpMethods)
.ToArray();

var builder = new StringBuilder();
foreach (var item in httpApiMethods)
{
builder.AppendLine($"{item.HttpMethods} /{item.Route} => {item.MethodSignature}");
}
var httpApi = builder.ToString();
Console.Write(httpApi);

Approver.Verify(httpApi);
}

IEnumerable<(MethodInfo Method, IHttpRouteInfoProvider Route)> GetControllerRoutes()
{
var controllers = typeof(Program).Assembly.GetTypes()
.Where(t => typeof(IHttpController).IsAssignableFrom(t));

foreach (var type in controllers)
{
foreach (var methodInfo in type.GetMethods())
{
var routeAtts = methodInfo.GetCustomAttributes(true).OfType<IHttpRouteInfoProvider>();
foreach (var routeAtt in routeAtts)
{
yield return (methodInfo, routeAtt);
}
}
}
}

static string PrettyTypeName(Type t)
{
if (t.IsArray)
{
return PrettyTypeName(t.GetElementType()) + "[]";
}

if (t.IsGenericType)
{
return string.Format("{0}<{1}>",
t.Name.Substring(0, t.Name.LastIndexOf("`", StringComparison.InvariantCulture)),
string.Join(", ", t.GetGenericArguments().Select(PrettyTypeName)));
}

return t.Name;
}

[Test]
public void TransportNames()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
GET / => ServiceControl.Infrastructure.WebApi.RootController:Urls()
GET /archive/groups/id/{groupId} => ServiceControl.MessageFailures.Api.ArchiveMessagesController:GetGroup(String groupId)
GET /configuration => ServiceControl.Infrastructure.WebApi.RootController:Config()
GET /configuration/remotes => ServiceControl.Infrastructure.WebApi.RootController:RemoteConfig()
GET /connection => ServiceControl.Connection.ConnectionController:GetConnectionDetails()
GET /conversations/{conversationid} => ServiceControl.CompositeViews.Messages.GetMessagesByConversationController:Messages(String conversationId)
GET /customchecks => ServiceControl.CustomChecks.CustomCheckController:CustomChecks(String status)
DELETE /customchecks/{id} => ServiceControl.CustomChecks.CustomCheckController:Delete(Guid id)
POST /edit/{failedmessageid} => ServiceControl.MessageFailures.Api.EditFailedMessagesController:Edit(String failedMessageId, EditMessageModel edit)
GET /edit/config => ServiceControl.MessageFailures.Api.EditFailedMessagesController:Config()
GET /endpoints => ServiceControl.Monitoring.EndpointsMonitoringController:Endpoints()
OPTIONS /endpoints => ServiceControl.Monitoring.EndpointsMonitoringController:GetSupportedOperations()
GET /endpoints/{endpoint}/audit-count => ServiceControl.CompositeViews.Messages.GetMessagesController:GetEndpointAuditCounts(String endpoint)
GET /endpoints/{endpoint}/messages => ServiceControl.CompositeViews.Messages.GetMessagesController:MessagesForEndpoint(String endpoint)
GET /endpoints/{endpoint}/messages/search => ServiceControl.CompositeViews.Messages.GetMessagesController:Search(String endpoint, String q)
GET /endpoints/{endpoint}/messages/search/{keyword} => ServiceControl.CompositeViews.Messages.GetMessagesController:SearchByKeyword(String endpoint, String keyword)
DELETE /endpoints/{endpointId} => ServiceControl.Monitoring.EndpointsMonitoringController:DeleteEndpoint(Guid endpointId)
PATCH /endpoints/{endpointId} => ServiceControl.Monitoring.EndpointsMonitoringController:Foo(Guid endpointId, EndpointUpdateModel data)
GET /endpoints/{endpointname}/errors => ServiceControl.MessageFailures.Api.GetAllErrorsController:ErrorsByEndpointName(String endpointName)
GET /endpoints/known => ServiceControl.Monitoring.EndpointsMonitoringController:KnownEndpoints()
GET /errors => ServiceControl.MessageFailures.Api.GetAllErrorsController:ErrorsGet()
HEAD /errors => ServiceControl.MessageFailures.Api.GetAllErrorsController:ErrorsHead()
POST /errors/{endpointname}/retry/all => ServiceControl.MessageFailures.Api.RetryMessagesController:RetryAllByEndpoint(String endpointName)
GET /errors/{failedmessageid:guid} => ServiceControl.MessageFailures.Api.GetErrorByIdController:ErrorBy(Guid failedMessageId)
POST /errors/{failedmessageid}/retry => ServiceControl.MessageFailures.Api.RetryMessagesController:RetryMessageBy(String failedMessageId)
PATCH /errors/{from}...{to}/unarchive => ServiceControl.MessageFailures.Api.UnArchiveMessagesController:Unarchive(String from, String to)
PATCH/POST /errors/{messageid}/archive => ServiceControl.MessageFailures.Api.ArchiveMessagesController:Archive(String messageId)
PATCH/POST /errors/archive => ServiceControl.MessageFailures.Api.ArchiveMessagesController:ArchiveBatch(List<String> messageIds)
GET /errors/groups/{classifier?} => ServiceControl.MessageFailures.Api.ArchiveMessagesController:GetArchiveMessageGroups(String classifier)
GET /errors/last/{failedmessageid:guid} => ServiceControl.MessageFailures.Api.GetErrorByIdController:ErrorLastBy(Guid failedMessageId)
POST /errors/queues/{queueaddress}/retry => ServiceControl.MessageFailures.Api.RetryMessagesController:RetryAllBy(String queueAddress)
GET /errors/queues/addresses => ServiceControl.MessageFailures.Api.QueueAddressController:GetAddresses()
GET /errors/queues/addresses/search/{search} => ServiceControl.MessageFailures.Api.QueueAddressController:GetAddressesBySearchTerm(String search)
POST /errors/retry => ServiceControl.MessageFailures.Api.RetryMessagesController:RetryAllBy(List<String> messageIds)
POST /errors/retry/all => ServiceControl.MessageFailures.Api.RetryMessagesController:RetryAll()
GET /errors/summary => ServiceControl.MessageFailures.Api.GetAllErrorsController:ErrorsSummary()
PATCH /errors/unarchive => ServiceControl.MessageFailures.Api.UnArchiveMessagesController:Unarchive(List<String> ids)
GET /eventlogitems => ServiceControl.EventLog.EventLogApiController:Items()
GET /heartbeats/stats => ServiceControl.Monitoring.EndpointsMonitoringController:HeartbeatStats()
GET /instance-info => ServiceControl.Infrastructure.WebApi.RootController:Config()
GET /license => ServiceControl.Licensing.LicenseController:License(Nullable<Boolean> refresh)
GET /messages => ServiceControl.CompositeViews.Messages.GetMessagesController:Messages()
GET /messages/{*catchAll} => ServiceControl.CompositeViews.Messages.GetMessagesController:CatchAll(String catchAll)
GET /messages/{id}/body => ServiceControl.CompositeViews.Messages.GetMessagesController:Get(String id)
GET /messages/search => ServiceControl.CompositeViews.Messages.GetMessagesController:Search(String q)
GET /messages/search/{keyword} => ServiceControl.CompositeViews.Messages.GetMessagesController:SearchByKeyWord(String keyword)
GET /notifications/email => ServiceControl.Notifications.Api.NotificationsController:GetEmailNotificationsSettings(HttpRequestMessage request)
POST /notifications/email => ServiceControl.Notifications.Api.NotificationsController:UpdateSettings(UpdateEmailNotificationsSettingsRequest request)
POST /notifications/email/test => ServiceControl.Notifications.Api.NotificationsController:SendTestEmail()
POST /notifications/email/toggle => ServiceControl.Notifications.Api.NotificationsController:ToggleEmailNotifications(ToggleEmailNotifications request)
PATCH /pendingretries/queues/resolve => ServiceControl.MessageFailures.Api.ResolveMessagesController:ResolveByQueue(ResolveRequest request)
POST /pendingretries/queues/retry => ServiceControl.MessageFailures.Api.PendingRetryMessagesController:RetryBy(PendingRetryRequest request)
PATCH /pendingretries/resolve => ServiceControl.MessageFailures.Api.ResolveMessagesController:ResolveBy(ResolveRequest request)
POST /pendingretries/retry => ServiceControl.MessageFailures.Api.PendingRetryMessagesController:RetryBy(List<String> ids)
GET /recoverability/classifiers => ServiceControl.Recoverability.API.FailureGroupsController:GetSupportedClassifiers()
GET /recoverability/groups/{classifier?} => ServiceControl.Recoverability.API.FailureGroupsController:GetAllGroups(String classifierFilter, String classifier)
DELETE /recoverability/groups/{groupid}/comment => ServiceControl.Recoverability.API.FailureGroupsController:DeleteComment(String groupId)
POST /recoverability/groups/{groupid}/comment => ServiceControl.Recoverability.API.FailureGroupsController:EditComment(String groupId, String comment)
GET /recoverability/groups/{groupId}/errors => ServiceControl.Recoverability.API.FailureGroupsController:GetGroupErrors(String groupId)
HEAD /recoverability/groups/{groupId}/errors => ServiceControl.Recoverability.API.FailureGroupsController:GetGroupErrorsCount(String groupId)
POST /recoverability/groups/{groupId}/errors/archive => ServiceControl.Recoverability.API.FailureGroupsArchiveController:ArchiveGroupErrors(String groupId)
POST /recoverability/groups/{groupId}/errors/retry => ServiceControl.Recoverability.API.FailureGroupsRetryController:ArchiveGroupErrors(String groupId)
POST /recoverability/groups/{groupId}/errors/unarchive => ServiceControl.Recoverability.API.FailureGroupsUnarchiveController:UnarchiveGroupErrors(String groupId)
GET /recoverability/groups/id/{groupId} => ServiceControl.Recoverability.API.FailureGroupsController:GetGroup(String groupId)
POST /recoverability/groups/reclassify => ServiceControl.Recoverability.API.FailureGroupsController:ReclassifyErrors()
GET /recoverability/history => ServiceControl.Recoverability.API.FailureGroupsController:GetRetryHistory()
DELETE /recoverability/unacknowledgedgroups/{groupId} => ServiceControl.Recoverability.API.UnacknowledgedGroupsController:AcknowledgeOperation(String groupId)
HEAD /redirect => ServiceControl.MessageRedirects.Api.MessageRedirectsController:CountRedirects()
GET /redirects => ServiceControl.MessageRedirects.Api.MessageRedirectsController:Redirects()
POST /redirects => ServiceControl.MessageRedirects.Api.MessageRedirectsController:NewRedirects(MessageRedirectRequest request)
DELETE /redirects/{messageredirectid:guid} => ServiceControl.MessageRedirects.Api.MessageRedirectsController:DeleteRedirect(Guid messageRedirectId)
PUT /redirects/{messageredirectid:guid} => ServiceControl.MessageRedirects.Api.MessageRedirectsController:UpdateRedirect(Guid messageRedirectId, MessageRedirectRequest request)
GET /sagas/{id} => ServiceControl.SagaAudit.SagasController:Sagas(Guid id)
Loading