Search code examples
sql-serverunit-testingtestingfitnessedbfit

insert xml data using dbfit


I'd like to insert some test xml data into a table before executing a stored proc that parses the xml and populates another table.

Setup: Insert test data
|execute|!- 
 Insert into dbo.XML_Table
  Values
  (
  '<Document File="123" NoOfPages="1">
  <Page Number="1">
  </Page>
</Document>',
  GetDate()
  )
-!|

The query works fine in SQL Server management studio

Insert into dbo.XML_Table
      Values
      (
      '<Document File="123" NoOfPages="1">
      <Page Number="1">
      </Page>
    </Document>',
      GetDate()
      )

However, when I save the test in dbfit, it looks like this in the browser

Setup: Insert test data
execute
Insert into dbo.XML_Table Values ( 99, ' ', GetDate(), 'gilbert' )

When I run the test, it appears to execute ok. There are no errors. I ran SQL Server profiler and can't see the query there.

I have 30+ other tests in this project that run ok, all selecting data.

Can anyone help?


Solution

  • Looks like the XML markup is getting confused with HTML markup. Try escaping the XML:

    '&lt;Document File="123" NoOfPages="1"&gt;

    etc