Browse Source

aaa

confirmation-email
J 11 years ago
parent
commit
f8583229ce
6 changed files with 111 additions and 22 deletions
  1. +27
    -0
      Sevomin.Tests/Controllers/FakeIdentity.cs
  2. +23
    -5
      Sevomin.Tests/Controllers/Job/NewJob.cs
  3. +34
    -0
      Sevomin.Tests/FakeDbContext.cs
  4. +12
    -15
      Sevomin.Tests/FakeJobRepository.cs
  5. +3
    -0
      Sevomin.Tests/Sevomin.Tests.csproj
  6. +12
    -2
      Sevomin.WebFrontend.Controllers/JobController.cs

+ 27
- 0
Sevomin.Tests/Controllers/FakeIdentity.cs View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace Sevomin.Tests.Controllers
{
public class FakeIdentity : IIdentity
{
public string AuthenticationType
{
get { throw new NotImplementedException(); }
}
public bool IsAuthenticated
{
get { return true; }
}
public string Name
{
get { return "test"; }
}
}
}

+ 23
- 5
Sevomin.Tests/Controllers/Job/NewJob.cs View File

@ -6,20 +6,38 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Rhino.Mocks;
using Sevomin.Models.Helpers;
using System.Web;
using System.Security.Principal;
namespace Sevomin.Tests.Controllers.Job
{
[TestClass]
public class NewJob
{
HttpContextBase fakeContext = MockRepository.GenerateStub<HttpContextBase>();
public JobController GetCUT()
{
JobController cut = new JobController();
return cut;
FakeJobRepository.Init();
fakeContext = MockRepository.GenerateStub<HttpContextBase>();
fakeContext.User = MockRepository.GenerateStub<IPrincipal>();
fakeContext.User.Stub(x => x.Identity).Return(new FakeIdentity());
JobController cut = new JobController(FakeJobRepository.Instance(),
MockRepository.GenerateMock<SevominUserManager>(FakeDbContext.Instance()), fakeContext);
return cut;
}
[TestMethod]
public void MyTestMethod()
{
}
[TestMethod]
public async void Returns_View_NewJob_JobController()
public async Task Returns_View_NewJob_JobController()
{
// Arrange
JobController cut = GetCUT();
@ -31,7 +49,7 @@ namespace Sevomin.Tests.Controllers.Job
}
[TestMethod]
public async void Returns_EmptyJobModel_NewJob_JobController()
public async Task Returns_EmptyJobModel_NewJob_JobController()
{
// Arrange
JobController cut = GetCUT();


+ 34
- 0
Sevomin.Tests/FakeDbContext.cs View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity.EntityFramework;
using Rhino.Mocks;
using Sevomin.Models;
namespace Sevomin.Tests
{
public class FakeDbContext
{
private static IdentityDbContext<User> _dbcontext;
static FakeDbContext()
{
Init();
}
internal static void Init()
{
_dbcontext = MockRepository.GenerateStub<IdentityDbContext<User>>("Test");
}
internal static IdentityDbContext<User> Instance()
{
return _dbcontext;
}
}
}

+ 12
- 15
Sevomin.Tests/FakeJobRepository.cs View File

@ -21,21 +21,18 @@ namespace Sevomin.Tests
internal static void Init()
{
//_Job = (new List<Job>() {
// new Job{ id = 1, Name = "A", TaskDefinitions = new List<TaskDefinition>()},
// new Job{ id = 2, Name = "B", TaskDefinitions = new List<TaskDefinition>() }
//}).AsQueryable();
//_JobRepository = MockRepository.GenerateStub<IJobRepository>();
//_JobRepository.Stub(x => x.Find(Arg<long>.Is.Anything))
// .WhenCalled(x => x.ReturnValue = _Job.FirstOrDefault(y => y.id == (long)x.Arguments[0]))
// .Return(new Job());
//_JobRepository.Stub(x => x.ListAll()).Return(_Job);
//_JobRepository.Stub(x => x.FindByUsername("new-mission"))
// .Return(null);
//_JobRepository.Stub(x => x.FindByUsername(Arg<string>.Is.Anything))
// .Return(new Job() { id = 1, Username = "test", Name = "A", TaskDefinitions = new List<TaskDefinition>() });
_Job = (new List<Job>() {
new Job{ Id = 1, AvalinId = "a", Avalin = new Avalin(){Id = "a", UserName="test"}, JobParameters = new List<JobParameter>(){new JobParameter{Id = 4}}},
new Job{ Id = 3, AvalinId = "b", Avalin = new Avalin(){Id = "b", UserName="B"}, JobParameters = new List<JobParameter>(){new JobParameter{Id = 4}}}
}).AsQueryable();
_JobRepository = MockRepository.GenerateStub<IJobRepository>();
_JobRepository.Stub(x => x.Find(Arg<long>.Is.Anything))
.WhenCalled(x => x.ReturnValue = _Job.FirstOrDefault(y => y.Id == (long)x.Arguments[0]))
.Return(new Job());
_JobRepository.Stub(x => x.ListAll()).Return(_Job);
}
internal static IJobRepository Instance()


+ 3
- 0
Sevomin.Tests/Sevomin.Tests.csproj View File

@ -52,6 +52,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath>
@ -74,7 +75,9 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Controllers\FakeIdentity.cs" />
<Compile Include="Controllers\Job\NewJob.cs" />
<Compile Include="FakeDbContext.cs" />
<Compile Include="FakeJobRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>


+ 12
- 2
Sevomin.WebFrontend.Controllers/JobController.cs View File

@ -9,6 +9,7 @@ using Sevomin.Models.Repositories;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Sevomin.Models.Helpers;
using System.Web;
namespace Sevomin.WebFrontend.Controllers
{
@ -16,16 +17,25 @@ namespace Sevomin.WebFrontend.Controllers
{
IJobRepository _JobRepository;
public SevominUserManager UserManager { get; private set; }
private HttpContextBase _httpContext;
public JobController()
: this(JobRepository.Current, new SevominUserManager(new UserStore<User>(SevominDbContext.Current)))
: this(JobRepository.Current,
new SevominUserManager(new UserStore<User>(SevominDbContext.Current)), null)
{
}
public JobController(IJobRepository jobRepository, SevominUserManager userManager)
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);
_httpContext = requestContext.HttpContext;
}
public JobController(IJobRepository jobRepository, SevominUserManager userManager, HttpContextBase httpContext)
{
_JobRepository = jobRepository;
UserManager = userManager;
_httpContext = httpContext;
}
public async Task<ActionResult> NewJob()


Loading…
Cancel
Save