Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODE RUB: Refactor Code #23

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ShouldSaveChangesSuccessfully()
// given
var client = new Client
{
Id = new System.Guid("e02a866b-1266-4033-93a2-ea94ac457ee8"),
Id = new Guid("e02a866b-1266-4033-93a2-ea94ac457ee8"),
cjdutoit marked this conversation as resolved.
Show resolved Hide resolved
};

// when
Expand All @@ -35,30 +35,30 @@ public void ShouldThrowDuplicateKeyExceptionOnSaveChanges()
// given
var client = new Client
{
Id = new System.Guid("e02a866b-1266-4033-93a2-ea94ac457ee8"),
Id = new Guid("e02a866b-1266-4033-93a2-ea94ac457ee8"),
cjdutoit marked this conversation as resolved.
Show resolved Hide resolved
};

// when
context.Add(client);
context.SaveChanges();

// when . then
Assert.Throws<DuplicateKeyCosmosException>(() =>
{
try
{
context.Add(client);
context.SaveChanges();
for (int i = 0; i < 2; i++)
{
context.Clients.Add(client);
context.SaveChanges();
}
}
catch (ArgumentException ex)
catch (ArgumentException argumentException)
{
throw new DuplicateKeyCosmosException(ex.Message);
throw new DuplicateKeyCosmosException(argumentException.Message);
}
finally
{
context.Clients.Remove(client);
context.SaveChanges();
}

});

// then
context.Remove(client);
context.SaveChanges();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System;
using Microsoft.EntityFrameworkCore;
using STX.EFxceptions.Cosmos.Base.Models.Exceptions;
using STX.EFxceptions.Cosmos.Tests.Acceptance.Models;
using Xunit;

namespace STX.EFxceptions.Cosmos.Tests.Acceptance
{
Expand Down
Loading