diff --git a/src/DocumentDbTests/Indexes/UniqueIndexTests.cs b/src/DocumentDbTests/Indexes/UniqueIndexTests.cs index 8d6865f875..aae74ee8f1 100644 --- a/src/DocumentDbTests/Indexes/UniqueIndexTests.cs +++ b/src/DocumentDbTests/Indexes/UniqueIndexTests.cs @@ -83,14 +83,8 @@ public void session.Store(secondDocument); //3. Unique Exception Was thrown - try - { - session.SaveChanges(); - } - catch (DocumentAlreadyExistsException exception) - { - ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); - } + var exception = Should.Throw(() => session.SaveChanges()); + ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); } [Fact] @@ -109,14 +103,8 @@ public void session.Store(secondDocument); //3. Unique Exception Was thrown - try - { - session.SaveChanges(); - } - catch (DocumentAlreadyExistsException exception) - { - ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); - } + var exception = Should.Throw(() => session.SaveChanges()); + ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); } [Fact] @@ -139,14 +127,8 @@ public void session.Events.Append(secondEvent.UserId, secondEvent); //3. Unique Exception Was thrown - try - { - session.SaveChanges(); - } - catch (MartenCommandException exception) - { - ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); - } + var exception = Should.Throw(() => session.SaveChanges()); + ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); } [Fact] @@ -166,13 +148,7 @@ public void session.Events.Append(secondEvent.UserId, secondEvent); //3. Unique Exception Was thrown - try - { - session.SaveChanges(); - } - catch (DocumentAlreadyExistsException exception) - { - ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); - } + var exception = Should.Throw(() => session.SaveChanges()); + ((PostgresException)exception.InnerException)?.SqlState.ShouldBe(UniqueSqlState); } }