public void delete_offer_deletes_equipment_offer_descendents()
        {
            var offerGuid = Guid.NewGuid();
            var equipmentOfferGuid = Guid.NewGuid();
            var offer = new OfferDto
            {
                OfferGuid = offerGuid,
                Equipment = new List<EquipmentOfferTrnDao>
                {
                    new EquipmentOfferTrnDao
                    {
                        EquipmentOfferGuid = equipmentOfferGuid,
                        OfferGuid = offerGuid,
                        EquipmentOptions = new List<EquipmentOptionTrnDao>
                        {
                            new EquipmentOptionTrnDao
                            {
                                EquipmentOptionTrnGuid = Guid.NewGuid(),
                                EquipmentOfferGuid = equipmentOfferGuid,
                                Quantity = 23
                            }
                        }
                    }
                },
                OfferReference = "Test offer",
                OpportunityGuid = Guid.NewGuid()
            };

            var logger = new MockSimpleSaveLogger();
            SimpleSaveExtensions.Logger = logger;
            
            try
            {
                using (IDbConnection connection = new SqlConnection())
                {
                    connection.Delete(offer);
                }
            }
            catch (InvalidOperationException)
            {
                //  Don't care
            }

            var scripts = logger.Scripts;
            Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts.");

            var sql = scripts[0].Buffer.ToString();

            var deleteFromEquipmentOptionIndex = sql.IndexOf("DELETE FROM [opp].[EQUIPMENT_OPTION_TRN]");
            Assert.IsTrue(deleteFromEquipmentOptionIndex >= 0, "No delete from [opp].[EQUIPMENT_OPTION_TRN]");

            var deleteFromEquipmentOfferIndex = sql.IndexOf("DELETE FROM [opp].[EQUIPMENT_OFFER_TRN]");
            Assert.IsTrue(deleteFromEquipmentOfferIndex >= 0, "No delete from [opp].[EQUIPMENT_OFFER_TRN]");

            var deleteFromOfferIndex = sql.IndexOf("DELETE FROM [opp].[OFFER_TRN]");
            Assert.IsTrue(deleteFromOfferIndex >= 0, "No delete from [opp].[OFFER_TRN]");

            Assert.IsTrue(
                deleteFromEquipmentOptionIndex < deleteFromEquipmentOfferIndex,
                "Delete from [opp].[EQUIPMENT_OPTION_TRN] should appear before delete from [opp].[EQUIPMENT_OFFER_TRN]");

            Assert.IsTrue(
                deleteFromEquipmentOfferIndex < deleteFromOfferIndex,
                "Delete from [opp].[EQUIPMENT_OFFER_TRN] should appear before delete from [opp].[OFFER_TRN]");
        }
        public void insert_offer_with_gateway_offer_should_only_insert_offer()
        {
            var offer = new OfferDto
            {
                GatewayOffer = new GatewayOfferDto
                {
                    IsBilledYearly = true,
                    PeriodicCharge = 100
                },
                OfferReference = "Test offer",
                OpportunityGuid = Guid.NewGuid()
            };

            var logger = new MockSimpleSaveLogger();
            SimpleSaveExtensions.Logger = logger;

            try
            {
                using (IDbConnection connection = new SqlConnection())
                {
                    connection.Create(offer);
                }
            }
            catch (InvalidOperationException)
            {
                //  Don't care
            }

            var scripts = logger.Scripts;
            Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts.");

            var sql = scripts[0].Buffer.ToString();

            Assert.IsTrue(
                sql.Contains("INSERT INTO [opp].[OFFER_TRN]"),
                "Should insert into OFFER_TRN.");

            Assert.IsFalse(
                sql.Contains("[opp].[GATEWAY_OFFER_TRN]"),
                "Should not insert into GATEWAY_OFFER_TRN");
        }