Skip to content

Commit

Permalink
Prepare for next iteration
Browse files Browse the repository at this point in the history
I made a lot of small changes that will help me during the next few
iterations.
  • Loading branch information
jehugaleahsa committed Jan 13, 2014
1 parent a8c8d64 commit 80453d0
Show file tree
Hide file tree
Showing 134 changed files with 19,080 additions and 16,196 deletions.
2 changes: 1 addition & 1 deletion Adapters.Tests/AdapterExceptionTester.cs
Expand Up @@ -15,7 +15,7 @@ public void ShouldBeSerializable()
AdapterException exception = new AdapterException(HttpStatusCode.InternalServerError, "exception message", innerException);

SerializationHelper helper = new SerializationHelper();
AdapterException deserialized = helper.RoundTrip(exception);
AdapterException deserialized = helper.Roundtrip(exception);

Assert.AreEqual(exception.StatusCode, deserialized.StatusCode, "The status code was not serialized.");
Assert.AreEqual(exception.Message, deserialized.Message, "The message was not serialized.");
Expand Down
14 changes: 13 additions & 1 deletion Adapters.Tests/Adapters.Tests.csproj
Expand Up @@ -11,11 +11,12 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Adapters.Tests</RootNamespace>
<AssemblyName>Adapters.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\TestMvcApplication\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -25,6 +26,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -33,6 +36,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Expand Down Expand Up @@ -63,6 +67,10 @@
<Project>{0DD6657B-13C2-423C-8E28-FB702EAEB20B}</Project>
<Name>Adapters</Name>
</ProjectReference>
<ProjectReference Include="..\DataObjects\DataObjects.csproj">
<Project>{01a2f933-7ed5-41dd-b9f9-048e9568696b}</Project>
<Name>DataObjects</Name>
</ProjectReference>
<ProjectReference Include="..\MvcUtilities\MvcUtilities.csproj">
<Project>{6D334141-39BB-42F8-9E37-53C8F2B8614E}</Project>
<Name>MvcUtilities</Name>
Expand All @@ -75,6 +83,10 @@
<Project>{CB5041CA-89E5-4650-BA3F-411F5539EEF8}</Project>
<Name>TestUtilities</Name>
</ProjectReference>
<ProjectReference Include="..\ViewModels\ViewModels.csproj">
<Project>{1aba12e7-d95e-448e-8a86-91972b0138ae}</Project>
<Name>ViewModels</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
6 changes: 3 additions & 3 deletions Adapters.Tests/AddressItemAdapterTester.cs
Expand Up @@ -3,11 +3,11 @@
using System.Linq;
using System.Net;
using Adapters.Mappers;
using Adapters.Models;
using ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using ServiceInterfaces.Entities;
using ServiceInterfaces.Repositories;
using DataObjects;
using ServiceInterfaces;

namespace Adapters.Tests
{
Expand Down
17 changes: 12 additions & 5 deletions Adapters.Tests/CustomerAdapterTester.cs
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Adapters.Mappers;
using Adapters.Models;
using ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using ServiceInterfaces.Entities;
using ServiceInterfaces.Repositories;
using DataObjects;
using ServiceInterfaces;

namespace Adapters.Tests
{
Expand All @@ -16,7 +17,7 @@ public class CustomerAdapterTester

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ShouldThrowExceptionIfNullPassedToCtor()
public void ShouldThrowExceptionIfNullPassedToConstructor()
{
new CustomerAdapter(null);
}
Expand Down Expand Up @@ -58,10 +59,13 @@ public void ShouldMapCustomerToViewModel()
mapper.Convert(dto).Returns(viewModel);

CustomerAdapter adapter = new CustomerAdapter(repository) { CustomerMapper = mapper };
CustomerData data = adapter.GetCustomer(Guid.Empty.ToString("N"));
PrimitiveMapper primitiveMapper = new PrimitiveMapper();
CustomerData data = adapter.GetCustomer(primitiveMapper.ToString(Guid.Empty));

repository.Received().GetCustomer(dto.CustomerId);
mapper.Received().Convert(dto);

Assert.IsNotNull(data, "The returned view model was null.");
}

#endregion
Expand All @@ -83,6 +87,9 @@ public void ShouldGetCustomersFromRepository()

repository.Received().GetCustomers();
mapper.Received(1).Convert(customers[0]);

Assert.IsNotNull(results, "Null was returned by the adapter.");
Assert.AreEqual(1, results.Count(), "The wrong number of view models were returned.");
}

