Skip to content

Commit

Permalink
Merge pull request #4 from SnowSE/garion-boundary-tests
Browse files Browse the repository at this point in the history
(Garion) Added boundary tests
  • Loading branch information
KalinAtSnow authored Mar 1, 2024
2 parents ffaac8a + efefcc6 commit b6140c6
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 52 deletions.
57 changes: 57 additions & 0 deletions KakeysBakery.Tests/AddOnTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public async Task Get_Addon_ById()
Assert.Equal(testaddon.Description, result.Description);
}

[Fact]
public async Task Get_AddOn_ById_When_NotExists()
{
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Addon>($"api/addon/get/{-1}");
});
}

[Fact]
public async Task Get_Addon_ByName()
{
Expand All @@ -93,6 +102,15 @@ public async Task Get_Addon_ByName()
Assert.Equal(testaddon.Description, result.Description);
}

[Fact]
public async Task Get_AddOn_ByName_When_NotExists()
{
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Addon>($"api/addon/get_by_name/foo");
});
}

[Fact]
public async Task Create_AddOn()
{
Expand Down Expand Up @@ -120,6 +138,32 @@ public async Task Create_AddOn()
Assert.Equal(testaddon.Description, result.Description);
}

[Fact]
public async Task Create_AddOn_When_AlreadyExists()
{
// ARRANGE
Addon existing = new Addon()
{
Description = "TestDesc",
Addontypename = "TestName",
Id = 101,
Suggestedprice = (decimal)100.25
};

// ACT
await client.PostAsJsonAsync("api/addon/add", existing);

// Assert
try
{
await client.PostAsJsonAsync("api/addon/add", existing);
}
catch (Exception ex)
{
Assert.Fail("Expected no exception, but got:" + ex.Message);
}
}

[Fact]
public async Task Edit_AddOn()
{
Expand Down Expand Up @@ -169,4 +213,17 @@ await Assert.ThrowsAsync<HttpRequestException>(async () =>
await client.GetFromJsonAsync<Addon>($"api/addon/get/{testaddon.Id}");
});
}

[Fact]
public async Task Delete_AddOn_When_NotExists()
{
try
{
await client.DeleteAsync($"api/addon/delete/{-1}");
}
catch (Exception ex)
{
Assert.Fail("Expected no exception, but got:" + ex.Message);
}
}
}
59 changes: 58 additions & 1 deletion KakeysBakery.Tests/BaseGoodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public async Task Get_BaseGood_ById()
Assert.Equal(testBaseGood.Id, result.Id);
}

[Fact]
public async Task Get_BaseGood_ById_When_NotExists()
{
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Basegood>($"api/basegood/get/{-1}");
});
}

[Fact]
public async Task Get_BaseGood_ByName()
{
Expand All @@ -89,6 +98,15 @@ public async Task Get_BaseGood_ByName()
Assert.Equal(testBaseGood.Id, result.Id);
}

[Fact]
public async Task Get_BaseGood_ByName_When_NotExists()
{
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Basegood>($"api/basegood/get_by_name/foo");
});
}

[Fact]
public async Task Create_BaseGood()
{
Expand All @@ -113,6 +131,32 @@ public async Task Create_BaseGood()
Assert.Equal(testBaseGood.Id, result.Id);
}

[Fact]
public async Task Create_BaseGood_When_AlreadyExists()
{
// ARRANGE
Basegood existing = new()
{
Basegoodname = "TestName",
Id = 101,
Suggestedprice = (decimal)100.25,
Flavor = "testFlavor"
};

// ACT
await client.PostAsJsonAsync("api/basegood/add", existing);

// Assert
try
{
await client.PostAsJsonAsync("api/basegood/add", existing);
}
catch (Exception ex)
{
Assert.Fail("Expected no exception, but got:" + ex.Message);
}
}

[Fact]
public async Task Edit_BaseGood()
{
Expand Down Expand Up @@ -162,7 +206,20 @@ public async Task Delete_BaseGood()
// ASSERT
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Addon>($"api/basegood/get/{testBaseGood.Id}");
await client.GetFromJsonAsync<Basegood>($"api/basegood/get/{testBaseGood.Id}");
});
}

[Fact]
public async Task Delete_BaseGood_When_NotExists()
{
try
{
await client.DeleteAsync($"api/basegood/delete/{-1}");
}
catch (Exception ex)
{
Assert.Fail("Expected no exception, but got:" + ex.Message);
}
}
}
94 changes: 73 additions & 21 deletions KakeysBakery.Tests/CustomerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ public async Task Get_CustomerList()
Surname = "last",
Phone = "8018018888",
Preferredcontact = "Text"

};

await client.PostAsJsonAsync("api/Customer/add", testCustomer);
await client.PostAsJsonAsync("api/customer/add", testCustomer);

// ACT
List<Customer>? Customers = await client.GetFromJsonAsync<List<Customer>>("api/Customer/getall");
List<Customer>? Customers = await client.GetFromJsonAsync<List<Customer>>("api/customer/getall");

// ASSERT
Assert.NotNull(Customers);
Expand All @@ -61,13 +60,12 @@ public async Task Get_Customer_ById()
Surname = "last",
Phone = "8018018888",
Preferredcontact = "Text"

};

