Skip to content

Commit

Permalink
License
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySkinner committed Jun 25, 2010
1 parent 5e64b17 commit 025af8a
Show file tree
Hide file tree
Showing 21 changed files with 647 additions and 77 deletions.
15 changes: 15 additions & 0 deletions GitAspx.5.1.ReSharper
Expand Up @@ -66,6 +66,21 @@
<XML>
<FormatSettings />
</XML>
<FileHeader Region="License"><![CDATA[Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx]]></FileHeader>
<GenerateMemberBody />
<Naming2>
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
Expand Down
43 changes: 31 additions & 12 deletions GitAspx.Tests/BaseTest.cs
@@ -1,12 +1,30 @@
#region License

// Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx

#endregion

namespace GitAspx.Tests {
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Web.Configuration;
using System.Xml.Linq;
using CassiniDev;
using NUnit.Framework;
using System.Linq;

[TestFixture]
public class BaseTest : CassiniDevServer {
Expand All @@ -24,7 +42,7 @@ public class BaseTest : CassiniDevServer {
ChangeRepo("C:\\Repositories");
}

private void ChangeRepo(string repoDir) {
void ChangeRepo(string repoDir) {
string path = "..\\..\\..\\GitAspx\\Web.config";

var doc = XDocument.Load(path);
Expand All @@ -38,26 +56,27 @@ public class BaseTest : CassiniDevServer {
protected HttpWebResponse Get(string url) {
try {
url = NormalizeUrl(url);
var request = (HttpWebRequest)WebRequest.Create(url);
return (HttpWebResponse)request.GetResponse();
var request = (HttpWebRequest) WebRequest.Create(url);
return (HttpWebResponse) request.GetResponse();
}
catch(WebException e) { //wtf, why does WebRequest throw for non-200 status codes?!
catch (WebException e) {
//wtf, why does WebRequest throw for non-200 status codes?!
return (HttpWebResponse) e.Response;
}
}

public HttpWebResponse Post(string url, string contentType = null) {
try {
url = NormalizeUrl(url);
var request = (HttpWebRequest)WebRequest.Create(url);
if(contentType!=null) {
var request = (HttpWebRequest) WebRequest.Create(url);
if (contentType != null) {
request.ContentType = contentType;
}
request.Method = "POST";
return (HttpWebResponse)request.GetResponse();
return (HttpWebResponse) request.GetResponse();
}
catch(WebException e) {
return (HttpWebResponse)e.Response;
catch (WebException e) {
return (HttpWebResponse) e.Response;
}
}
}
Expand Down
30 changes: 26 additions & 4 deletions GitAspx.Tests/InfoRefsControllerTests.cs
@@ -1,3 +1,23 @@
#region License

// Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx

#endregion

namespace GitAspx.Tests {
using System.IO;
using GitAspx.Controllers;
Expand All @@ -11,7 +31,10 @@ public class InfoRefsControllerTests {
[SetUp]
public void Setup() {
var dir = new DirectoryInfo("../../Repositories");
this.controller = new InfoRefsController(new RepositoryService(new AppSettings { ReceivePack = true, UploadPack = true, RepositoriesDirectory = dir })).FakeContxt();
controller =
new InfoRefsController(
new RepositoryService(new AppSettings {ReceivePack = true, UploadPack = true, RepositoriesDirectory = dir})).
FakeContxt();
}

[Test]
Expand All @@ -26,16 +49,15 @@ public class InfoRefsControllerTests {
body.ShouldContain("0000009514bf0836c3371b740ebad55fbda6223bd7940f20 HEAD");
body.ShouldContain("multi_ack_detailed");
*/ }
*/
}

[Test]
public void Gets_receive_pack_advertisement() {

}

[Test]
public void Returns_404_when_repository_not_found() {

}
}
}
22 changes: 20 additions & 2 deletions GitAspx.Tests/MainTests.cs
@@ -1,8 +1,26 @@
#region License

// Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx

#endregion

namespace GitAspx.Tests {
using System;
using System.Net;
using NUnit.Framework;
using System.Linq;

// These tests are largely ported from GRack.
// They are all in one file to ensure the webserver is only started once (slooow)
Expand Down
35 changes: 25 additions & 10 deletions GitAspx.Tests/MockHttpContext.cs
@@ -1,3 +1,23 @@
#region License

// Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx

#endregion

namespace GitAspx.Tests {
using System;
using System.Collections;
Expand All @@ -7,19 +27,18 @@ namespace GitAspx.Tests {
using Moq;

public class MockHttpContext : Mock<HttpContextBase> {

readonly Mock<HttpServerUtilityBase> server = new Mock<HttpServerUtilityBase>();

public MockHttpContext() {
HttpRequest = new HttpRequestMock();
HttpResponse = new HttpResponseMock();

Setup(c => c.Request).Returns(this.HttpRequest.Object);
Setup(c => c.Response).Returns(this.HttpResponse.Object);
Setup(c => c.Request).Returns(HttpRequest.Object);
Setup(c => c.Response).Returns(HttpResponse.Object);
Setup(x => x.Session).Returns(new MockSessionState());
Setup(x => x.Server).Returns(server.Object);
Setup(x => x.Items).Returns(new Hashtable());
this.SetupProperty(x => x.User);
SetupProperty(x => x.User);
}

public HttpRequestMock HttpRequest { get; private set; }
Expand All @@ -45,7 +64,6 @@ public class HttpRequestMock : Mock<HttpRequestBase> {
Setup(r => r.Form).Returns(form);
Setup(x => x.InputStream).Returns(inputStream);
}

}

public class HttpResponseMock : Mock<HttpResponseBase> {
Expand All @@ -57,14 +75,12 @@ public class HttpResponseMock : Mock<HttpResponseBase> {
Setup(x => x.OutputStream).Returns(outputStream);
SetupProperty(x => x.ContentType);
SetupProperty(x => x.StatusCode);
Setup(x => x.Write(It.IsAny<string>())).Callback(new Action<string>(s => {
writer.Write(s);
}));
Setup(x => x.Write(It.IsAny<string>())).Callback(new Action<string>(s => { writer.Write(s); }));
}
}

public class MockSessionState : HttpSessionStateBase {
private Hashtable hash = new Hashtable();
readonly Hashtable hash = new Hashtable();

public override object this[string name] {
get { return hash[name]; }
Expand All @@ -91,5 +107,4 @@ public class MockSessionState : HttpSessionStateBase {
hash.Clear();
}
}

}
24 changes: 22 additions & 2 deletions GitAspx.Tests/TestExtensions.cs
@@ -1,3 +1,23 @@
#region License

// Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx

#endregion

namespace GitAspx.Tests {
using System;
using System.IO;
Expand Down Expand Up @@ -36,10 +56,10 @@ public static class TestExtensions {
}

public static string[] SplitOnNewLine(this string str) {
return str.Split(new[] { "\n" }, StringSplitOptions.None);
return str.Split(new[] {"\n"}, StringSplitOptions.None);
}

public static T FakeContxt<T>(this T controller) where T:Controller {
public static T FakeContxt<T>(this T controller) where T : Controller {
var context = MockHttpContext.Create();
var cc = new ControllerContext(context, new RouteData(), controller);
controller.ControllerContext = cc;
Expand Down
36 changes: 26 additions & 10 deletions GitAspx/Controllers/BaseController.cs
@@ -1,13 +1,29 @@
using System.IO;
using System.Web.Mvc;
#region License

namespace GitAspx.Controllers
{
using System.Linq;
// Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx

#endregion

namespace GitAspx.Controllers {
using System.IO;
using System.Web.Mvc;
using GitAspx.Lib;

public class BaseController : Controller
{
public class BaseController : Controller {
public AppSettings AppSettings { get; set; }

protected string PktFlush() {
Expand All @@ -31,15 +47,15 @@ public class BaseController : Controller
}

protected bool HasAccess(Rpc rpc, bool checkContentType = false) {
if(checkContentType && Request.ContentType != string.Format("application/x-git-{0}-request", rpc.GetDescription())) {
if (checkContentType && Request.ContentType != string.Format("application/x-git-{0}-request", rpc.GetDescription())) {
return false;
}

if(rpc == Rpc.ReceivePack) {
if (rpc == Rpc.ReceivePack) {
return AppSettings.ReceivePack;
}

if(rpc == Rpc.UploadPack) {
if (rpc == Rpc.UploadPack) {
return AppSettings.UploadPack;
}

Expand Down

0 comments on commit 025af8a

Please sign in to comment.