Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes Unused Code #217

Merged
merged 5 commits into from
Jan 1, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TestResult.xml

# Visual Studio 2015 cache/options directory
.vs/
.vscode/

#SonarQube
.sonarqube/
Expand Down
23 changes: 0 additions & 23 deletions nupkg/Grapevine.nuspec

This file was deleted.

3 changes: 2 additions & 1 deletion src/Grapevine.Local/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class TestResource
[RestRoute(HttpMethod = HttpMethod.ALL, PathInfo = "^.*$")]
public IHttpContext LevelOne(IHttpContext context)
{
throw new Exception("Killing It!");
// throw new Exception("Killing It!");
return context;
}

[RestRoute]
Expand Down
1 change: 0 additions & 1 deletion src/Grapevine.Tests.Assembly/ToDoListRoutes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grapevine.Interfaces.Server;
using Grapevine.Server;
using Grapevine.Server.Attributes;
using Grapevine.Shared;

Expand Down
1 change: 0 additions & 1 deletion src/Grapevine.Tests.Assembly/UserRoutes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grapevine.Interfaces.Server;
using Grapevine.Server;
using Grapevine.Server.Attributes;
using Grapevine.Shared;

Expand Down
65 changes: 24 additions & 41 deletions src/Grapevine.Tests/Client/RestClientFacts.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
using System;
using System.Net;
using Grapevine.Client;
using Grapevine.Shared;
using Shouldly;
using Xunit;

namespace Grapevine.Tests.Client
{
public class RestClientFacts
{
public class Constructors
{
[Fact]
public void BaseInitialization()
{
const string baseurl = "http://localhost:1234/";

var client = new RestClient { Host = "localhost", Port = 1234, Scheme = UriScheme.Http };

client.BaseUrl.AbsoluteUri.ShouldBe(baseurl);
client.Cookies.ShouldNotBeNull();
client.Credentials.ShouldBeNull();
}
}

public class Execute
using System;
using Grapevine.Client;
using Grapevine.Shared;
using Shouldly;
using Xunit;

namespace Grapevine.Tests.Client
{
public class RestClientFacts
{
public class Constructors
{
[Fact]
public void ClientRunsTimeoutDelegateOnRequestTimeoutIfSet()
public void BaseInitialization()
{
var actionCalled = false;
Action updateActionCalled = () => actionCalled = true;

var client = new RestClient { RequestTimeoutAction = updateActionCalled,
Host = "localhost", Port = 1234, Scheme = UriScheme.Http };

var req = new RestRequest { Timeout = 1, ContentType = ContentType.MIME };
const string baseurl = "http://localhost:1234/";

client.Execute(req);
var client = new RestClient { Host = "localhost", Port = 1234, Scheme = UriScheme.Http };

actionCalled.ShouldBeTrue();
client.BaseUrl.AbsoluteUri.ShouldBe(baseurl);
client.Cookies.ShouldNotBeNull();
client.Credentials.ShouldBeNull();
}
}

public class Execute
{
[Fact]
public void ClientRethrowsExceptionIfNoTimeoutDelegateSetAndRequestTimesOut()
{
var client = new RestClient { Host = "localhost", Port = 1234, Scheme = UriScheme.Http };

var req = new RestRequest { Timeout = 1, ContentType = ContentType.MIME };

Should.Throw<WebException>(() => client.Execute(req));
Should.Throw<Exception>(() => client.Execute(req));
}
}
}
}
}
}
}
1 change: 0 additions & 1 deletion src/Grapevine.Tests/Mocks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Text;
using Grapevine.Interfaces.Server;
Expand Down
31 changes: 2 additions & 29 deletions src/Grapevine.Tests/Server/AdvancedRestServerFacts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net;
using Grapevine.Interfaces.Server;
using Grapevine.Interfaces.Server;
using Grapevine.Server;
using NSubstitute;
using Shouldly;
Expand All @@ -14,7 +13,7 @@ public void AuthenticationSchemeSelectorDelegateProperty()
{
var listener = Substitute.For<IHttpListener>();
var advanced = new AdvancedRestServer(listener);

var val = advanced.AuthenticationSchemeSelectorDelegate;
advanced.AuthenticationSchemeSelectorDelegate = val;

Expand All @@ -35,32 +34,6 @@ public void AuthenticationSchemesProperty()
listener.Received().AuthenticationSchemes = val;
}

//[Fact]
//public void ExtendedProtectionPolicyProperty()
//{
// var listener = Substitute.For<IHttpListener>();
// var advanced = new AdvancedRestServer(listener);

// var val = advanced.ExtendedProtectionPolicy;
// advanced.ExtendedProtectionPolicy = val;

// var temp = listener.Received().ExtendedProtectionPolicy;
// listener.Received().ExtendedProtectionPolicy = val;
//}

//[Fact]
//public void ExtendedProtectionSelectorDelegateProperty()
//{
// var listener = Substitute.For<IHttpListener>();
// var advanced = new AdvancedRestServer(listener);

// var val = advanced.ExtendedProtectionSelectorDelegate;
// advanced.ExtendedProtectionSelectorDelegate = val;

// var temp = listener.Received().ExtendedProtectionSelectorDelegate;
// listener.Received().ExtendedProtectionSelectorDelegate = val;
//}