await client.PostAsJsonAsync("api/Customer/add", testCustomer);
await client.PostAsJsonAsync("api/customer/add", testCustomer);

// ACT
Customer? result = await client.GetFromJsonAsync<Customer>($"api/Customer/get/{testCustomer.Id}");
Customer? result = await client.GetFromJsonAsync<Customer>($"api/customer/get/{testCustomer.Id}");

// ASSERT
Assert.NotNull(result);
Expand All @@ -79,6 +77,15 @@ public async Task Get_Customer_ById()
Assert.Equal(testCustomer.Preferredcontact, result.Preferredcontact);
}

[Fact]
public async Task Get_Customer_ById_When_NotExists()
{
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Customer>($"api/customer/get/{-1}");
});
}

[Fact]
public async Task Get_Customer_ByName()
{
Expand All @@ -91,13 +98,12 @@ public async Task Get_Customer_ByName()
Surname = "aheie",
Phone = "8018018888",
Preferredcontact = "Text"

};

await client.PostAsJsonAsync("api/Customer/add", testCustomer);
await client.PostAsJsonAsync("api/customer/add", testCustomer);

// ACT
Customer? result = await client.GetFromJsonAsync<Customer>($"api/Customer/get_by_name/{testCustomer.Forename}/{testCustomer.Surname}");
Customer? result = await client.GetFromJsonAsync<Customer>($"api/customer/get_by_name/{testCustomer.Forename}/{testCustomer.Surname}");

// ASSERT
Assert.NotNull(result);
Expand All @@ -109,6 +115,15 @@ public async Task Get_Customer_ByName()
Assert.Equal(testCustomer.Preferredcontact, result.Preferredcontact);
}

[Fact]
public async Task Get_Customer_ByName_When_NotExists()
{
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Customer>($"api/customer/get_by_name/foo");
});
}

[Fact]
public async Task Create_Customer()
{
Expand All @@ -121,12 +136,11 @@ public async Task Create_Customer()
Surname = "last",
Phone = "8018018888",
Preferredcontact = "Text"

};

// ACT
await client.PostAsJsonAsync("api/Customer/add", testCustomer);
Customer? result = await client.GetFromJsonAsync<Customer>($"api/Customer/get/{testCustomer.Id}");
await client.PostAsJsonAsync("api/customer/add", testCustomer);
Customer? result = await client.GetFromJsonAsync<Customer>($"api/customer/get/{testCustomer.Id}");

// ASSERT
Assert.NotNull(result);
Expand All @@ -138,6 +152,33 @@ public async Task Create_Customer()
Assert.Equal(testCustomer.Preferredcontact, result.Preferredcontact);
}

[Fact]
public async Task Create_Customer_When_AlreadyExists()
{
// ARRANGE
Customer testCustomer = new Customer()
{
Id = 5,
Email = "test Email",
Forename = "first",
Surname = "last",
Phone = "8018018888",
Preferredcontact = "Text"
};

await client.PostAsJsonAsync("api/customer/add", testCustomer);

// ASSERT
try
{
await client.PostAsJsonAsync("api/customer/add", testCustomer);
}
catch (Exception ex)
{
Assert.Fail("Expected no exception, but got:" + ex.Message);
}
}

[Fact]
public async Task Edit_Customer()
{
Expand All @@ -150,15 +191,14 @@ public async Task Edit_Customer()
Surname = "last",
Phone = "8018018888",
Preferredcontact = "Text"

};

await client.PostAsJsonAsync("api/Customer/add", testCustomer);
await client.PostAsJsonAsync("api/customer/add", testCustomer);

// ACT
testCustomer.Surname = "Edited Test Married Name";
await client.PatchAsJsonAsync("api/Customer/update", testCustomer);
Customer? result = await client.GetFromJsonAsync<Customer>($"api/Customer/get/{testCustomer.Id}");
await client.PatchAsJsonAsync("api/customer/update", testCustomer);
Customer? result = await client.GetFromJsonAsync<Customer>($"api/customer/get/{testCustomer.Id}");

// ASSERT
Assert.NotNull(result);
Expand All @@ -179,21 +219,33 @@ public async Task Delete_Customer()
Surname = "last",
Phone = "8018018888",
Preferredcontact = "Text"

};

await client.PostAsJsonAsync("api/Customer/add", testCustomer);
await client.PostAsJsonAsync("api/customer/add", testCustomer);

// Assert
Assert.NotNull(await client.GetFromJsonAsync<Customer>($"api/Customer/get/{testCustomer.Id}"));
Assert.NotNull(await client.GetFromJsonAsync<Customer>($"api/customer/get/{testCustomer.Id}"));

// ACT
await client.DeleteAsync($"api/Customer/delete/{testCustomer.Id}");
await client.DeleteAsync($"api/customer/delete/{testCustomer.Id}");

// ASSERT
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await client.GetFromJsonAsync<Customer>($"api/Customer/get/{testCustomer.Id}");
await client.GetFromJsonAsync<Customer>($"api/customer/get/{testCustomer.Id}");
});
}

[Fact]
public async Task Delete_Customer_When_NotExists()
{
try
{
await client.DeleteAsync($"api/customer/delete/{-1}");
}
catch (Exception ex)
{
Assert.Fail("Expected no exception, but got:" + ex.Message);
}
}
}
Loading

0 comments on commit b6140c6

Please sign in to comment.