Browse files

fixed tests, moved build out of csproj and into build script

  • Loading branch information...
1 parent a2bba73 commit 6893d441ecf33387e935fd6614a38407aad42527 @shiftbot shiftbot committed Mar 17, 2012
View
43 build.proj
@@ -1,17 +1,28 @@
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
- <UsingTask AssemblyFile=".\tools\xunit\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit" />
-
- <Target Name="Compile">
- <Message Text=" ===========Building Website===========" Importance="High" />
- <MSBuild Projects="./src/Ideastrike.sln" Properties="Configuration=$(Configuration)" />
- </Target>
-
-
- <Target Name="AppHarbor" DependsOnTargets="Compile">
- <Message Text="===========Testing AppHarbor Build===========" Importance="High" />
-
- <MSBuild Projects="./src/AppHarbor.sln" Properties="Configuration=$(Configuration)" />
- </Target>
-
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+ <UsingTask AssemblyFile=".\tools\xunit\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit" />
+
+ <Target Name="Compile">
+ <Message Text=" ===========Building Website===========" Importance="High" />
+ <MSBuild Projects="./src/Ideastrike.sln" Properties="Configuration=$(Configuration)" />
+ </Target>
+
+ <Target Name="Test" DependsOnTargets="Compile">
+
+ <Message Text="===========Tests===========" Importance="High" />
+
+ <ItemGroup>
+ <TestFiles Include=".\**\bin\$(Configuration)\*Tests.dll" />
+ </ItemGroup>
+
+ <xunit Assembly="@(TestFiles)" />
+ </Target>
+
+
+ <Target Name="AppHarbor" DependsOnTargets="Compile;Test">
+ <Message Text="===========Testing AppHarbor Build===========" Importance="High" />
+
+ <MSBuild Projects="./src/AppHarbor.sln" Properties="Configuration=$(Configuration)" />
+ </Target>
+
</Project>
View
33 tests/IdeaStrike.Tests/AdminModuleTests/when_an_authenticated_user_views_the_admin_page.cs
@@ -1,26 +1,23 @@
-using Ideastrike.Nancy.Models;
using Ideastrike.Nancy.Modules;
-using Moq;
using Nancy;
-using Nancy.Testing;
+using Nancy.Responses;
using Xunit;
namespace IdeaStrike.Tests.AdminModuleTests
{
- public class when_an_authenticated_user_views_the_admin_page : IdeaStrikeSpecBase<AdminModule>
- {
- public when_an_authenticated_user_views_the_admin_page() {
- EnableFormsAuth();
+ public class when_an_authenticated_user_views_the_admin_page : IdeaStrikeSpecBase<AdminModule>
+ {
+ public when_an_authenticated_user_views_the_admin_page()
+ {
+ SetView("Admin/Index", new HtmlResponse());
+ EnableFormsAuth();
+ Get("/admin", with => with.LoggedInUser(CreateMockUser("shiftkey")));
+ }
- Get("/admin", with => {
- with.LoggedInUser(CreateMockUser("shiftkey"));
- });
- }
-
- [Fact]
- public void it_should_set_the_status_code_to_ok()
- {
- Assert.Equal(HttpStatusCode.OK, Response.StatusCode);
- }
- }
+ [Fact]
+ public void it_should_set_the_status_code_to_ok()
+ {
+ Assert.Equal(HttpStatusCode.OK, Response.StatusCode);
+ }
+ }
}
View
28 tests/IdeaStrike.Tests/FeatureModuleTests/when_adding_a_new_feature.cs
@@ -5,20 +5,20 @@
namespace IdeaStrike.Tests.FeatureModuleTests
{
- // TODO: test that unauthenticated user cannot access resource
+ // TODO: test that unauthenticated user cannot access resource
- public class when_adding_a_new_feature : IdeaStrikeSpecBase<FeatureModule>
- {
- public when_adding_a_new_feature() {
- EnableFormsAuth();
- Post("/idea/0/feature", with => {
- with.LoggedInUser(CreateMockUser("shiftkey"));
- });
- }
+ public class when_adding_a_new_feature : IdeaStrikeSpecBase<FeatureModule>
+ {
+ public when_adding_a_new_feature()
+ {
+ EnableFormsAuth();
+ Post("/idea/0/feature", with => with.LoggedInUser(CreateMockUser("shiftkey")));
+ }
- [Fact]
- public void it_should_add_the_new_feature() {
- _Features.Verify(B => B.Add(0, It.IsAny<Feature>()));
- }
- }
+ [Fact]
+ public void it_should_add_the_new_feature()
+ {
+ _Features.Verify(B => B.Add(0, It.IsAny<Feature>()));
+ }
+ }
}
View
29 tests/IdeaStrike.Tests/FeatureModuleTests/when_an_unauthenticated_user_adds_a_features.cs
@@ -1,22 +1,21 @@
-using Ideastrike.Nancy.Models;
-using Ideastrike.Nancy.Modules;
-using Moq;
-using Nancy;
+using Ideastrike.Nancy.Modules;
using Nancy.Testing;
using Xunit;
namespace IdeaStrike.Tests.FeatureModuleTests
{
- public class when_an_unauthenticated_user_adds_a_features : IdeaStrikeSpecBase<FeatureModule>
- {
- public when_an_unauthenticated_user_adds_a_features() {
- EnableFormsAuth();
- Post("/idea/0/feature");
- }
+ public class when_an_unauthenticated_user_adds_a_features : IdeaStrikeSpecBase<FeatureModule>
+ {
+ public when_an_unauthenticated_user_adds_a_features()
+ {
+ EnableFormsAuth();
+ Post("/idea/0/feature");
+ }
- [Fact]
- public void it_should_redirect_to_the_login_page() {
- Response.ShouldHaveRedirectedTo("/login");
- }
- }
+ [Fact]
+ public void it_should_redirect_to_the_login_page()
+ {
+ Response.ShouldHaveRedirectedTo("/login");
+ }
+ }
}
View
25 tests/IdeaStrike.Tests/HomeModuleTests/when_viewing_the_home_page.cs
@@ -1,19 +1,22 @@
using Ideastrike.Nancy.Modules;
using Nancy;
-using Nancy.Testing;
+using Nancy.Responses;
using Xunit;
namespace IdeaStrike.Tests.HomeModuleTests
{
- public class when_viewing_the_home_page : IdeaStrikeSpecBase<HomeModule>
- {
- public when_viewing_the_home_page() {
- Get("/");
- }
+ public class when_viewing_the_home_page : IdeaStrikeSpecBase<HomeModule>
+ {
+ public when_viewing_the_home_page()
+ {
+ SetView("Home/Index", new HtmlResponse());
+ Get("/");
+ }
- [Fact]
- public void it_should_set_the_status_code_to_ok_for_the_home_page() {
- Assert.Equal(HttpStatusCode.OK, Response.StatusCode);
- }
- }
+ [Fact]
+ public void it_should_set_the_status_code_to_ok_for_the_home_page()
+ {
+ Assert.Equal(HttpStatusCode.OK, Response.StatusCode);
+ }
+ }
}
View
3 tests/IdeaStrike.Tests/IdeaModuleTests/when_viewing_the_idea_page.cs
@@ -1,6 +1,7 @@
using Ideastrike.Nancy.Models;
using Ideastrike.Nancy.Modules;
using Nancy;
+using Nancy.Responses;
using Xunit;
namespace IdeaStrike.Tests.IdeaModuleTests
@@ -11,6 +12,8 @@ public class when_viewing_the_idea_page : IdeaStrikeSpecBase<IdeaModule>
public when_viewing_the_idea_page()
{
+ SetView("Idea/Index", new HtmlResponse());
+
_Ideas.Setup(d => d.Get(_Idea.Id)).Returns(_Idea);
Get("/idea/0");
View
2 tests/IdeaStrike.Tests/IdeaStrike.Tests.csproj
@@ -117,6 +117,6 @@
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<UsingTask AssemblyFile="..\..\tools\xunit\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit" />
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Debug' AND $(NCRUNCH) == ''">
- <xunit Assembly="bin\debug\IdeaStrike.Tests.dll" />
+ <!--<xunit Assembly="bin\debug\IdeaStrike.Tests.dll" />-->
</Target>
</Project>
View
50 tests/IdeaStrike.Tests/IdeaStrikeSpecBase.cs
@@ -1,19 +1,19 @@
using System;
-using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
using System.Linq;
using System.Linq.Expressions;
-using System.Text;
using Ideastrike;
using Ideastrike.Nancy;
using Ideastrike.Nancy.Models;
using Ideastrike.Nancy.Models.Repositories;
using Moq;
using Nancy;
+using Nancy.Responses;
using Nancy.Testing;
-using System.Drawing;
-using System.IO;
-using System.Drawing.Imaging;
+using Nancy.ViewEngines;
namespace IdeaStrike.Tests
{
@@ -36,33 +36,36 @@ public class IdeaStrikeSpecBase<TModule> where TModule : NancyModule
protected Mock<IFeatureRepository> _Features = new Mock<IFeatureRepository>();
protected Mock<IActivityRepository> _Activity = new Mock<IActivityRepository>();
protected Mock<ISettingsRepository> _Settings = new Mock<ISettingsRepository>();
- //protected Mock<IdeastrikeContext> _Context = new Mock<IdeastrikeContext>();
protected Mock<IImageRepository> _Images = new Mock<IImageRepository>();
public IdeaStrikeSpecBase()
{
+ ViewFactory = new Mock<IViewFactory>();
+
Bootstrapper = new ConfigurableBootstrapper(with =>
{
with.Module<TModule>();
with.Dependencies(_Users.Object, _Ideas.Object, _Features.Object, _Activity.Object, _Settings.Object, _Images.Object);
with.DisableAutoRegistration();
with.NancyEngine<NancyEngine>();
+ with.ViewFactory(ViewFactory.Object);
with.RootPathProvider<CustomRootPathProvider>();
});
}
protected User CreateMockUser(string username)
{
- var user = new User {
- Id = Guid.NewGuid(),
- UserName = username,
- UserClaims = new Collection<UserClaim> {new UserClaim {Claim = new Claim {Name = "admin"}} }
- };
- _Users.Setup(d => d.Get(user.Id)).Returns(user);
- _Users.Setup(d => d.GetUserFromIdentifier(user.Id)).Returns(user);
- _Users.Setup(d => d.FindBy(It.IsAny<Expression<Func<User, bool>>>())).Returns(new[] { user }.AsQueryable());
- return user;
- }
+ var user = new User
+ {
+ Id = Guid.NewGuid(),
+ UserName = username,
+ UserClaims = new Collection<UserClaim> { new UserClaim { Claim = new Claim { Name = "admin" } } }
+ };
+ _Users.Setup(d => d.Get(user.Id)).Returns(user);
+ _Users.Setup(d => d.GetUserFromIdentifier(user.Id)).Returns(user);
+ _Users.Setup(d => d.FindBy(It.IsAny<Expression<Func<User, bool>>>())).Returns(new[] { user }.AsQueryable());
+ return user;
+ }
protected void EnableFormsAuth()
{
@@ -75,13 +78,12 @@ protected void EnableFormsAuth()
protected byte[] CreateImageBits()
{
- Bitmap img = new Bitmap(10, 10);
- Graphics imgData = Graphics.FromImage(img);
+ var img = new Bitmap(10, 10);
+ var imgData = Graphics.FromImage(img);
imgData.DrawLine(new Pen(Color.Blue), 0, 0, 10, 10);
-
byte[] imageBits = null;
- using (MemoryStream memoryStream = new MemoryStream())
+ using (var memoryStream = new MemoryStream())
{
img.Save(memoryStream, ImageFormat.Bmp);
imageBits = memoryStream.ToArray();
@@ -106,5 +108,13 @@ protected void Put(string path, Action<BrowserContext> browserContext = null)
Browser = new Browser(Bootstrapper);
Response = Browser.Put(path, browserContext);
}
+
+ public Mock<IViewFactory> ViewFactory { get; set; }
+
+ public void SetView(string path, HtmlResponse htmlResponse)
+ {
+ ViewFactory.Setup(v => v.RenderView(path, It.IsAny<object>(), It.IsAny<ViewLocationContext>()))
+ .Returns(htmlResponse);
+ }
}
}

0 comments on commit 6893d44

Please sign in to comment.