80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using LCU.API.Collections.RepoApi.Services;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace LCU.API.Collections.RepoApiTests.Services
|
|
{
|
|
public class SavedLocationServiceTest
|
|
{
|
|
[Fact]
|
|
public async void ListAll_Ok()
|
|
{
|
|
var mockLocation = getMockLocation();
|
|
var savedLocationService = getSavedLocationService();
|
|
|
|
var result = await savedLocationService.ListAllAsync();
|
|
var locationEnumerator = result.GetEnumerator();
|
|
|
|
locationEnumerator.MoveNext();
|
|
var firstLocationFromService = locationEnumerator.Current;
|
|
Assert.Equal(mockLocation.ID, firstLocationFromService.ID);
|
|
Assert.Equal(mockLocation.Name, firstLocationFromService.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public async void GetOne_Ok()
|
|
{
|
|
var mockLocation = getMockLocation();
|
|
var savedLocationService = getSavedLocationService();
|
|
|
|
var result = await savedLocationService.GetAsync(1);
|
|
Assert.Equal(mockLocation.ID, result.ID);
|
|
Assert.Equal(mockLocation.Name, result.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Update_Ok()
|
|
{
|
|
var mockLocation = getMockLocation();
|
|
var savedLocationService = getSavedLocationService();
|
|
|
|
var oldId = mockLocation.ID;
|
|
mockLocation.ID = 2;
|
|
mockLocation.Name = "New Name";
|
|
|
|
var result = await savedLocationService.UpdateAsync(mockLocation);
|
|
Assert.Equal(mockLocation.Name, result.Name);
|
|
Assert.Equal(oldId, result.ID);
|
|
}
|
|
|
|
private SavedLocationService getSavedLocationService()
|
|
{
|
|
var savedLocations = getMockLocationList();
|
|
|
|
var mockRepository = new Mock<ISavedLocationRepository>();
|
|
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
|
|
|
mockRepository.Setup(repo => repo.ListAsync()).ReturnsAsync(savedLocations);
|
|
mockRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(savedLocations[0]);
|
|
mockRepository.Setup(repo => repo.Update(It.IsAny<SavedLocation>()));
|
|
|
|
return new SavedLocationService(mockRepository.Object, mockUnitOfWork.Object);
|
|
}
|
|
|
|
private IList<SavedLocation> getMockLocationList()
|
|
{
|
|
return new List<SavedLocation>
|
|
{
|
|
getMockLocation()
|
|
};
|
|
}
|
|
|
|
private SavedLocation getMockLocation()
|
|
{
|
|
return new SavedLocation() {ID = 1, Name = "Some Weird Storage Place"};
|
|
}
|
|
}
|
|
} |