Skip to content

Instantly share code, notes, and snippets.

View dsibinski's full-sized avatar

Dawid Sibiński dsibinski

View GitHub Profile
[TestClass]
public class CarServiceContextInitTests
{
// to have the same Configuration object as in Startup
private IConfigurationRoot _configuration;
// represents database's configuration
private DbContextOptions<CarServiceContext> _options;
public CarServiceContextInitTests()
[TestMethod]
public void InitializeDatabaseWithDataTest()
{
using (var context = new CarServiceContext(_options))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var car1 = new Car()
{
[Test]
public void two_persons_are_properly_saved_with_the_same_event()
{
// given
var event1 = new Event
{
Name = "Volleyball",
Date = new DateTime(2017, 06, 18),
Place = "Sports hall"
};
SET XACT_ABORT ON
GO
BEGIN TRANSACTION
GO
-- SQL object 1 (CREATE/ALTER/INSERT etc...)
GO
-- SQL object 2 (CREATE/ALTER/INSERT etc...)
GO
SET xact_abort ON
GO
BEGIN TRANSACTION
GO
CREATE TABLE [dbo].[People]
(
[id] [INT] IDENTITY(1, 1) NOT NULL,
[name] [NVARCHAR](max) NOT NULL,
INssSERT INTO dbo.Persons -- syntax error - 'INssSERT' instead of 'INSERT'
(NAME)
VALUES ('Dawid')
SET xact_abort ON
GO
BEGIN TRANSACTION
GO
CREATE TABLE [dbo].[People]
(
[id] [INT] IDENTITY(1, 1) NOT NULL,
[name] [NVARCHAR](max) NOT NULL,
INssSERT INTO dbo.Persons (NAME) VALUES ('Dawid')
GO
if @@error != 0 raiserror('Error in script execution', 20, -1) with log
GO
SET xact_abort ON
GO
BEGIN TRANSACTION
GO
CREATE TABLE [dbo].[People]
(
[id] [INT] IDENTITY(1, 1) NOT NULL,
[name] [NVARCHAR](max) NOT NULL,
Msg 208, Level 16, State 1, Line 33
Invalid object name 'dbo.Persons'.
Msg 3902, Level 16, State 1, Line 39
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.