Skip to content

Commit

Permalink
Changed delete method to return bool, fixed typos and other problems …
Browse files Browse the repository at this point in the history
…based on PR review
  • Loading branch information
mkoper02 committed May 6, 2024
1 parent e5d67f2 commit 034e2cb
Show file tree
Hide file tree
Showing 12 changed files with 679 additions and 426 deletions.
89 changes: 57 additions & 32 deletions Server/ReasnAPI/ReasnAPI.Tests/Services/AddressServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using ReasnAPI.Models.Database;
using Moq;
using Moq.EntityFrameworkCore;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using ReasnAPI.Services;
using Moq;
using Moq.EntityFrameworkCore;

namespace ReasnAPI.Tests.Services {
namespace ReasnAPI.Tests.Services
{
[TestClass]
public class AddressServiceTests {
public class AddressServiceTests
{
[TestMethod]
public void GetAddressById_AddressExists_AddressReturned() {
public void GetAddressById_AddressExists_AddressReturned()
{
var mockContext = new Mock<ReasnContext>();

var address = new Address {
var address = new Address
{
Id = 1,
City = "City",
Country = "Country",
Expand All @@ -20,7 +24,7 @@ public void GetAddressById_AddressExists_AddressReturned() {
ZipCode = "ZipCode"
};

mockContext.Setup(c => c.Addresses).ReturnsDbSet([ address ]);
mockContext.Setup(c => c.Addresses).ReturnsDbSet([address]);

var addressService = new AddressService(mockContext.Object);

Expand All @@ -35,7 +39,8 @@ public void GetAddressById_AddressExists_AddressReturned() {
}

[TestMethod]
public void GetAddressById_AddressDoesNotExist_NullReturned() {
public void GetAddressById_AddressDoesNotExist_NullReturned()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

Expand All @@ -47,10 +52,12 @@ public void GetAddressById_AddressDoesNotExist_NullReturned() {
}

[TestMethod]
public void GetAllAddresses_AddressesExist_AddressesReturned() {
public void GetAllAddresses_AddressesExist_AddressesReturned()
{
var mockContext = new Mock<ReasnContext>();

var address1 = new Address {
var address1 = new Address
{
Id = 1,
City = "City",
Country = "Country",
Expand All @@ -59,7 +66,8 @@ public void GetAllAddresses_AddressesExist_AddressesReturned() {
ZipCode = "ZipCode"
};

var address2 = new Address {
var address2 = new Address
{
Id = 2,
City = "City",
Country = "Country",
Expand All @@ -68,7 +76,7 @@ public void GetAllAddresses_AddressesExist_AddressesReturned() {
ZipCode = "ZipCode"
};

mockContext.Setup(c => c.Addresses).ReturnsDbSet([ address1, address2 ]);
mockContext.Setup(c => c.Addresses).ReturnsDbSet([address1, address2]);

var addressService = new AddressService(mockContext.Object);

Expand All @@ -79,7 +87,8 @@ public void GetAllAddresses_AddressesExist_AddressesReturned() {
}

[TestMethod]
public void GetAllAddresses_NoAddresses_EmptyListReturned() {
public void GetAllAddresses_NoAddresses_EmptyListReturned()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

Expand All @@ -92,10 +101,12 @@ public void GetAllAddresses_NoAddresses_EmptyListReturned() {
}

[TestMethod]
public void GetAddressesByFilter_AddressesExist_AddressesReturned() {
public void GetAddressesByFilter_AddressesExist_AddressesReturned()
{
var mockContext = new Mock<ReasnContext>();

var address1 = new Address {
var address1 = new Address
{
Id = 1,
City = "City",
Country = "Country",
Expand All @@ -104,7 +115,8 @@ public void GetAddressesByFilter_AddressesExist_AddressesReturned() {
ZipCode = "ZipCode"
};

var address2 = new Address {
var address2 = new Address
{
Id = 2,
City = "City",
Country = "Country",
Expand All @@ -123,7 +135,8 @@ public void GetAddressesByFilter_AddressesExist_AddressesReturned() {
}

[TestMethod]
public void GetAddressesByFilter_NoAddresses_EmptyListReturned() {
public void GetAddressesByFilter_NoAddresses_EmptyListReturned()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

Expand All @@ -136,13 +149,15 @@ public void GetAddressesByFilter_NoAddresses_EmptyListReturned() {
}

[TestMethod]
public void CreateAddress_AddressCreated_AddressReturned() {
public void CreateAddress_AddressCreated_AddressReturned()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

var addressService = new AddressService(mockContext.Object);

var addressDto = new AddressDto {
var addressDto = new AddressDto
{
City = "City",
Country = "Country",
State = "State",
Expand All @@ -161,7 +176,8 @@ public void CreateAddress_AddressCreated_AddressReturned() {
}

[TestMethod]
public void CreateAddress_AddressDtoIsNull_NullReturned() {
public void CreateAddress_AddressDtoIsNull_NullReturned()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

Expand All @@ -173,10 +189,12 @@ public void CreateAddress_AddressDtoIsNull_NullReturned() {
}

[TestMethod]
public void UpdateAddress_AddressUpdated_AddressReturned() {
public void UpdateAddress_AddressUpdated_AddressReturned()
{
var mockContext = new Mock<ReasnContext>();

var address = new Address {
var address = new Address
{
Id = 1,
City = "City",
Country = "Country",
Expand All @@ -185,11 +203,12 @@ public void UpdateAddress_AddressUpdated_AddressReturned() {
ZipCode = "ZipCode"
};

mockContext.Setup(c => c.Addresses).ReturnsDbSet([ address ]);
mockContext.Setup(c => c.Addresses).ReturnsDbSet([address]);

var addressService = new AddressService(mockContext.Object);

var addressDto = new AddressDto {
var addressDto = new AddressDto
{
City = "City2",
Country = "Country2",
State = "State2",
Expand All @@ -208,13 +227,15 @@ public void UpdateAddress_AddressUpdated_AddressReturned() {
}

[TestMethod]
public void UpdateAddress_AddressDoesNotExist_NullReturned() {
public void UpdateAddress_AddressDoesNotExist_NullReturned()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

var addressService = new AddressService(mockContext.Object);

var addressDto = new AddressDto {
var addressDto = new AddressDto
{
City = "City2",
Country = "Country2",
State = "State2",
Expand All @@ -228,7 +249,8 @@ public void UpdateAddress_AddressDoesNotExist_NullReturned() {
}

[TestMethod]
public void UpdateAddress_AddressDtoIsNull_NullReturned() {
public void UpdateAddress_AddressDtoIsNull_NullReturned()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

Expand All @@ -240,10 +262,12 @@ public void UpdateAddress_AddressDtoIsNull_NullReturned() {
}

[TestMethod]
public void DeleteAddress_AdddressExists_AddressDeleted() {
public void DeleteAddress_AdddressExists_AddressDeleted()
{
var mockContext = new Mock<ReasnContext>();

var address = new Address {
var address = new Address
{
Id = 1,
City = "City",
Country = "Country",
Expand All @@ -252,7 +276,7 @@ public void DeleteAddress_AdddressExists_AddressDeleted() {
ZipCode = "ZipCode"
};

mockContext.Setup(c => c.Addresses).ReturnsDbSet([ address ]);
mockContext.Setup(c => c.Addresses).ReturnsDbSet([address]);

var addressService = new AddressService(mockContext.Object);

Expand All @@ -262,7 +286,8 @@ public void DeleteAddress_AdddressExists_AddressDeleted() {
}

[TestMethod]
public void DeleteAddress_AddressDoesNotExist_NothingHappens() {
public void DeleteAddress_AddressDoesNotExist_NothingHappens()
{
var mockContext = new Mock<ReasnContext>();
mockContext.Setup(c => c.Addresses).ReturnsDbSet([]);

Expand Down
Loading

0 comments on commit 034e2cb

Please sign in to comment.