Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #86 from martijnmelchers/fix/UnitTest
Browse files Browse the repository at this point in the history
Fix/unit test
  • Loading branch information
NanoSector authored Jan 14, 2020
2 parents 02f8ad9 + 00fa13f commit e848651
Show file tree
Hide file tree
Showing 167 changed files with 3,652 additions and 2,712 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
bin/
obj/
packages/
*.user
PublishProfiles/

# macOS vomit
.DS_Store

# IntelliJ/Rider files
.idea/
.idea/

# Other
Uploads/
Binary file modified assets/DataModel_KD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/DomainServices/DomainServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Helpers" />
<Folder Include="Helpers\" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/DomainServices/Enums/FestispecPaths.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace Festispec.DomainServices.Enums
{
[ExcludeFromCodeCoverage]
public static class FestispecPaths
{
// base %AppData% path.
Expand Down
27 changes: 27 additions & 0 deletions src/DomainServices/Factories/AnswerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Festispec.Models.Answers;
using Festispec.Models.Questions;

namespace Festispec.DomainServices.Factories
{
[ExcludeFromCodeCoverage]
public class AnswerFactory
{
public Answer GetAnswer(Question question)
{
return question switch
{
NumericQuestion _ => new NumericAnswer(),
RatingQuestion _ => new NumericAnswer(),
MultipleChoiceQuestion _ => new MultipleChoiceAnswer(),
StringQuestion _ => new StringAnswer(),
DrawQuestion _ => new FileAnswer(),
UploadPictureQuestion _ => new FileAnswer(),
_ => throw new Exception()
};

}
}
}
2 changes: 2 additions & 0 deletions src/DomainServices/Factories/GraphSelectorFactory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Festispec.Models;
using Festispec.Models.GraphConverters;
using Festispec.Models.Interfaces;

namespace Festispec.DomainServices.Factories
{
[ExcludeFromCodeCoverage]
public class GraphSelectorFactory
{
private readonly Dictionary<GraphType, IGraphable> _converters;
Expand Down
2 changes: 2 additions & 0 deletions src/DomainServices/Factories/QuestionFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Festispec.Models.Questions;

namespace Festispec.DomainServices.Factories
{
[ExcludeFromCodeCoverage]
public class QuestionFactory
{
public QuestionFactory()
Expand Down
11 changes: 3 additions & 8 deletions src/DomainServices/Interfaces/IAvailabilityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ namespace Festispec.DomainServices.Interfaces
{
public interface IAvailabilityService
{
Task<Availability> AddUnavailabilityEntireDay(int employeeId, DateTime date, string reason);

Task RemoveUnavailablity(int availabilityId);

Task SaveChanges();

Task<Availability> AddUnavailabilityEntireDay(int employeeId, DateTime date, string reason);
Task RemoveUnavailability(int availabilityId);
Availability GetUnavailabilityForDay(int employeeId, DateTime date);

Task<Dictionary<long, Availability>> GetUnavailabilitiesForFuture(int employeeId, DateTime startDate);
Task<Dictionary<long, Availability>> GetUnavailabilityForFuture(int employeeId, DateTime startDate);
}
}
6 changes: 0 additions & 6 deletions src/DomainServices/Interfaces/ICustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ namespace Festispec.DomainServices.Interfaces
public interface ICustomerService : ISyncable
{
List<Customer> GetAllCustomers();

Customer GetCustomer(int customerId);
Task<Customer> GetCustomerAsync(int customerId);

Task<int> RemoveCustomerAsync(int customerId);

Task<Customer> CreateCustomerAsync(string name, int kvkNr, Address address, ContactDetails contactDetails);
Task<Customer> CreateCustomerAsync(Customer customer);

Task UpdateCustomerAsync(Customer customer);

Task<int> SaveChangesAsync();
public bool CanDeleteCustomer(Customer customer);
}
}
9 changes: 0 additions & 9 deletions src/DomainServices/Interfaces/IEmployeeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,13 @@ namespace Festispec.DomainServices.Interfaces
public interface IEmployeeService : ISyncable
{
List<Employee> GetAllEmployees();

List<Employee> GetAllEmployeesActiveAndNonActive();

Employee GetEmployee(int employeeId);
Task<Employee> GetEmployeeAsync(int employeeId);

Task<int> RemoveEmployeeAsync(int employeeId);

Task<Employee> CreateEmployeeAsync(FullName name, string iban, string username, string password,
Role role, Address address, ContactDetails contactDetails);

Task<Employee> CreateEmployeeAsync(Employee employee);

Task UpdateEmployee(Employee employee);


Task<int> SaveChangesAsync();
bool CanRemoveEmployee(Employee employee);
Account GetAccountForEmployee(int employeeId);
Expand Down
9 changes: 0 additions & 9 deletions src/DomainServices/Interfaces/IExampleService.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/DomainServices/Interfaces/IFestivalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Festispec.DomainServices.Interfaces
public interface IFestivalService : ISyncable
{
Task<Festival> CreateFestival(Festival festival, int customerId);
Task<Festival> GetFestivalAsync(int festivalId);
Festival GetFestival(int festivalId);
ICollection<Festival> GetFestivals();
Task UpdateFestival(Festival festival);
Expand Down
5 changes: 3 additions & 2 deletions src/DomainServices/Interfaces/IInspectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ int employeeId
);

Task RemoveInspection(int plannedInspectionId, string cancellationReason);
Task<int> SaveChanges();
Task<Festival> GetFestivalAsync(int festivalId);
Task<int> ProcessPlannedInspections(IEnumerable<PlannedInspection> plannedInspections,
Questionnaire questionnaire);
Questionnaire questionnaire, string instructions);
}


}
10 changes: 0 additions & 10 deletions src/DomainServices/Interfaces/IQuestionService.cs

This file was deleted.

6 changes: 1 addition & 5 deletions src/DomainServices/Interfaces/IQuestionnaireService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ public interface IQuestionnaireService : ISaveable, ISyncable
Task<Questionnaire> CopyQuestionnaire(int questionnaireId, string questionnaireName);
Task<Question> GetQuestion(int questionId);
Task<Answer> CreateAnswer(Answer answer);
void Save();

List<Question> GetQuestionsFromQuestionnaire(int questionnaireId);
List<Answer> GetAnswers();


Task<TAnswer> GetAnswer<TAnswer>(int id) where TAnswer : Answer;
Task<List<PlannedInspection>> GetPlannedInspections(int employeeId);
Task<PlannedInspection> GetPlannedInspection(int plannedInspectionId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DomainServices/Interfaces/ISicknessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Festispec.DomainServices.Interfaces
{
public interface ISicknessService
{
Task<Availability> AddAbsense(int employeeId, string reason, DateTime? endDate);
Task EndAbsense(int employeeId);
Task<Availability> AddAbsence(int employeeId, string reason, DateTime? endDate);
Task EndAbsence(int employeeId);
bool IsSick(int employeeId);

}
Expand Down
3 changes: 1 addition & 2 deletions src/DomainServices/Interfaces/ISyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public interface ISyncService<T> where T : Entity
void AddEntities(IEnumerable<T> entities);

void SaveChanges();
void SaveChangesAsync();


FestispecContext GetSyncContext();
void Flush();
}
Expand Down
11 changes: 5 additions & 6 deletions src/DomainServices/Services/AddressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public async Task<Address> SaveAddress(Address address)
if (!address.Validate())
throw new InvalidAddressException();

Address existing = await _db.Addresses.FirstOrDefaultAsync(a =>
a.Latitude != 0 && a.Latitude == address.Latitude && a.Longitude != 0 && a.Longitude == a.Longitude);
Address existing = await _db.Addresses.FirstOrDefaultAsync(a => a.Latitude == address.Latitude && a.Longitude == address.Longitude);

if (existing != null)
return existing;
Expand All @@ -36,14 +35,14 @@ public async Task<Address> SaveAddress(Address address)
public async Task RemoveAddress(Address address)
{
var existing = 0;
existing += await _db.Festivals.Include(f => f.Address).CountAsync(a => a.Address.Id == address.Id);
existing += await _db.Employees.Include(e => e.Address).CountAsync(e => e.Address.Id == address.Id);
existing += await _db.Customers.Include(c => c.Address).CountAsync(c => c.Address.Id == address.Id);
existing += await _db.Festivals.Include(f => f.Address).CountAsync(a => a.Address.Id == address.Id && a.Address.Latitude == address.Latitude && a.Address.Longitude == address.Longitude);
existing += await _db.Employees.Include(e => e.Address).CountAsync(e => e.Address.Id == address.Id && e.Address.Latitude == address.Latitude && e.Address.Longitude == address.Longitude);
existing += await _db.Customers.Include(c => c.Address).CountAsync(c => c.Address.Id == address.Id && c.Address.Latitude == address.Latitude && c.Address.Longitude == address.Longitude);

if (existing == 0)
_db.Addresses.Remove(address);

await _db.SaveChangesAsync();
}
}
}
}
15 changes: 9 additions & 6 deletions src/DomainServices/Services/AuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Festispec.Models.EntityMapping;
using System.Data.Entity;
using System.Diagnostics.CodeAnalysis;

namespace Festispec.DomainServices.Services
{
Expand All @@ -13,7 +14,8 @@ public class AuthenticationService : IAuthenticationService
private readonly FestispecContext _db;
private readonly ISyncService<Account> _syncService;

public Account LoggedIn { get; private set; }
[ExcludeFromCodeCoverage]
private Account LoggedIn { get; set; }

public AuthenticationService(FestispecContext db, ISyncService<Account> syncService)
{
Expand All @@ -23,7 +25,7 @@ public AuthenticationService(FestispecContext db, ISyncService<Account> syncServ

public Account AssembleAccount(string username, string password, Role requiredRole)
{
Account existing = _db.Accounts.FirstOrDefault(x => x.Username == username);
var existing = _db.Accounts.FirstOrDefault(x => x.Username == username);

if (existing != null)
throw new EntityExistsException();
Expand All @@ -43,7 +45,7 @@ public Account AssembleAccount(string username, string password, Role requiredRo

public Account Login(string username, string password, Role requiredRole)
{
Account account = _db.Accounts.FirstOrDefault(x => x.Username == username);
var account = _db.Accounts.FirstOrDefault(x => x.Username == username);

if (account == null || !BCrypt.Net.BCrypt.Verify(password, account.Password))
throw new AuthenticationException("Username or password are incorrect");
Expand All @@ -59,7 +61,7 @@ public Account Login(string username, string password, Role requiredRole)

public async Task ChangePassword(string username, string password, string newPassword)
{
Account account = _db.Accounts.FirstOrDefault(x => x.Username == username);
var account = _db.Accounts.FirstOrDefault(x => x.Username == username);

if (account == null || !BCrypt.Net.BCrypt.Verify(password, account.Password))
throw new AuthenticationException("Username or password are incorrect");
Expand All @@ -69,14 +71,15 @@ public async Task ChangePassword(string username, string password, string newPas
await _db.SaveChangesAsync();
}

[ExcludeFromCodeCoverage]
public void Sync()
{
if (LoggedIn == null)
return;

FestispecContext ctx = _syncService.GetSyncContext();
var ctx = _syncService.GetSyncContext();

Account account = ctx.Accounts.Include(a => a.Employee).First(a => a.Id == LoggedIn.Id);
var account = ctx.Accounts.Include(a => a.Employee).First(a => a.Id == LoggedIn.Id);

_syncService.Flush();
_syncService.AddEntity(account);
Expand Down
Loading

0 comments on commit e848651

Please sign in to comment.