Hi,

I have difficulty making the test below to pass. I need to tell NH that
there's only 1 Image related to Product and if another is assigned the old
one should be deleted.

Some help please?

// THE TEST
[Test]
public void ReplaceProductImage_DeletesOldRecord() {
 // Initialise
 var p = new Product {
  Image = new BinaryContent {
   Content = Encoding.ASCII.GetBytes("image")
  }
 };
 Session.Save(p);
 Session.Flush();
 // Exercise
 var totalImagesBefore = Session.Linq<BinaryContent>().Count();
 p.Image = new BinaryContent {
  Content = Encoding.ASCII.GetBytes("another")
 };
 Session.Flush();
 var totalImagesAfter = Session.Linq<BinaryContent>().Count();
 // Verify
 totalImagesAfter.Should().Be.EqualTo(totalImagesBefore);
}


// THE MODEL
public class Product {
 public virtual int Id { get; protected set; }
 public virtual BinaryContent Image { get; set; }
}
public class BinaryContent {
 public virtual int Id { get; protected set; }
 public virtual byte[] Content { get; set; }
}
// THE MAPPING
public class BinaryContentMap : ClassMap<BinaryContent> {
 public BinaryContentMap() {
  Id(x => x.Id).GeneratedBy.Native();
  Map(x => x.Content).CustomTypeIs("BinaryBlob").WithLengthOf(102400);
 }
}



Cheers,
Dmitriy.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to