Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using HelpMyStreet.Contracts.CommunicationService.Request;
using HelpMyStreet.Contracts.UserService.Request;
using HelpMyStreet.Contracts.UserService.Response;
using HelpMyStreet.Utils.Models;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UserService.Core.Interfaces.Repositories;
using UserService.Core.Interfaces.Services;
using UserService.Handlers;

namespace UserService.UnitTests
{
public class GetIncompleteRegistrationStatusHandlerTests
{
private GetIncompleteRegistrationStatusHandler _classUnderTest;
private List<UserRegistrationStep> _users;
private Mock<IRepository> _repository;

[SetUp]
public void SetUp()
{
SetupRepository();
_classUnderTest = new GetIncompleteRegistrationStatusHandler(_repository.Object);
}

private void SetupRepository()
{
_repository = new Mock<IRepository>();

_repository.Setup(x => x.GetIncompleteRegistrationStatusAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(() => _users);
}

[Test]
public async Task GivenVolRegIncompleteThenVolsReturned()
{
_users = new List<UserRegistrationStep>()
{
new UserRegistrationStep()
{
UserId = 1,
RegistrationStep = 2,
DateCompleted = DateTime.Now
},
new UserRegistrationStep()
{
UserId = 2,
RegistrationStep = 2,
DateCompleted = DateTime.Now
}
};
var request = new GetIncompleteRegistrationStatusRequest();
var result = await _classUnderTest.Handle(request, CancellationToken.None);
Assert.AreEqual(_users, result.Users);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,29 @@ public class GetVolunteersByPostcodeAndActivityHandlerTests
{
private Mock<IHelperService> _helperService;
private Mock<IRepository> _repository;

private IEnumerable<HelperWithinRadiusDTO> _helpers;

private GetVolunteersByPostcodeAndActivityHandler _classUnderTest;

[SetUp]
public void SetUp()
{

_repository = new Mock<IRepository>();
SetUpRepository();
SetUpHelperService();

_classUnderTest = new GetVolunteersByPostcodeAndActivityHandler(_helperService.Object, _repository.Object);
}

private void SetUpRepository()
{
_repository = new Mock<IRepository>();
}

private void SetUpHelperService()
{
_helpers = new List<HelperWithinRadiusDTO>
{
new HelperWithinRadiusDTO {
{
new HelperWithinRadiusDTO {
User = new User
{
ID = 1,
Expand All @@ -46,13 +57,12 @@ public void SetUp()
}
};
_helperService = new Mock<IHelperService>();
_helperService.Setup(x => x.GetHelpersWithinRadius(It.IsAny<string>(), It.IsAny<double?>(),It.IsAny<CancellationToken>())).ReturnsAsync(() => _helpers);
_helperService.Setup(x => x.GetHelpersWithinRadius(It.IsAny<string>(), It.IsAny<double?>(), It.IsAny<CancellationToken>())).ReturnsAsync(() => _helpers);
}

[Test]
public async Task WhenIGetHelper_WithNoStreetChampionOrNoLinkedActivity_NoUserIsReturned()
{

GetVolunteersByPostcodeAndActivityRequest request = new GetVolunteersByPostcodeAndActivityRequest()
{
VolunteerFilter = new VolunteerFilter
Expand All @@ -62,18 +72,15 @@ public async Task WhenIGetHelper_WithNoStreetChampionOrNoLinkedActivity_NoUserIs
}
};

GetVolunteersByPostcodeAndActivityHandler getVolunteersByPostcodeAndActivityHandler = new GetVolunteersByPostcodeAndActivityHandler(_helperService.Object, _repository.Object);
var result = await _classUnderTest.Handle(request, CancellationToken.None);

GetVolunteersByPostcodeAndActivityResponse result = await getVolunteersByPostcodeAndActivityHandler.Handle(request, CancellationToken.None);
Assert.AreEqual(0, result.Volunteers.Count());
_helperService.Verify(X => X.GetHelpersWithinRadius("NG1 1AA", It.IsAny<double?>(), It.IsAny<CancellationToken>()));
}


[Test]
public async Task WhenIGetHelper_WithNoStreetChampionButWithLinkedActivity_IGetOneUserReturened()
{

GetVolunteersByPostcodeAndActivityRequest request = new GetVolunteersByPostcodeAndActivityRequest()
{
VolunteerFilter = new VolunteerFilter
Expand All @@ -83,12 +90,62 @@ public async Task WhenIGetHelper_WithNoStreetChampionButWithLinkedActivity_IGetO
}
};

GetVolunteersByPostcodeAndActivityHandler getVolunteersByPostcodeAndActivityHandler = new GetVolunteersByPostcodeAndActivityHandler(_helperService.Object, _repository.Object);

GetVolunteersByPostcodeAndActivityResponse result = await getVolunteersByPostcodeAndActivityHandler.Handle(request, CancellationToken.None);

var result = await _classUnderTest.Handle(request, CancellationToken.None);
Assert.AreEqual(1, result.Volunteers.Count());
_helperService.Verify(X => X.GetHelpersWithinRadius("NG1 1AA", It.IsAny<double?>(), It.IsAny<CancellationToken>()));
}

[Test]
public async Task GivenMultipleVolsOnlyVolsWithCorrectActivityReturned()
{
_helpers = new List<HelperWithinRadiusDTO>
{
new HelperWithinRadiusDTO {
User = new User
{
ID = 1,
UserPersonalDetails = new UserPersonalDetails
{
DisplayName = "Test",
EmailAddress = "test@test.com"
},
SupportActivities = new List<SupportActivities>{ SupportActivities.Shopping},

},
Distance = 1,
},
new HelperWithinRadiusDTO {
User = new User
{
ID = 2,
UserPersonalDetails = new UserPersonalDetails
{
DisplayName = "Test2",
EmailAddress = "test2@test.com"
},
SupportActivities = new List<SupportActivities>{ SupportActivities.CheckingIn},

},
Distance = 1,
}
};

SupportActivities sa = SupportActivities.Shopping;

GetVolunteersByPostcodeAndActivityRequest request = new GetVolunteersByPostcodeAndActivityRequest()
{
VolunteerFilter = new VolunteerFilter
{
Postcode = "NG1 1AA",
Activities = new List<SupportActivities> { sa }
}
};

var result = await _classUnderTest.Handle(request, CancellationToken.None);
Assert.AreEqual(
_helpers.Where(x=> x.User.SupportActivities.Contains(sa)).Select(x=> x.User.ID).ToList(),
result.Volunteers.Select(x=> x.UserID).ToList());
}

}
}
15 changes: 14 additions & 1 deletion UserService/UserService.UnitTests/HelperServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void SetUp()
IsVerifiedType = IsVerifiedType.IsVerified,
Latitude = 1,
Longitude = 2,
SupportRadiusMiles = 2
SupportRadiusMiles = 3
},
new CachedVolunteerDto()
{
Expand Down Expand Up @@ -120,5 +120,18 @@ public async Task WhenICall_WithHelpers_InsideSupportRadius_IGetUsers()
var users = await _helperService.GetHelpersWithinRadius("T35T 3TY", It.IsAny<double?>(), new CancellationToken());
Assert.AreEqual(2, users.Count());
}

[Test]
public async Task GivenMultipleVolsOnlyVolsWithinSupportRadiusReturned()
{
_distanceInMiles = 2;

var volunteers = _cachedVolunteerDtos.Where(y => y.SupportRadiusMiles >= _distanceInMiles).Select(x=> x.UserId).ToList();

_users = _users.Where(x => volunteers.Contains(x.ID));

var users = await _helperService.GetHelpersWithinRadius("T35T 3TY", It.IsAny<double?>(), new CancellationToken());
Assert.AreEqual(volunteers, users.Select(x => x.User.ID).ToList());
}
}
}