Skip to content
Draft
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
6 changes: 3 additions & 3 deletions HangTab.Tests/Extensions/ListItemExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void SetLowestBowlerHangCount_EmptyList_DoesNotThrow()
public void SetBowlerHangSumByWeeks_SetsHangCountCorrectly()
{
// Arrange
var bowler1 = new BowlerListItemViewModel(id: 1, name: "A", isSub: false);
var bowler2 = new BowlerListItemViewModel(id: 2, name: "B", isSub: false);
var bowler1 = new BowlerListItemViewModel{ Id = 1, Name = "A", IsSub = true };
var bowler2 = new BowlerListItemViewModel{ Id = 2, Name = "B", IsSub = false };
var weeks = new List<Week>
{
new()
Expand Down Expand Up @@ -90,7 +90,7 @@ public void SetBowlerHangSumByWeeks_WithSubs_SumsCorrectly()
// Arrange
var subId = 10;
var hangCount = 5;
var bowler = new BowlerListItemViewModel(id:subId, name: "Super Sub", isSub: true);
var bowler = new BowlerListItemViewModel{ Id = subId, Name = "Super Sub", IsSub = true };
var weeks = new List<Week>
{
new()
Expand Down
26 changes: 2 additions & 24 deletions HangTab.Tests/Mappers/BowlerListItemViewModelMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ public class BowlerListItemViewModelMapperTests
public void Map_FromPersonList_ReturnsCorrectViewModel()
{
// Arrange
var mapper = new BowlerListItemViewModelMapper();
var people = new List<Person>
{
new() { Id = 1, Name = "Alice", IsSub = false, ImageUrl = "img1" },
new() { Id = 2, Name = "Bob", IsSub = true, ImageUrl = "img2" }
};

// Act
var actual = mapper.Map(people).ToList();
var actual = people.ToBowlerListItemViewModelList().ToList();

// Assert
Assert.Equal(2, actual.Count);
Expand All @@ -38,7 +37,6 @@ public void Map_FromPersonList_ReturnsCorrectViewModel()
public void Map_FromBowlerList_ReturnsCorrectViewModel()
{
// Arrange
var mapper = new BowlerListItemViewModelMapper();
var bowlers = new List<Bowler>
{
new() {
Expand All @@ -51,7 +49,7 @@ public void Map_FromBowlerList_ReturnsCorrectViewModel()
};

// Act
var vm = mapper.Map(bowlers).ToList();
var vm = bowlers.ToBowlerListItemViewModelList().ToList();

// Assert
Assert.Single(vm);
Expand All @@ -64,24 +62,4 @@ public void Map_FromBowlerList_ReturnsCorrectViewModel()
Assert.Equal("img3", actual.ImageUrl);
Assert.Equal(Status.UsingSub, actual.Status);
}

[Fact]
public void Map_NullPerson_ThrowsArgumentNullException()
{
// Arrange
var mapper = new BowlerListItemViewModelMapper();

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map((IEnumerable<Person>)null!));
}

[Fact]
public void Map_NullBowler_ThrowsArgumentNullException()
{
// Arrange
var mapper = new BowlerListItemViewModelMapper();

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map((IEnumerable<Bowler>)null!));
}
}
30 changes: 14 additions & 16 deletions HangTab.Tests/Mappers/BowlerMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ public class BowlerMapperTests
public void Map_ValidCurrentWeekListItemViewModel_MapsToBowler()
{
// Arrange
var mapper = new BowlerMapper();
var vm = new CurrentWeekListItemViewModel(
weekId: 2,
bowlerId: 10,
personId: 5,
subId: 7,
status: Status.UsingSub,
hangCount: 3,
name: "Test Bowler",
isSub: false,
initials: "TB",
imageUrl: "img.png"
);
var vm = new CurrentWeekListItemViewModel
{
WeekId = 2,
BowlerId = 10,
PersonId = 5,
SubId = 7,
Status = Status.UsingSub,
HangCount = 3,
Name = "Test Bowler",
IsSub = false,
ImageUrl = "img.png"
};

// Act
var actual = mapper.Map(vm);
var actual = vm.ToBowler();

// Assert
Assert.Equal(10, actual.Id);
Expand All @@ -38,10 +37,9 @@ public void Map_ValidCurrentWeekListItemViewModel_MapsToBowler()
public void Map_NullViewModel_ThrowsArgumentNullException()
{
// Arrange
var mapper = new BowlerMapper();
CurrentWeekListItemViewModel? vm = null;

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map(vm!));
Assert.Throws<ArgumentNullException>(() => vm.ToBowler());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class CurrentWeekListItemViewModelMapperTests
public void Map_ValidBowlerList_MapsToViewModels()
{
// Arrange
var mapper = new CurrentWeekListItemViewModelMapper();
var bowlers = new List<Bowler>
{
new() {
Expand Down Expand Up @@ -46,7 +45,7 @@ public void Map_ValidBowlerList_MapsToViewModels()
};

// Act
var actual = mapper.Map(bowlers).ToList();
var actual = bowlers.ToCurrentWeekListItemViewModelList().ToList();

// Assert
Assert.Equal(2, actual.Count);
Expand Down Expand Up @@ -78,9 +77,9 @@ public void Map_ValidBowlerList_MapsToViewModels()
public void Map_NullBowlerList_ThrowsArgumentNullException()
{
// Arrange
var mapper = new CurrentWeekListItemViewModelMapper();
List<Bowler> bowlers = null!;

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map(null!));
Assert.Throws<ArgumentNullException>(() => bowlers.ToCurrentWeekListItemViewModelList());
}
}
24 changes: 10 additions & 14 deletions HangTab.Tests/Mappers/PersonMapperTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using HangTab.Enums;
using HangTab.Mappers;
using HangTab.ViewModels.Items;

Expand All @@ -10,19 +9,16 @@ public class PersonMapperTests
public void Map_ValidBowlerListItemViewModel_MapsToPerson()
{
// Arrange
var mapper = new PersonMapper();
var vm = new BowlerListItemViewModel(
id: 42,
name: "Jane Doe",
isSub: true,
bowlerId: 7,
hangCount: 3,
imageUrl: "img.png",
status: Status.UsingSub
);
var vm = new BowlerListItemViewModel
{
Id = 42,
Name = "Jane Doe",
IsSub = true,
ImageUrl = "img.png"
};

// Act
var person = mapper.Map(vm);
var person = vm.ToPerson();

// Assert
Assert.Equal(42, person.Id);
Expand All @@ -35,9 +31,9 @@ public void Map_ValidBowlerListItemViewModel_MapsToPerson()
public void Map_NullViewModel_ThrowsArgumentNullException()
{
// Arrange
var mapper = new PersonMapper();
BowlerListItemViewModel vm = null!;

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map(null!));
Assert.Throws<ArgumentNullException>(() => vm.ToPerson());
}
}
7 changes: 3 additions & 4 deletions HangTab.Tests/Mappers/SubListItemViewModelMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ public class SubListItemViewModelMapperTests
public void Map_ValidPersonList_MapsToViewModels()
{
// Arrange
var mapper = new SubListItemViewModelMapper();
var people = new List<Person>
{
new() { Id = 1, Name = "Alice", IsSub = true, ImageUrl = "img1.png" },
new() { Id = 2, Name = "Bob", IsSub = false, ImageUrl = "img2.png" }
};

// Act
var actual = mapper.Map(people).ToList();
var actual = people.ToSubListItemViewModelList().ToList();

// Assert
Assert.Equal(2, actual.Count);
Expand All @@ -37,9 +36,9 @@ public void Map_ValidPersonList_MapsToViewModels()
public void Map_NullPeopleList_ThrowsArgumentNullException()
{
// Arrange
var mapper = new SubListItemViewModelMapper();
List<Person> people = null!;

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map(null!));
Assert.Throws<ArgumentNullException>(() => people.ToSubListItemViewModelList());
}
}
15 changes: 6 additions & 9 deletions HangTab.Tests/Mappers/WeekListItemViewModelMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class WeekListItemViewModelMapperTests
public void Map_ValidWeeks_MapsToViewModels()
{
// Arrange
var mapper = new WeekListItemViewModelMapper();
var weeks = new List<Week>
{
new()
Expand Down Expand Up @@ -41,26 +40,25 @@ public void Map_ValidWeeks_MapsToViewModels()
};

// Act
var actual = mapper.Map(weeks).ToList();
var actual = weeks.ToWeekListItemViewModelList().ToList();

// Assert
Assert.Single(actual);
var vm = actual[0];
Assert.Equal(1, vm.Id);
Assert.Equal(2, vm.Number);
Assert.Equal(3, vm.BusRides);
Assert.Equal(7, vm.HangCount); // 5 + 2
Assert.Equal(7, vm.TotalHangCount); // 5 + 2
}

[Fact]
public void Map_EmptyWeeks_ReturnsEmpty()
{
// Arrange
var mapper = new WeekListItemViewModelMapper();
var weeks = new List<Week>();

// Act
var actual = mapper.Map(weeks).ToList();
var actual = weeks.ToWeekListItemViewModelList().ToList();

// Assert
Assert.Empty(actual);
Expand All @@ -70,17 +68,16 @@ public void Map_EmptyWeeks_ReturnsEmpty()
public void Map_NullWeeks_ThrowsArgumentNullException()
{
// Arrange
var mapper = new WeekListItemViewModelMapper();
List<Week>? weeks = null!;

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map(null!));
Assert.Throws<ArgumentNullException>(() => weeks.ToWeekListItemViewModelList());
}

[Fact]
public void Map_WeekWithNullBowlers_ThrowsArgumentNullException()
{
// Arrange
var mapper = new WeekListItemViewModelMapper();
var weeks = new List<Week>
{
new()
Expand All @@ -93,6 +90,6 @@ public void Map_WeekWithNullBowlers_ThrowsArgumentNullException()
};

// Act & Assert
Assert.Throws<ArgumentNullException>(() => mapper.Map(weeks).ToList());
Assert.Throws<ArgumentNullException>(() => weeks.ToWeekListItemViewModelList().ToList());
}
}
Loading
Loading