[Fact]
public void IgnoreWriteExceptionsProperty()
{
Expand Down
3 changes: 1 addition & 2 deletions src/Grapevine.Tests/Server/HttpResponseExtensionsFacts.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using Grapevine.Interfaces.Server;
using Grapevine.Server;
Expand Down Expand Up @@ -120,7 +119,7 @@ public void SendsStatusCodeAndException()
{
const HttpStatusCode status = HttpStatusCode.EnhanceYourCalm;
var exception = new Exception("This is the exception message");

var bytes = GetBytes($"{exception.Message}{Environment.NewLine}<br>{Environment.NewLine}{exception.StackTrace}");

_response.ContentEncoding = Encoding.ASCII;
Expand Down
2 changes: 1 addition & 1 deletion src/Grapevine.Tests/Server/PublicFolderFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void NoParameters()
[Fact]
public void AbsolutePathShouldNotChange()
{
const string path = @"C:\temp\kjhgf";
string path = Path.Combine(Path.GetTempPath(), "kjhgf");

var folder = new PublicFolder(path);

Expand Down
2 changes: 1 addition & 1 deletion src/Grapevine.Tests/Server/RestServerExtensionsFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void StopsServer()
var stopped = new ManualResetEvent(false);
var port = PortFinder.FindNextLocalOpenPort(1234);

using (var server = new RestServer { Connections = 1, Port = port })
using (var server = new RestServer { Port = port })
{
server.OnAfterStop += () => { stopped.Set(); };

Expand Down
8 changes: 2 additions & 6 deletions src/Grapevine.Tests/Server/RestServerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using Grapevine.Exceptions.Server;
using Grapevine.Interfaces.Server;
using Grapevine.Interfaces.Shared;
using Grapevine.Server;
using Grapevine.Shared;
using Grapevine.Shared.Loggers;
using NSubstitute;
using Shouldly;
Expand All @@ -24,7 +21,6 @@ public void DefaultConfiguration()
{
using (var server = new RestServer())
{
server.Connections.ShouldBe(50);
server.EnableThrowingExceptions.ShouldBeFalse();
server.Host.ShouldBe("localhost");
server.IsListening.ShouldBeFalse();
Expand Down Expand Up @@ -773,9 +769,9 @@ public class CustomSettings : ServerSettings
public CustomSettings()
{
Port = "5555";
OnBeforeStart = () =>
BeforeStarting += (s) =>
{
UseHttps = true;
s.UseHttps = true;
};
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/Grapevine.Tests/Server/RouterFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ public void ExecutesAfterRouting()
context.WasRespondedTo.Returns(true); return ctx; });
routing.Add(route);

var router = new Router { After = ctx => { executionOrder.Add("after"); return ctx; } };
var router = new Router();
router.AfterRouting += ctx => {
executionOrder.Add("after");
};

router.Route(context, routing);

Expand Down Expand Up @@ -146,7 +149,8 @@ public void ExecutesBeforeRouting()
context.WasRespondedTo.Returns(true); return ctx; });
routing.Add(route);

var router = new Router { Before = ctx => { executionOrder.Add("before"); return ctx; } };
var router = new Router();
router.BeforeRouting += ctx => { executionOrder.Add("before"); };

router.Route(context, routing);

Expand Down
61 changes: 1 addition & 60 deletions src/Grapevine.Tests/Server/ServerSettingsFacts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Grapevine.Server;
Expand Down Expand Up @@ -31,65 +30,7 @@ public void DefaultConfiguration()
options.UseHttps.ShouldBeFalse();
options.Host.ShouldBe("localhost");
options.Port.ShouldBe("1234");
options.Connections.ShouldBe(50);
options.EnableThrowingExceptions.ShouldBeFalse();

options.OnAfterStart.ShouldBeNull();
options.OnBeforeStart.ShouldBeNull();

options.OnAfterStop.ShouldBeNull();
options.OnBeforeStop.ShouldBeNull();

options.OnStart.ShouldBeNull();
options.OnStop.ShouldBeNull();
}
}

public class OnStartProperty
{
[Fact]
public void IsSynonymForOnAfterStart()
{
var options = new ServerSettings();

Action action1 = () => { };
Action action2 = () => { };

options.OnStart = action1;

options.OnBeforeStart.ShouldBeNull();
options.OnAfterStart.ShouldBe(action1);
options.OnStart.ShouldBe(action1);

options.OnAfterStart = action2;

options.OnBeforeStart.ShouldBeNull();
options.OnAfterStart.ShouldBe(action2);
options.OnStart.ShouldBe(action2);
}
}

public class OnStopProperty
{
[Fact]
public void IsSynonymForOnAfterStop()
{
var options = new ServerSettings();

Action action1 = () => { };
Action action2 = () => { };

options.OnStop = action1;

options.OnBeforeStop.ShouldBeNull();
options.OnAfterStop.ShouldBe(action1);
options.OnStop.ShouldBe(action1);

options.OnAfterStop = action2;

options.OnBeforeStop.ShouldBeNull();
options.OnAfterStop.ShouldBe(action2);
options.OnStop.ShouldBe(action2);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Grapevine.Tests/Shared/ContentTypeFacts.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Grapevine.Shared;
using Shouldly;
using Xunit;
Expand Down
13 changes: 0 additions & 13 deletions src/Grapevine/Client/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public class RestClient : IRestClient
public CookieContainer Cookies { get; }
public ICredentials Credentials { get; set; }

private Action _requestTimeoutAction;

public Dictionary<WebExceptionStatus, WebExceptionHandler> WebExceptionHandlers;

public RestClient()
Expand All @@ -81,17 +79,6 @@ public RestClient()
WebExceptionHandlers = new Dictionary<WebExceptionStatus, WebExceptionHandler>();
}

[Obsolete("RequestTimeoutAction is deprecated, add an entry to WebExceptionHandlers instead.")]
public Action RequestTimeoutAction
{
get { return _requestTimeoutAction; }
set
{
_requestTimeoutAction = value;
WebExceptionHandlers[WebExceptionStatus.Timeout] = (client, request, exception) => _requestTimeoutAction();
}
}

public string Host
{
get { return Builder.Host; }
Expand Down
Loading