Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbesen committed Oct 29, 2024
1 parent 30aafc2 commit e998e4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
5 changes: 3 additions & 2 deletions StpFoodBlazor/StpFoodBlazor/Helpers/DealFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ public DealEvent[] filter() {
}

DealEvent[] filteredDeals = Deals;
if (Day != null) {

if (!string.IsNullOrWhiteSpace(Day)) {
filteredDeals = filterByDay(filteredDeals, Day);
}

if (Name != null) {
if (!string.IsNullOrWhiteSpace(Name)) {
filteredDeals = filterByName(filteredDeals, Name);
}

Expand Down
35 changes: 13 additions & 22 deletions StpFoodBlazor/StpFoodBlazorTest/Helpers/DealFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
using StpFoodBlazor.Services;
using System.Threading.Tasks;
using System;
using System.Runtime.ConstrainedExecution;
using Bunit.Extensions;

namespace StpFoodBlazorTest.Helpers {

public class DealFilterTest {
private readonly DealEvent[] deals;
private readonly DealFilter filter;
public DealFilterTest() {
deals = getDeals().Result;
filter = new DealFilter();
}

[Fact]
public void ShouldHandleEmptyDeals() {
DealFilter filter = new DealFilter();

DealEvent[] filteredDeals = filter.filter();

Assert.Empty(filteredDeals);
}

[Fact]
public async Task ShouldReturnInputWhenNoFilterConditions() {
DealEvent[] deals = await getDeals();
public void ShouldReturnInputWhenNoFilterConditions() {
int dealsLength = deals.Length;
DealFilter filter = new DealFilter();
filter.Deals = deals;

DealEvent[] filteredDeals = filter.filter();
Expand All @@ -32,10 +33,8 @@ public async Task ShouldReturnInputWhenNoFilterConditions() {
}

[Fact]
public async Task ShouldReturnFilteredByDay() {
public void ShouldReturnFilteredByDay() {
String day = "Monday";
DealEvent[] deals = await getDeals();
DealFilter filter = new DealFilter();
filter.Deals = deals;
filter.Day = day;

Expand All @@ -46,10 +45,8 @@ public async Task ShouldReturnFilteredByDay() {
}

[Fact]
public async Task ShouldReturnFilteredByName() {
public void ShouldReturnFilteredByName() {
String name = "Pino's Pizza";
DealEvent[] deals = await getDeals();
DealFilter filter = new DealFilter();
filter.Deals = deals;
filter.Name = name;

Expand All @@ -60,11 +57,9 @@ public async Task ShouldReturnFilteredByName() {
}

[Fact]
public async Task ShouldReturnFilteredByNameAndDay() {
public void ShouldReturnFilteredByNameAndDay() {
String name = "Pino's Pizza";
String day = "Tuesday";
DealEvent[] deals = await getDeals();
DealFilter filter = new DealFilter();
filter.Deals = deals;
filter.Name = name;
filter.Day = day;
Expand All @@ -79,9 +74,7 @@ public async Task ShouldReturnFilteredByNameAndDay() {
}

[Fact]
public async Task ShouldReturnFilteredByAlcoholTrue() {
DealEvent[] deals = await getDeals();
DealFilter filter = new DealFilter();
public void ShouldReturnFilteredByAlcoholTrue() {
filter.Deals = deals;
filter.Alcohol = true;

Expand All @@ -94,9 +87,7 @@ public async Task ShouldReturnFilteredByAlcoholTrue() {
}

[Fact]
public async Task ShouldReturnFilteredByAlcoholFalse() {
DealEvent[] deals = await getDeals();
DealFilter filter = new DealFilter();
public void ShouldReturnFilteredByAlcoholFalse() {
filter.Deals = deals;
filter.Alcohol = false;

Expand Down

0 comments on commit e998e4c

Please sign in to comment.