Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions GpioController/Models/FilterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ namespace GpioController.Models;

public class FilterSettings
{
public required List<int> AllowOnlyTheseChipsets { get; set; }
public required List<int> AllowOnlyTheseGpios { get; set; }
public FilterSettings()
{
AllowOnlyTheseChipsets = new();
AllowOnlyTheseGpios = new();
}

public List<int> AllowOnlyTheseChipsets { get; set; }
public List<int> AllowOnlyTheseGpios { get; set; }
}
2 changes: 1 addition & 1 deletion GpioController/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"Authorization": {
"Enabled": true,
"Enabled": false,
"AuthorizedEmails": [
"yourEmail@gmail.com"
],
Expand Down
42 changes: 41 additions & 1 deletion GpioControllerTests/Services/GpioServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class GpioServiceTests
{
private ICommandFactory commandFactory;

Check warning on line 15 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'commandFactory' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
private IOptions<FilterSettings> filterSettings;

Check warning on line 16 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'filterSettings' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
private ICommand<GpioInfoRequest, GpioInfoResult> command;

public GpioService GetSystemUnderTest()
Expand Down Expand Up @@ -73,7 +73,7 @@
}

[Fact]
public void OrderResultsByFilter_ShouldSortResults_WhenFilterIsPresent()
public void OrderResultsByFilter_WhenFilterIsPresent_ShouldSortResults()
{
var sut = GetSystemUnderTest();

Expand Down Expand Up @@ -107,8 +107,48 @@

var result = sut.OrderResultsByFilter(data).ToArray();

result[0].Id.Should().Be(81);

Check warning on line 110 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
result[1].Id.Should().Be(95);

Check warning on line 111 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
result[2].Id.Should().Be(80);

Check warning on line 112 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

[Fact]
public void OrderResultsByFilter_WhenNoFilterIsPresent_ShouldStillReturnOriginalResults()
{
var sut = GetSystemUnderTest();

A.CallTo(() => filterSettings.Value).Returns(new FilterSettings
{
AllowOnlyTheseChipsets = [],
AllowOnlyTheseGpios = []
});

var data = new List<Gpio>
{
new()
{
Chipset = 1,
Id = 95,
Name = "Gpio 95"
},
new()
{
Chipset = 1,
Id = 80,
Name = "Gpio 80"
},
new()
{
Chipset = 1,
Id = 81,
Name = "Gpio 81"
}
};

var result = sut.OrderResultsByFilter(data).ToArray();

result[0].Id.Should().Be(95);

Check warning on line 150 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
result[1].Id.Should().Be(80);

Check warning on line 151 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
result[2].Id.Should().Be(81);

Check warning on line 152 in GpioControllerTests/Services/GpioServiceTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
}
Loading