-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create new project for Services testing * Add query parameter classes * Add PagedList class * Add pagination methods to services and repos * Added unit tests for FoodEFRepository methods * Implement food api get method with pagination * Add more incomplete changes * Add test for RestaurantEFRepository * made folders for tests * Restructure, remove old repos, implement services * Implement updated repositories * Remove all code from console app * Change get metods in repos to take order delegate * Revert changes to get methods in repos * Implement pagination in restaurant controller * Fix bugs, add new function to food repo * Add inefficient sorting * Fix bug * fixed compiling issues * Fix GetRestaurantsCloserThan function * Fixed bug in GetAllRestaurantsCloserThan * Fix bug * Add methods to typeOfFoodRepository * Added unit test for TypeOfFoodEFRepository * Tests refactor * Move id generation to persistence layer * Added some tests for FoodServices * Add typeOfFood api methods * Added more tests for FoodServce * Remove interface to abstract DbContext * Fix get and insert methods in food repo * Fix url and description bugs * Fix restaurant food list not showing types of food * Added tests for RestaurantServices * Partially fix update methods * Fix bug when updating not existing entity * Update not passing tests * Fix pagedListExtensions bug * Fix sorting by distance, move dto mapping to mappers * Add foods property to restaurant model and fix sorting * Add foods property to restaurant model and fix sorting Co-authored-by: DominykasSip <[email protected]>
- Loading branch information
1 parent
0577ccf
commit 1fff3a5
Showing
20 changed files
with
739 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
backend/Services.Tests/RepositoriesUnitTests/FoodEFRepositoryUnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using Domain.Entities; | ||
using Domain.Models; | ||
using Services.Repositories; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Services.Tests.RepositoriesUnitTests | ||
{ | ||
public class FoodEFRepositoryUnitTests : UnitTests | ||
{ | ||
private FoodEntity FoodEntity { get; set; } | ||
private Food Food { get; set; } | ||
|
||
public FoodEFRepositoryUnitTests() | ||
{ | ||
FoodEntity = GetSampleFoodEntity(); | ||
Food = GetSampleFood(); | ||
} | ||
|
||
|
||
[Fact] | ||
public void Insert_InsertFoodToDataBase() | ||
{ | ||
var sut = new FoodEFRepository(_context); | ||
|
||
sut.Insert(Food); | ||
|
||
List<FoodEntity> foods = _context.Foods.ToList(); | ||
Assert.Single(foods); | ||
Assert.Equal(Food.Id, foods.First().Id.ToString()); | ||
} | ||
|
||
[Fact] | ||
public void Delete_DeletesExistingFood() | ||
{ | ||
_context.Foods.Add(FoodEntity); | ||
_context.SaveChanges(); | ||
var sut = new FoodEFRepository(_context); | ||
|
||
sut.Delete(FoodEntity.Id.ToString()); | ||
|
||
Assert.Empty(_context.Foods.ToList()); | ||
} | ||
|
||
[Fact] | ||
public void GetAll_OneFoodInDataBase_GetsAllExistingFoods() | ||
{ | ||
_context.Foods.Add(FoodEntity); | ||
_context.SaveChanges(); | ||
var sut = new FoodEFRepository(_context); | ||
|
||
Assert.Single(sut.GetAll()); | ||
} | ||
|
||
[Fact] | ||
public void GetAll_MoreThanOneFoodInDataBase_GetsAllExistingFoods() | ||
{ | ||
_context.Foods.Add(FoodEntity); | ||
var otherFoodId = Guid.NewGuid(); | ||
var otherTypeId = Guid.NewGuid(); | ||
var otherFood = GetSampleFoodEntity(); | ||
otherFood.Id = otherFoodId; | ||
otherFood.TypesOfFood.First().Id = otherTypeId; | ||
_context.Foods.Add(otherFood); | ||
_context.SaveChanges(); | ||
var sut = new FoodEFRepository(_context); | ||
|
||
IQueryable<Food> foods = sut.GetAll(); | ||
|
||
Assert.NotEmpty(foods); | ||
Assert.Equal(FoodEntity.Id.ToString(), foods.ToList()[0].Id); | ||
Assert.Equal(otherFoodId.ToString(), foods.ToList()[1].Id); | ||
} | ||
|
||
[Fact] | ||
public void GetById_FoodExistsInDataBase_ReturnsFood() | ||
{ | ||
_context.Foods.Add(FoodEntity); | ||
_context.SaveChanges(); | ||
var sut = new FoodEFRepository(_context); | ||
|
||
var food = sut.GetById(FoodEntity.Id.ToString()); | ||
|
||
Assert.Equal(FoodEntity.Id.ToString(), food.Id); | ||
} | ||
|
||
[Fact] | ||
public void GetById_FoodDoesntExistsInDataBase_ReturnsNull() | ||
{ | ||
var sut = new FoodEFRepository(_context); | ||
|
||
var food = sut.GetById(Guid.NewGuid().ToString()); | ||
|
||
Assert.Null(food); | ||
} | ||
|
||
[Fact] | ||
public void Update_UpdateExistingFood() | ||
{ | ||
_context.Foods.Add(FoodEntity); | ||
_context.SaveChanges(); | ||
var sut = new FoodEFRepository(_context); | ||
var newFoodName = "NewFoodTestName"; | ||
var food = new Food | ||
{ | ||
Id = FoodEntity.Id.ToString(), | ||
IdRestaurant = FoodEntity.RestaurantId.ToString(), | ||
Name = newFoodName, | ||
TypesOfFood = GetSampleTypesOfFoodList(), | ||
PercentPerInterval = 1 | ||
}; | ||
food.TypesOfFood.First().Id = Guid.NewGuid().ToString(); | ||
|
||
sut.Update(food); | ||
|
||
var UpdatedFood = _context.Foods.Find(FoodEntity.Id); | ||
Assert.Equal(FoodEntity.Id, UpdatedFood.Id); | ||
Assert.NotEqual(FoodEntity.Name, UpdatedFood.Name); | ||
} | ||
|
||
[Fact] | ||
public void Update_UpdateNotExistingFood() | ||
{ | ||
_context.Foods.Add(FoodEntity); | ||
_context.SaveChanges(); | ||
var sut = new FoodEFRepository(_context); | ||
var newFoodName = "NewFoodTestName"; | ||
var food = new Food | ||
{ | ||
Id = Guid.NewGuid().ToString(), | ||
IdRestaurant = FoodEntity.Id.ToString(), | ||
Name = newFoodName, | ||
TypesOfFood = GetSampleTypesOfFoodList(), | ||
PercentPerInterval = 1 | ||
}; | ||
|
||
sut.Update(food); | ||
|
||
var foodFormDB = _context.Foods.Find(FoodEntity.Id); | ||
Assert.Equal(FoodEntity.Name, foodFormDB.Name); | ||
} | ||
} | ||
} |
Oops, something went wrong.