Permalink
Browse files

Updating tests

  • Loading branch information...
1 parent 3c02383 commit d3a07310bd70514d9417bc812af82142a3f306ea @jchadwick jchadwick committed Dec 21, 2011
View
@@ -10,11 +10,11 @@ namespace Ebuy
[MetadataType(typeof(Auction.Metadata))]
public class Auction : Entity
{
- public string Title { get; set; }
- public string Description { get; set; }
- public DateTime StartTime { get; set; }
- public DateTime EndTime { get; set; }
- public Currency StartingPrice { get; set; }
+ public virtual string Title { get; set; }
+ public virtual string Description { get; set; }
+ public virtual DateTime StartTime { get; set; }
+ public virtual DateTime EndTime { get; set; }
+ public virtual Currency StartingPrice { get; set; }
public virtual Bid WinningBid { get; private set; }
View
@@ -3,9 +3,8 @@
namespace Ebuy
{
- public class Bid
+ public class Bid : IEquatable<Bid>
{
- [Key]
public virtual Guid Id
{
get
@@ -54,6 +53,37 @@ private Bid()
{
}
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (Bid)) return false;
+ return Equals((Bid) obj);
+ }
+
+ public bool Equals(Bid other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+ return other.Id.Equals(Id);
+ }
+
+ public override int GetHashCode()
+ {
+ return Id.GetHashCode();
+ }
+
+ public static bool operator ==(Bid left, Bid right)
+ {
+ return Equals(left, right);
+ }
+
+ public static bool operator !=(Bid left, Bid right)
+ {
+ return !Equals(left, right);
+ }
+
+
public class Metadata
{
[Required]
@@ -67,8 +97,8 @@ public class Metadata
public object Timestamp { get; set; }
[Required]
+ [InverseProperty("Bids")]
public object User { get; set; }
}
-
}
}
View
@@ -1,3 +1,4 @@
+using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using CustomExtensions.DataAnnotations;
@@ -25,7 +26,7 @@ public interface IEntity
string Key { get; }
}
- public abstract class Entity : IEntity
+ public abstract class Entity : IEntity, IEquatable<Entity>
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual long Id { get; protected set; }
@@ -43,5 +44,45 @@ protected virtual string GenerateKey()
{
return KeyGenerator.Generate();
}
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (Entity)) return false;
+ return Equals((Entity) obj);
+ }
+
+ public bool Equals(Entity other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+
+ if (Id == 0 || other.Id == 0)
+ return Equals(other._key, _key);
+
+ return other.Id == Id;
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ if (Id == 0)
+ return Key.GetHashCode() * 397;
+
+ return Id.GetHashCode();
+ }
+ }
+
+ public static bool operator ==(Entity left, Entity right)
+ {
+ return Equals(left, right);
+ }
+
+ public static bool operator !=(Entity left, Entity right)
+ {
+ return !Equals(left, right);
+ }
}
}
View
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.Contracts;
using CustomExtensions.DataAnnotations;
@@ -9,22 +10,35 @@ namespace Ebuy
[MetadataType(typeof(User.Metadata))]
public class User : Entity
{
- public string DisplayName
+ public virtual ICollection<Bid> Bids { get; private set; }
+
+ public virtual string DisplayName
{
get { return _displayName ?? FullName; }
set { _displayName = value; }
}
private string _displayName;
[Unique]
- public string EmailAddress { get; set; }
+ public virtual string EmailAddress { get; set; }
+
+ public virtual string FullName { get; set; }
+
+ public virtual ICollection<Payment> Payments { get; private set; }
+
+ public virtual ICollection<Review> Reviews { get; private set; }
- public string FullName { get; set; }
+ public virtual ICollection<Auction> WatchedAuctions { get; private set; }
+
+
+ public User()
+ {
+ Bids = new Collection<Bid>();
+ Payments = new Collection<Payment>();
+ Reviews = new Collection<Review>();
+ WatchedAuctions = new Collection<Auction>();
+ }
- public virtual ICollection<Bid> Bids { get; set; }
- public virtual ICollection<Payment> Payments { get; set; }
- public virtual ICollection<Review> Reviews { get; set; }
- public virtual ICollection<Auction> WatchedAuctions { get; set; }
protected override string GenerateKey()
{
@@ -6,16 +6,16 @@ namespace Ebuy
[MetadataType(typeof(WebsiteImage.Metadata))]
public class WebsiteImage
{
- public Guid Id
+ public virtual Guid Id
{
get { return _id ?? Guid.NewGuid(); }
set { _id = value; }
}
private Guid? _id;
- public string ImageUrl { get; set; }
+ public virtual string ImageUrl { get; set; }
- public string ThumbnailUrl { get; set; }
+ public virtual string ThumbnailUrl { get; set; }
public WebsiteImage()
@@ -1,10 +1,11 @@
+using System.Linq;
using Ebuy;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IntegrationTests.Core.DataAccess
{
[TestClass]
- public class AuctionRepositoryTests : RepositoryTestFixture
+ public class AuctionPersistenceTests : RepositoryTestFixture
{
[TestMethod]
public void ShouldSaveNewAuction()
@@ -22,7 +23,6 @@ public void ShouldFindAuctionById()
public void ShouldPersistBids()
{
var auction = CreateAndSaveNewEntity<Auction>();
-
var user1 = CreateAndSaveNewEntity<User>();
var user2 = CreateAndSaveNewEntity<User>();
@@ -36,6 +36,10 @@ public void ShouldPersistBids()
var savedAuction = context.Auctions.Find(auction.Id);
Assert.AreEqual(3, savedAuction.Bids.Count);
Assert.AreEqual("$30", savedAuction.WinningBid.Price);
+
+ var savedUser = context.Users.Find(user1.Id);
+ Assert.AreEqual(2, savedUser.Bids.Count);
+ Assert.IsTrue(savedUser.Bids.OrderBy(x => x.Price.Amount).Last().IsWinningBid);
});
}
}
@@ -4,7 +4,7 @@
namespace IntegrationTests.Core.DataAccess
{
[TestClass]
- public class CategoryRepositoryTests : RepositoryTestFixture
+ public class CategoryPersistenceTests : RepositoryTestFixture
{
[TestMethod]
public void ShouldSaveNewCategory()
@@ -5,7 +5,7 @@
namespace IntegrationTests.Core.DataAccess
{
[TestClass]
- public class ProductRepositoryTests : RepositoryTestFixture
+ public class ProductPersistenceTests : RepositoryTestFixture
{
[TestMethod]
public void ShouldSaveNewProduct()
@@ -5,7 +5,7 @@
namespace IntegrationTests.Core.DataAccess
{
[TestClass]
- public class UserRepositoryTests : RepositoryTestFixture
+ public class UserPersistenceTests : RepositoryTestFixture
{
[TestMethod]
public void ShouldSaveNewUser()
@@ -68,12 +68,12 @@
<Compile Include="App_Start\EntityFramework.SqlServerCompact.cs" />
<Compile Include="AssertException.cs" />
<Compile Include="Core\DataAccess\RepositoryInitializer.cs" />
- <Compile Include="Core\DataAccess\AuctionRepositoryTests.cs" />
- <Compile Include="Core\DataAccess\CategoryRepositoryTests.cs" />
+ <Compile Include="Core\DataAccess\AuctionPersistenceTests.cs" />
+ <Compile Include="Core\DataAccess\CategoryPersistenceTests.cs" />
<Compile Include="Core\DataAccess\DataContextTestFixture.cs" />
- <Compile Include="Core\DataAccess\ProductRepositoryTests.cs" />
+ <Compile Include="Core\DataAccess\ProductPersistenceTests.cs" />
<Compile Include="Core\DataAccess\RepositoryTests.cs" />
- <Compile Include="Core\DataAccess\UserRepositoryTests.cs" />
+ <Compile Include="Core\DataAccess\UserPersistenceTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestDataGenerator.cs" />
</ItemGroup>

0 comments on commit d3a0731

Please sign in to comment.