From 487c174940ccc1de5d3c2fb298620408182a8748 Mon Sep 17 00:00:00 2001 From: Dav Evans Date: Thu, 31 Jul 2014 20:16:27 +1000 Subject: [PATCH] Remove Church.Model --- .../Church.Components.Core.csproj | 8 ++++---- .../Church.Components.Core/ChurchService.cs | 4 ++-- .../Church.Components.Core/IChurchService.cs | 4 ++-- .../Church.Components.Core/Model/Address.cs | 13 ++++++++++++ .../Church.Components.Core/Model/Church.cs | 20 +++++++++++++++++++ .../Church.Components.Core/Model/Location.cs | 15 ++++++++++++++ .../Church.Components.Core/Model/TimeZone.cs | 8 ++++++++ .../Repository/CoreContext.cs | 3 +-- .../Repository/CoreRepository.cs | 4 ++-- .../Repository/ICoreRepository.cs | 4 ++-- .../ModelMappings/AddressMappings.cs | 2 +- .../ModelMappings/ChurchMappings.cs | 2 +- .../ModelMappings/LocationMappings.cs | 2 +- .../ModelMappings/TimeZoneMappings.cs | 2 +- .../Church.Host.Owin.Core.csproj | 4 ---- .../Controllers/ChurchController.cs | 9 +++++---- src/Church/Church.Host.Owin.Core/Startup.cs | 12 +++++------ .../Church.IntegrationTests.csproj | 4 ---- .../ChurchControllerTests.cs | 12 +++++------ src/Church/Church.sln | 6 ------ 20 files changed, 90 insertions(+), 48 deletions(-) create mode 100644 src/Church/Church.Components.Core/Model/Address.cs create mode 100644 src/Church/Church.Components.Core/Model/Church.cs create mode 100644 src/Church/Church.Components.Core/Model/Location.cs create mode 100644 src/Church/Church.Components.Core/Model/TimeZone.cs diff --git a/src/Church/Church.Components.Core/Church.Components.Core.csproj b/src/Church/Church.Components.Core/Church.Components.Core.csproj index 7eb5c11..977867c 100644 --- a/src/Church/Church.Components.Core/Church.Components.Core.csproj +++ b/src/Church/Church.Components.Core/Church.Components.Core.csproj @@ -49,6 +49,10 @@ + + + + @@ -63,10 +67,6 @@ {5ed93ccb-eff1-4d29-be10-433a8431cc27} Church.Common - - {3563e57a-a00f-4d0b-8e02-099d3315d954} - Church.Model - diff --git a/src/Church/Church.Components.Core/ChurchService.cs b/src/Church/Church.Components.Core/ChurchService.cs index 139e479..250a979 100644 --- a/src/Church/Church.Components.Core/ChurchService.cs +++ b/src/Church/Church.Components.Core/ChurchService.cs @@ -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); } diff --git a/src/Church/Church.Components.Core/IChurchService.cs b/src/Church/Church.Components.Core/IChurchService.cs index d9124e2..15ccd5a 100644 --- a/src/Church/Church.Components.Core/IChurchService.cs +++ b/src/Church/Church.Components.Core/IChurchService.cs @@ -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); } } diff --git a/src/Church/Church.Components.Core/Model/Address.cs b/src/Church/Church.Components.Core/Model/Address.cs new file mode 100644 index 0000000..ff5a937 --- /dev/null +++ b/src/Church/Church.Components.Core/Model/Address.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/Church/Church.Components.Core/Model/Church.cs b/src/Church/Church.Components.Core/Model/Church.cs new file mode 100644 index 0000000..b55ede1 --- /dev/null +++ b/src/Church/Church.Components.Core/Model/Church.cs @@ -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 Locations { get; set; } + + public Church() + { + Locations = new List(); + } + } +} diff --git a/src/Church/Church.Components.Core/Model/Location.cs b/src/Church/Church.Components.Core/Model/Location.cs new file mode 100644 index 0000000..3f3d049 --- /dev/null +++ b/src/Church/Church.Components.Core/Model/Location.cs @@ -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; } + } +} diff --git a/src/Church/Church.Components.Core/Model/TimeZone.cs b/src/Church/Church.Components.Core/Model/TimeZone.cs new file mode 100644 index 0000000..a21c9e9 --- /dev/null +++ b/src/Church/Church.Components.Core/Model/TimeZone.cs @@ -0,0 +1,8 @@ +namespace Church.Components.Core.Model +{ + public class TimeZone + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/src/Church/Church.Components.Core/Repository/CoreContext.cs b/src/Church/Church.Components.Core/Repository/CoreContext.cs index a8a4125..1c1102e 100644 --- a/src/Church/Church.Components.Core/Repository/CoreContext.cs +++ b/src/Church/Church.Components.Core/Repository/CoreContext.cs @@ -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 { - public DbSet Churches { get; set; } + public DbSet Churches { get; set; } protected override void OnModelCreating(DbModelBuilder builder) { diff --git a/src/Church/Church.Components.Core/Repository/CoreRepository.cs b/src/Church/Church.Components.Core/Repository/CoreRepository.cs index 6d29730..ab5cdd9 100644 --- a/src/Church/Church.Components.Core/Repository/CoreRepository.cs +++ b/src/Church/Church.Components.Core/Repository/CoreRepository.cs @@ -11,7 +11,7 @@ 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)) @@ -19,7 +19,7 @@ public Model.Core.Church GetById(int churchId) .FirstOrDefault(x => x.Id == churchId); } - public void Add(Model.Core.Church church) + public void Add(Model.Church church) { _dbContext.Churches.Add(church); _dbContext.SaveChanges(); diff --git a/src/Church/Church.Components.Core/Repository/ICoreRepository.cs b/src/Church/Church.Components.Core/Repository/ICoreRepository.cs index 10c8cae..acdc822 100644 --- a/src/Church/Church.Components.Core/Repository/ICoreRepository.cs +++ b/src/Church/Church.Components.Core/Repository/ICoreRepository.cs @@ -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); } } diff --git a/src/Church/Church.Components.Core/Repository/ModelMappings/AddressMappings.cs b/src/Church/Church.Components.Core/Repository/ModelMappings/AddressMappings.cs index c614a1f..7c8fd15 100644 --- a/src/Church/Church.Components.Core/Repository/ModelMappings/AddressMappings.cs +++ b/src/Church/Church.Components.Core/Repository/ModelMappings/AddressMappings.cs @@ -1,5 +1,5 @@ using System.Data.Entity.ModelConfiguration; -using Church.Model.Core; +using Church.Components.Core.Model; namespace Church.Components.Core.Repository.ModelMappings { diff --git a/src/Church/Church.Components.Core/Repository/ModelMappings/ChurchMappings.cs b/src/Church/Church.Components.Core/Repository/ModelMappings/ChurchMappings.cs index 74dc737..e314a1f 100644 --- a/src/Church/Church.Components.Core/Repository/ModelMappings/ChurchMappings.cs +++ b/src/Church/Church.Components.Core/Repository/ModelMappings/ChurchMappings.cs @@ -2,7 +2,7 @@ namespace Church.Components.Core.Repository.ModelMappings { - public class ChurchMappings : EntityTypeConfiguration + public class ChurchMappings : EntityTypeConfiguration { public ChurchMappings() { diff --git a/src/Church/Church.Components.Core/Repository/ModelMappings/LocationMappings.cs b/src/Church/Church.Components.Core/Repository/ModelMappings/LocationMappings.cs index 8b77bf9..bc96b85 100644 --- a/src/Church/Church.Components.Core/Repository/ModelMappings/LocationMappings.cs +++ b/src/Church/Church.Components.Core/Repository/ModelMappings/LocationMappings.cs @@ -1,5 +1,5 @@ using System.Data.Entity.ModelConfiguration; -using Church.Model.Core; +using Church.Components.Core.Model; namespace Church.Components.Core.Repository.ModelMappings { diff --git a/src/Church/Church.Components.Core/Repository/ModelMappings/TimeZoneMappings.cs b/src/Church/Church.Components.Core/Repository/ModelMappings/TimeZoneMappings.cs index e88e3f7..721f905 100644 --- a/src/Church/Church.Components.Core/Repository/ModelMappings/TimeZoneMappings.cs +++ b/src/Church/Church.Components.Core/Repository/ModelMappings/TimeZoneMappings.cs @@ -2,7 +2,7 @@ namespace Church.Components.Core.Repository.ModelMappings { - public class TimeZoneMappings : EntityTypeConfiguration + public class TimeZoneMappings : EntityTypeConfiguration { public TimeZoneMappings() { diff --git a/src/Church/Church.Host.Owin.Core/Church.Host.Owin.Core.csproj b/src/Church/Church.Host.Owin.Core/Church.Host.Owin.Core.csproj index 8e7dd0d..1dd95fa 100644 --- a/src/Church/Church.Host.Owin.Core/Church.Host.Owin.Core.csproj +++ b/src/Church/Church.Host.Owin.Core/Church.Host.Owin.Core.csproj @@ -120,10 +120,6 @@ {dc8504ad-f791-4c54-83ca-7727cc1d7e2a} Church.Components.Core - - {3563e57a-a00f-4d0b-8e02-099d3315d954} - Church.Model - 10.0 diff --git a/src/Church/Church.Host.Owin.Core/Controllers/ChurchController.cs b/src/Church/Church.Host.Owin.Core/Controllers/ChurchController.cs index efa8d71..65b9c94 100644 --- a/src/Church/Church.Host.Owin.Core/Controllers/ChurchController.cs +++ b/src/Church/Church.Host.Owin.Core/Controllers/ChurchController.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; @@ -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(church)); + : Request.CreateResponse(HttpStatusCode.OK, Mapper.Map(church)); } [HttpPost] @@ -36,10 +37,10 @@ public HttpResponseMessage AddChurch([FromBody]ChurchViewModel churchViewModel) return Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Invalid Church"); } - var church = Mapper.Map(churchViewModel); + var church = Mapper.Map(churchViewModel); _churchService.Add(church); - var responseViewModel = Mapper.Map(church); + var responseViewModel = Mapper.Map(church); return Request.CreateResponse(HttpStatusCode.Created, responseViewModel); } @@ -53,7 +54,7 @@ public IEnumerable ChurchLocationsByChurchId(int churchId) { throw new HttpResponseException(HttpStatusCode.NotFound); } - return Mapper.MapList(church.Locations); + return Mapper.MapList(church.Locations); } } } diff --git a/src/Church/Church.Host.Owin.Core/Startup.cs b/src/Church/Church.Host.Owin.Core/Startup.cs index 7bfe528..95c3d29 100644 --- a/src/Church/Church.Host.Owin.Core/Startup.cs +++ b/src/Church/Church.Host.Owin.Core/Startup.cs @@ -36,22 +36,22 @@ void RegisterComponents(TinyIoCContainer container) private void RegisterMappings() { - Mapper.CreateMap(); - Mapper.CreateMap(); + Mapper.CreateMap(); + Mapper.CreateMap(); - Mapper.CreateMap() + Mapper.CreateMap() .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() + Mapper.CreateMap() .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(); + Mapper.CreateMap(); - Mapper.CreateMap() + Mapper.CreateMap() .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)); diff --git a/src/Church/Church.IntegrationTests/Church.IntegrationTests.csproj b/src/Church/Church.IntegrationTests/Church.IntegrationTests.csproj index 68e6741..6308ae5 100644 --- a/src/Church/Church.IntegrationTests/Church.IntegrationTests.csproj +++ b/src/Church/Church.IntegrationTests/Church.IntegrationTests.csproj @@ -86,10 +86,6 @@ {5616031c-ee10-437f-9a26-6d3b1081bb06} Church.Host.Owin.Core - - {3563e57a-a00f-4d0b-8e02-099d3315d954} - Church.Model - diff --git a/src/Church/Church.IntegrationTests/ChurchControllerTests.cs b/src/Church/Church.IntegrationTests/ChurchControllerTests.cs index 15b8426..5d3c04d 100644 --- a/src/Church/Church.IntegrationTests/ChurchControllerTests.cs +++ b/src/Church/Church.IntegrationTests/ChurchControllerTests.cs @@ -43,7 +43,7 @@ public void ReturnsChurchWithMatchingIdAndName() const string fakeName = "FakeChurch"; var mockChurchService = MockRepository.GenerateMock(); - 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 @@ -57,7 +57,7 @@ public void ReturnsChurchWithMatchingIdAndName() var json = response.Content.ReadAsStringAsync().Result; //ASSERT - var actual = JsonConvert.DeserializeObject(json); + var actual = JsonConvert.DeserializeObject(json); Assert.AreEqual(churchId, actual.Id); Assert.AreEqual(fakeName, actual.Name); } @@ -98,7 +98,7 @@ public void ReturnsCreatedHttpStatusCode() }; var mockChurchService = MockRepository.GenerateMock(); - mockChurchService.Expect(x => x.Add(Arg.Matches(c => c.Name == "Foo"))); + mockChurchService.Expect(x => x.Add(Arg.Matches(c => c.Name == "Foo"))); Container.Register(typeof (IChurchService), mockChurchService); //ACT @@ -124,8 +124,8 @@ public void ReturnsChurchWithId() }; var mockChurchService = MockRepository.GenerateStub(); - mockChurchService.Stub(x => x.Add(Arg.Is.Anything)) - .Callback((Model.Core.Church c) => + mockChurchService.Stub(x => x.Add(Arg.Is.Anything)) + .Callback((Components.Core.Model.Church c) => { c.Id = 101; return true; @@ -157,7 +157,7 @@ public void ReturnsChurchWithSameNameAndTimeZoneAsRequest() }; var mockChurchService = MockRepository.GenerateStub(); - mockChurchService.Stub(x => x.Add(Arg.Is.Anything)).Callback((Model.Core.Church c) =>{ c.Id = 101; return true; }); + mockChurchService.Stub(x => x.Add(Arg.Is.Anything)).Callback((Components.Core.Model.Church c) => { c.Id = 101; return true; }); Container.Register(typeof(IChurchService), mockChurchService); //ACT diff --git a/src/Church/Church.sln b/src/Church/Church.sln index ee96ef2..f006163 100644 --- a/src/Church/Church.sln +++ b/src/Church/Church.sln @@ -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}" @@ -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