#endregion
Expand Down
19 changes: 11 additions & 8 deletions Adapters.Tests/CustomerMapperTester.cs
@@ -1,16 +1,16 @@
using System;
using Adapters.Mappers;
using Adapters.Models;
using ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ServiceInterfaces.Entities;
using DataObjects;

namespace Adapters.Tests
{
[TestClass]
public class CustomerMapperTester
{
[TestMethod]
public void ShouldConvertViewModelToDTOIgnoringMissingCustomerId()
public void ShouldConvertViewModelToDataObjectIgnoringMissingCustomerId()
{
CustomerData viewModel = new CustomerData()
{
Expand All @@ -23,13 +23,14 @@ public void ShouldConvertViewModelToDTOIgnoringMissingCustomerId()
CustomerMapper mapper = new CustomerMapper();
Customer customer = mapper.Convert(viewModel);

Assert.AreEqual(DateTime.Parse(viewModel.BirthDate), customer.BirthDate, "The birth date was not mapped.");
PrimitiveMapper primitiveMapper = new PrimitiveMapper();
Assert.AreEqual(viewModel.BirthDate, primitiveMapper.ToString(customer.BirthDate), "The birth date was not mapped.");
Assert.AreEqual(viewModel.Height, customer.Height, "The height was not mapped.");
Assert.AreEqual(viewModel.Name, customer.Name, "The name was not mapped.");
}

[TestMethod]
public void ShouldConvertViewModelToDTO()
public void ShouldConvertViewModelToDataObject()
{
CustomerData viewModel = new CustomerData()
{
Expand All @@ -42,14 +43,15 @@ public void ShouldConvertViewModelToDTO()
CustomerMapper mapper = new CustomerMapper();
Customer customer = mapper.Convert(viewModel);

Assert.AreEqual(DateTime.Parse(viewModel.BirthDate), customer.BirthDate, "The birth date was not mapped.");
PrimitiveMapper primitiveMapper = new PrimitiveMapper();
Assert.AreEqual(viewModel.BirthDate, primitiveMapper.ToString(customer.BirthDate), "The birth date was not mapped.");
Assert.AreEqual(Guid.Parse(viewModel.CustomerId), customer.CustomerId, "The customer ID was not mapped.");
Assert.AreEqual(viewModel.Height, customer.Height, "The height was not mapped.");
Assert.AreEqual(viewModel.Name, customer.Name, "The name was not mapped.");
}

[TestMethod]
public void ShouldConvertDTOToViewModel()
public void ShouldConvertDataObjectToViewModel()
{
Customer customer = new Customer()
{
Expand All @@ -62,7 +64,8 @@ public void ShouldConvertDTOToViewModel()
CustomerMapper mapper = new CustomerMapper();
CustomerData viewModel = mapper.Convert(customer);

Assert.AreEqual(customer.BirthDate, DateTime.Parse(viewModel.BirthDate), "The birth date was not mapped.");
PrimitiveMapper primitiveMapper = new PrimitiveMapper();
Assert.AreEqual(customer.BirthDate, primitiveMapper.ToDateTime(viewModel.BirthDate), "The birth date was not mapped.");
Assert.AreEqual(customer.CustomerId, Guid.Parse(viewModel.CustomerId), "The customer ID was not mapped.");
Assert.AreEqual(customer.Height, viewModel.Height, "The height was not mapped.");
Assert.AreEqual(customer.Name, viewModel.Name, "The name was not mapped.");
Expand Down
4 changes: 2 additions & 2 deletions Adapters.Tests/PrimitiveMapperTester.cs
Expand Up @@ -9,7 +9,7 @@ namespace Adapters.Tests
public class PrimitiveMapperTester
{
[TestMethod]
public void ShouldThrowAdapterExceptionForBadGuid()
public void ShouldThrowAdapterExceptionForInvalidGuid()
{
try
{
Expand All @@ -33,7 +33,7 @@ public void ShouldConvertValidStringIntoGuid()
}

[TestMethod]
public void ShouldThrowAdapterExceptionForBadDate()
public void ShouldThrowAdapterExceptionForInvalidDate()
{
try
{
Expand Down
7 changes: 4 additions & 3 deletions Adapters.Tests/Properties/AssemblyInfo.cs
@@ -1,5 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System;
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand All @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("Adapters.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyCompany("Truncon")]
[assembly: AssemblyProduct("Adapters.Tests")]
[assembly: AssemblyCopyright("Copyright © HP 2013")]
[assembly: AssemblyTrademark("")]
Expand All @@ -33,3 +33,4 @@
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: CLSCompliant(true)]
22 changes: 13 additions & 9 deletions Adapters/Adapters.csproj
Expand Up @@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Adapters</RootNamespace>
<AssemblyName>Adapters</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\TestMvcApplication\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -23,6 +24,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,18 +34,13 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AdapterException.cs" />
Expand All @@ -51,12 +49,14 @@
<Compile Include="Mappers\CustomerMapper.cs" />
<Compile Include="Mappers\PrimitiveMapper.cs" />
<Compile Include="Mappers\AddressItemMapper.cs" />
<Compile Include="Models\CustomerData.cs" />
<Compile Include="Models\AddressItemData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AddressItemAdapter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataObjects\DataObjects.csproj">
<Project>{01a2f933-7ed5-41dd-b9f9-048e9568696b}</Project>
<Name>DataObjects</Name>
</ProjectReference>
<ProjectReference Include="..\MvcUtilities\MvcUtilities.csproj">
<Project>{6D334141-39BB-42F8-9E37-53C8F2B8614E}</Project>
<Name>MvcUtilities</Name>
Expand All @@ -69,6 +69,10 @@
<Project>{45C0C712-ECF5-41C8-989C-7D7F75E60B77}</Project>
<Name>ServiceInterfaces</Name>
</ProjectReference>
<ProjectReference Include="..\ViewModels\ViewModels.csproj">
<Project>{1aba12e7-d95e-448e-8a86-91972b0138ae}</Project>
<Name>ViewModels</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Expand Down
10 changes: 5 additions & 5 deletions Adapters/AddressItemAdapter.cs
Expand Up @@ -3,10 +3,10 @@
using System.Linq;
using System.Net;
using Adapters.Mappers;
using Adapters.Models;
using ViewModels;
using Policies;
using ServiceInterfaces.Entities;
using ServiceInterfaces.Repositories;
using DataObjects;
using ServiceInterfaces;

namespace Adapters
{
Expand Down Expand Up @@ -67,10 +67,10 @@ public AddressItemData AddAddressItem(AddressItemData data)

[Log]
[ErrorMessage("An error occurred while removing the address item.")]
public void RemoveAddressItem(string itemId)
public void RemoveAddressItem(string settingId)
{
PrimitiveMapper mapper = new PrimitiveMapper();
AddressItem item = itemRepository.GetAddressItem(mapper.ToGuid(itemId));
AddressItem item = itemRepository.GetAddressItem(mapper.ToGuid(settingId));
if (item == null)
{
throw new AdapterException(HttpStatusCode.NotFound, "An address item with the given ID was not found.");
Expand Down
10 changes: 7 additions & 3 deletions Adapters/CustomerAdapter.cs
Expand Up @@ -3,10 +3,10 @@
using System.Linq;
using System.Net;
using Adapters.Mappers;
using Adapters.Models;
using ViewModels;
using Policies;
using ServiceInterfaces.Entities;
using ServiceInterfaces.Repositories;
using DataObjects;
using ServiceInterfaces;

namespace Adapters
{
Expand Down Expand Up @@ -67,6 +67,10 @@ public CustomerData AddCustomer(CustomerData customerData)
[ErrorMessage("An error occurred while updating the customer.")]
public void UpdateCustomer(CustomerData customerData)
{
if (customerData == null)
{
throw new AdapterException(HttpStatusCode.BadRequest, "No information provided for the customer being updated.");
}
Customer original = getCustomer(customerData.CustomerId);
Customer modified = CustomerMapper.Convert(customerData);
customerRepository.Update(original, modified);
Expand Down
14 changes: 11 additions & 3 deletions Adapters/Mappers/AddressItemMapper.cs
@@ -1,20 +1,24 @@
using System;
using Adapters.Models;
using ServiceInterfaces.Entities;
using ViewModels;
using DataObjects;

namespace Adapters.Mappers
{
public interface IAddressItemMapper
{
AddressItem Convert(AddressItemData data);

AddressItemData Convert(AddressItem setting);
AddressItemData Convert(AddressItem item);
}

public class AddressItemMapper : IAddressItemMapper
{
public AddressItem Convert(AddressItemData data)
{
if (data == null)
{
return null;
}
PrimitiveMapper mapper = new PrimitiveMapper();
AddressItem item = new AddressItem();
if (!String.IsNullOrWhiteSpace(data.AddressItemId))
Expand All @@ -29,6 +33,10 @@ public AddressItem Convert(AddressItemData data)

public AddressItemData Convert(AddressItem item)
{
if (item == null)
{
return null;
}
PrimitiveMapper mapper = new PrimitiveMapper();
AddressItemData data = new AddressItemData();
data.AddressItemId = mapper.ToString(item.AddressItemId);
Expand Down

0 comments on commit 80453d0

Please sign in to comment.