Skip to content

Commit

Permalink
Remove Church.Model
Browse files Browse the repository at this point in the history
  • Loading branch information
davevans committed Jul 31, 2014
1 parent 8be82b1 commit 487c174
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<ItemGroup>
<Compile Include="ChurchService.cs" />
<Compile Include="IChurchService.cs" />
<Compile Include="Model\Address.cs" />
<Compile Include="Model\Church.cs" />
<Compile Include="Model\Location.cs" />
<Compile Include="Model\TimeZone.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository\CoreContext.cs" />
<Compile Include="Repository\ModelMappings\AddressMappings.cs" />
Expand All @@ -63,10 +67,6 @@
<Project>{5ed93ccb-eff1-4d29-be10-433a8431cc27}</Project>
<Name>Church.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Church.Model\Church.Model.csproj">
<Project>{3563e57a-a00f-4d0b-8e02-099d3315d954}</Project>
<Name>Church.Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
4 changes: 2 additions & 2 deletions src/Church/Church.Components.Core/ChurchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public ChurchService(Repository.ICoreRepository coreRepository)
_coreRepository = coreRepository;
}

public Model.Core.Church GetById(int churchId)
public Model.Church GetById(int churchId)
{
return _coreRepository.GetById(churchId);
}

public void Add(Model.Core.Church church)
public void Add(Model.Church church)
{
_coreRepository.Add(church);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Church/Church.Components.Core/IChurchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface IChurchService
{
Model.Core.Church GetById(int churchId);
void Add(Model.Core.Church church);
Model.Church GetById(int churchId);
void Add(Model.Church church);
}
}
13 changes: 13 additions & 0 deletions src/Church/Church.Components.Core/Model/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Church.Components.Core.Model
{
public class Address
{
public int Id { get; set; }
public string Street1 { get; set; }
public string Street2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostCode { get; set; }
public string Country { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/Church/Church.Components.Core/Model/Church.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;

namespace Church.Components.Core.Model
{
public class Church
{
public int Id { get; set; }
public string Name { get; set; }

public int TimeZoneId { get; set; }
public virtual TimeZone TimeZone { get; set; }

public ICollection<Location> Locations { get; set; }

public Church()
{
Locations = new List<Location>();
}
}
}
15 changes: 15 additions & 0 deletions src/Church/Church.Components.Core/Model/Location.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Church.Components.Core.Model
{
public class Location
{
public int Id { get; set; }
public string Name { get; set; }


public int ChurchId { get; set; }
public virtual Church Church { get; set; }

public int AddressId { get; set; }
public Address Address { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/Church/Church.Components.Core/Model/TimeZone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Church.Components.Core.Model
{
public class TimeZone
{
public int Id { get; set; }
public string Name { get; set; }
}
}
3 changes: 1 addition & 2 deletions src/Church/Church.Components.Core/Repository/CoreContext.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Church.Common.Database;
using System.Data.Entity;
using Church.Components.Core.Repository.ModelMappings;
using ModelCore = Church.Model.Core;

namespace Church.Components.Core.Repository
{
public class CoreContext : BaseContext<CoreContext>
{
public DbSet<ModelCore.Church> Churches { get; set; }
public DbSet<Model.Church> Churches { get; set; }

protected override void OnModelCreating(DbModelBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public CoreRepository()
_dbContext = new CoreContext();
}

public Model.Core.Church GetById(int churchId)
public Model.Church GetById(int churchId)
{
return _dbContext.Churches
.Include(x => x.Locations.Select(a => a.Address))
.Include(x => x.TimeZone)
.FirstOrDefault(x => x.Id == churchId);
}

public void Add(Model.Core.Church church)
public void Add(Model.Church church)
{
_dbContext.Churches.Add(church);
_dbContext.SaveChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface ICoreRepository
{
Model.Core.Church GetById(int churchId);
void Add(Model.Core.Church church);
Model.Church GetById(int churchId);
void Add(Model.Church church);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Data.Entity.ModelConfiguration;
using Church.Model.Core;
using Church.Components.Core.Model;

namespace Church.Components.Core.Repository.ModelMappings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Church.Components.Core.Repository.ModelMappings
{
public class ChurchMappings : EntityTypeConfiguration<Model.Core.Church>
public class ChurchMappings : EntityTypeConfiguration<Model.Church>
{
public ChurchMappings()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Data.Entity.ModelConfiguration;
using Church.Model.Core;
using Church.Components.Core.Model;

namespace Church.Components.Core.Repository.ModelMappings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Church.Components.Core.Repository.ModelMappings
{
public class TimeZoneMappings : EntityTypeConfiguration<Model.Core.TimeZone>
public class TimeZoneMappings : EntityTypeConfiguration<Model.TimeZone>
{
public TimeZoneMappings()
{
Expand Down
4 changes: 0 additions & 4 deletions src/Church/Church.Host.Owin.Core/Church.Host.Owin.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@
<Project>{dc8504ad-f791-4c54-83ca-7727cc1d7e2a}</Project>
<Name>Church.Components.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Church.Model\Church.Model.csproj">
<Project>{3563e57a-a00f-4d0b-8e02-099d3315d954}</Project>
<Name>Church.Model</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
Expand All @@ -24,7 +25,7 @@ public HttpResponseMessage ChurchById(int churchId)
var church = _churchService.GetById(churchId);
return church == null ?
Request.CreateErrorResponse(HttpStatusCode.NotFound, "Church {0} not found.".FormatWith(churchId))
: Request.CreateResponse(HttpStatusCode.OK, Mapper.Map<Model.Core.Church, ChurchViewModel>(church));
: Request.CreateResponse(HttpStatusCode.OK, Mapper.Map<Components.Core.Model.Church, ChurchViewModel>(church));
}

[HttpPost]
Expand All @@ -36,10 +37,10 @@ public HttpResponseMessage AddChurch([FromBody]ChurchViewModel churchViewModel)
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Invalid Church");
}

var church = Mapper.Map<ChurchViewModel, Model.Core.Church>(churchViewModel);
var church = Mapper.Map<ChurchViewModel, Components.Core.Model.Church>(churchViewModel);
_churchService.Add(church);

var responseViewModel = Mapper.Map<Model.Core.Church, ChurchViewModel>(church);
var responseViewModel = Mapper.Map<Components.Core.Model.Church, ChurchViewModel>(church);
return Request.CreateResponse(HttpStatusCode.Created, responseViewModel);
}

Expand All @@ -53,7 +54,7 @@ public IEnumerable<LocationViewModel> ChurchLocationsByChurchId(int churchId)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return Mapper.MapList<Model.Core.Location, LocationViewModel>(church.Locations);
return Mapper.MapList<Components.Core.Model.Location, LocationViewModel>(church.Locations);
}
}
}
12 changes: 6 additions & 6 deletions src/Church/Church.Host.Owin.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ void RegisterComponents(TinyIoCContainer container)

private void RegisterMappings()
{
Mapper.CreateMap<Model.Core.TimeZone, TimeZoneViewModel>();
Mapper.CreateMap<TimeZoneViewModel, Model.Core.TimeZone>();
Mapper.CreateMap<Components.Core.Model.TimeZone, TimeZoneViewModel>();
Mapper.CreateMap<TimeZoneViewModel, Components.Core.Model.TimeZone>();

Mapper.CreateMap<Model.Core.Church, ChurchViewModel>()
Mapper.CreateMap<Components.Core.Model.Church, ChurchViewModel>()
.ForMember(x => x.Id, o => o.MapFrom(d => d.Id))
.ForMember(x => x.Name, o => o.MapFrom(d => d.Name))
.ForMember(x => x.TimeZone, o => o.MapFrom(d => d.TimeZone));

Mapper.CreateMap<ChurchViewModel, Model.Core.Church>()
Mapper.CreateMap<ChurchViewModel, Components.Core.Model.Church>()
.ForMember(x => x.Id, o => o.MapFrom(d => d.Id))
.ForMember(x => x.Name, o => o.MapFrom(d => d.Name))
.ForMember(x => x.TimeZone, o => o.MapFrom(d => d.TimeZone));

Mapper.CreateMap<Model.Core.Address, AddressViewModel>();
Mapper.CreateMap<Components.Core.Model.Address, AddressViewModel>();

Mapper.CreateMap<Model.Core.Location, LocationViewModel>()
Mapper.CreateMap<Components.Core.Model.Location, LocationViewModel>()
.ForMember(d => d.Id, o => o.MapFrom(x => x.Id))
.ForMember(d => d.Name, o => o.MapFrom(x => x.Name))
.ForMember(d => d.Address, o => o.MapFrom(x => x.Address));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@
<Project>{5616031c-ee10-437f-9a26-6d3b1081bb06}</Project>
<Name>Church.Host.Owin.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Church.Model\Church.Model.csproj">
<Project>{3563e57a-a00f-4d0b-8e02-099d3315d954}</Project>
<Name>Church.Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config">
Expand Down
12 changes: 6 additions & 6 deletions src/Church/Church.IntegrationTests/ChurchControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void ReturnsChurchWithMatchingIdAndName()
const string fakeName = "FakeChurch";

var mockChurchService = MockRepository.GenerateMock<IChurchService>();
mockChurchService.Expect(x => x.GetById(churchId)).Return(new Model.Core.Church
mockChurchService.Expect(x => x.GetById(churchId)).Return(new Components.Core.Model.Church
{
Id = churchId,
Name = fakeName
Expand All @@ -57,7 +57,7 @@ public void ReturnsChurchWithMatchingIdAndName()
var json = response.Content.ReadAsStringAsync().Result;

//ASSERT
var actual = JsonConvert.DeserializeObject<Model.Core.Church>(json);
var actual = JsonConvert.DeserializeObject<Components.Core.Model.Church>(json);
Assert.AreEqual(churchId, actual.Id);
Assert.AreEqual(fakeName, actual.Name);
}
Expand Down Expand Up @@ -98,7 +98,7 @@ public void ReturnsCreatedHttpStatusCode()
};

var mockChurchService = MockRepository.GenerateMock<IChurchService>();
mockChurchService.Expect(x => x.Add(Arg<Model.Core.Church>.Matches(c => c.Name == "Foo")));
mockChurchService.Expect(x => x.Add(Arg<Components.Core.Model.Church>.Matches(c => c.Name == "Foo")));
Container.Register(typeof (IChurchService), mockChurchService);

//ACT
Expand All @@ -124,8 +124,8 @@ public void ReturnsChurchWithId()
};

var mockChurchService = MockRepository.GenerateStub<IChurchService>();
mockChurchService.Stub(x => x.Add(Arg<Model.Core.Church>.Is.Anything))
.Callback((Model.Core.Church c) =>
mockChurchService.Stub(x => x.Add(Arg<Components.Core.Model.Church>.Is.Anything))
.Callback((Components.Core.Model.Church c) =>
{
c.Id = 101;
return true;
Expand Down Expand Up @@ -157,7 +157,7 @@ public void ReturnsChurchWithSameNameAndTimeZoneAsRequest()
};

var mockChurchService = MockRepository.GenerateStub<IChurchService>();
mockChurchService.Stub(x => x.Add(Arg<Model.Core.Church>.Is.Anything)).Callback((Model.Core.Church c) =>{ c.Id = 101; return true; });
mockChurchService.Stub(x => x.Add(Arg<Components.Core.Model.Church>.Is.Anything)).Callback((Components.Core.Model.Church c) => { c.Id = 101; return true; });
Container.Register(typeof(IChurchService), mockChurchService);

//ACT
Expand Down
6 changes: 0 additions & 6 deletions src/Church/Church.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "Church.SQL", "Church.SQL\Church.SQL.sqlproj", "{3D64A9F6-32CA-4414-8E9F-DA5A31EF194B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Church.Model", "Church.Model\Church.Model.csproj", "{3563E57A-A00F-4D0B-8E02-099D3315D954}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Church.Components.Core", "Church.Components.Core\Church.Components.Core.csproj", "{DC8504AD-F791-4C54-83CA-7727CC1D7E2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Church.Common", "Church.Common\Church.Common.csproj", "{5ED93CCB-EFF1-4D29-BE10-433A8431CC27}"
Expand All @@ -25,10 +23,6 @@ Global
{3D64A9F6-32CA-4414-8E9F-DA5A31EF194B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D64A9F6-32CA-4414-8E9F-DA5A31EF194B}.Release|Any CPU.Build.0 = Release|Any CPU
{3D64A9F6-32CA-4414-8E9F-DA5A31EF194B}.Release|Any CPU.Deploy.0 = Release|Any CPU
{3563E57A-A00F-4D0B-8E02-099D3315D954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3563E57A-A00F-4D0B-8E02-099D3315D954}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3563E57A-A00F-4D0B-8E02-099D3315D954}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3563E57A-A00F-4D0B-8E02-099D3315D954}.Release|Any CPU.Build.0 = Release|Any CPU
{DC8504AD-F791-4C54-83CA-7727CC1D7E2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC8504AD-F791-4C54-83CA-7727CC1D7E2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC8504AD-F791-4C54-83CA-7727CC1D7E2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit 487c174

Please sign in to comment.