public void Insert( LineItem lineItem ) { IDbCommand command = _session.CreateCommandWithinCurrentTransaction(); command.CommandText = SqlGenerator.GenerateInsertSql( "LineItem", new[] { "Id", "Order_id", "Product_id", "Quantity", "UnitPrice" }, // HasIdentityColumn ); HasNoIdentityColumn ); command.SetParameter( "@Id", lineItem.Id ); command.SetParameter( "@Order_id", lineItem.Order.Id ); command.SetParameter( "@Product_id", lineItem.Product.Id ); command.SetParameter( "@Quantity", lineItem.Quantity ); command.SetDecimalParameter( "@UnitPrice", lineItem.UnitPrice ); LogCommand( command ); command.ExecuteNonQuery(); }
protected override void TestSetUp() { _expectedLineItem = a.LineItem.build(); _db.Add( _expectedLineItem ) .Persist(); _actualLineItem = _session.Get< LineItem >( _expectedLineItem.Id ); }
public TestDatabase Add( LineItem lineItem ) { // Exit if null or if this has already been added. if ( _lineItems.AddIfUnique( lineItem, x => x.Id == lineItem.Id ) ) { // Add parents. Add( lineItem.Order ); // Add children. Add( lineItem.Product ); } return this; }
public void OrderTotalShouldBeTheSumOfTheLineItems() { // Arrange. var customer = new Customer { FirstName = "Bob", LastName = "Smith" }; var order = new Order { Customer = customer, OrderDate = DateTime.Now }; var lineItem1 = new LineItem { Order = order, Product = new Product { Name = "Product1", Description = "Product1 Description" }, Quantity = 1, UnitPrice = 1.60 }; var lineItem2 = new LineItem { Order = order, Product = new Product { Name = "Product2", Description = "Product2 Description" }, Quantity = 10, UnitPrice = 25.99 }; order.LineItems.Add( lineItem1 ); order.LineItems.Add( lineItem2 ); // Act. var actualTotal = order.TotalAmount; // Assert. const double expectedTotal = ( 1 * 1.60 ) + ( 10 * 25.99 ); actualTotal.Should().Be.EqualTo( expectedTotal ); }