Skip to content

Commit

Permalink
Merge pull request #40 from russkyc/develop-restructure
Browse files Browse the repository at this point in the history
Add project restructure changes to dev branch
  • Loading branch information
russkyc committed Jun 8, 2023
2 parents cf0c208 + 7d7c867 commit 211f693
Show file tree
Hide file tree
Showing 110 changed files with 665 additions and 984 deletions.
29 changes: 5 additions & 24 deletions Russkyc.GroomWise.Tests/Factories/AppointmentFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,24 @@ namespace Russkyc.GroomWise.Tests.Factories;
public class AppointmentFactoryTests
{
[Theory]
[InlineData(0, "Grooming Service", "Cut and Trim", 0, 0, 0, 0, 0)]
[InlineData(1, "Operation", "Infection treatment", 0, 0, 0, 0, 0)]
void Create_Returns_New_Employee_WithModifications(
int id,
string title,
string description,
int appointmentStatus,
int employeeId,
int customerId,
int groomingServiceId,
int petId
)
[InlineData(0, "Grooming Service", "Cut and Trim")]
[InlineData(1, "Operation", "Infection treatment")]
void Create_Returns_New_Employee_WithModifications(int id, string title, string description)
{
// Setup
var accountFactory = new AppointmentFactory();
var appointmentFactory = new AppointmentFactory();

// Execute
var result = accountFactory.Create(appointment =>
var result = appointmentFactory.Create(appointment =>
{
appointment.Id = id;
appointment.Title = title;
appointment.Description = description;
appointment.AppointmentStatus = appointmentStatus;
appointment.EmployeeId = employeeId;
appointment.CustomerId = customerId;
appointment.GroomingServiceId = groomingServiceId;
appointment.PetId = petId;
});

// Assert
Assert.Equal(id, result.Id);
Assert.Equal(title, result.Title);
Assert.Equal(description, result.Description);
Assert.Equal(appointmentStatus, result.AppointmentStatus);
Assert.Equal(employeeId, result.EmployeeId);
Assert.Equal(customerId, result.CustomerId);
Assert.Equal(groomingServiceId, result.GroomingServiceId);
Assert.Equal(petId, result.PetId);
}
}
4 changes: 0 additions & 4 deletions Russkyc.GroomWise.Tests/Factories/EmployeeFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ int employeeType
account.FirstName = firstName;
account.MiddleName = middleName;
account.LastName = lastName;
account.AddressId = addressId;
account.EmployeeType = employeeType;
});

// Assert
Assert.Equal(id, result.Id);
Assert.Equal(firstName, result.FirstName);
Assert.Equal(middleName, result.MiddleName);
Assert.Equal(lastName, result.LastName);
Assert.Equal(addressId, result.AddressId);
Assert.Equal(employeeType, result.EmployeeType);
}
}
24 changes: 3 additions & 21 deletions Russkyc.GroomWise.Tests/Factories/NavItemFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,20 @@
// without written, signed consent from the author is strictly prohibited.

using System.Windows.Controls;
using GroomWise.Models.Enums;

namespace Russkyc.GroomWise.Tests.Factories;

public class NavItemFactoryTests
{
[Theory]
[InlineData(
0,
"dashboard",
typeof(UserControl),
true,
"dashboard",
new[] { EmployeeType.Admin, EmployeeType.Manager }
)]
[InlineData(
1,
"employees",
typeof(UserControl),
true,
"employees",
new[] { EmployeeType.Manager }
)]
[InlineData(0, "dashboard", typeof(UserControl), true, "dashboard")]
[InlineData(1, "employees", typeof(UserControl), true, "employees")]
void Create_Returns_New_NavItem_WithModifications(
int id,
string name,
Type page,
bool selected,
string shortName,
EmployeeType[] accountTypes
string shortName
)
{
// Setup
Expand All @@ -47,7 +31,6 @@ EmployeeType[] accountTypes
navItem.Page = page;
navItem.Selected = selected;
navItem.ShortName = shortName;
navItem.AccountTypes = accountTypes;
});

// Assert
Expand All @@ -56,6 +39,5 @@ EmployeeType[] accountTypes
Assert.Equal(page, result.Page);
Assert.Equal(selected, result.Selected);
Assert.Equal(shortName, result.ShortName);
Assert.Equal(accountTypes, result.AccountTypes);
}
}
63 changes: 0 additions & 63 deletions Russkyc.GroomWise.Tests/Helpers/DataClassHelperTests.cs

This file was deleted.

4 changes: 0 additions & 4 deletions Russkyc.GroomWise.Tests/Russkyc.GroomWise.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@
<ProjectReference Include="..\Russkyc.GroomWise\Russkyc.GroomWise.csproj" />
</ItemGroup>

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

</Project>
83 changes: 0 additions & 83 deletions Russkyc.GroomWise/Models/Abstractions/EncryptedRepository.cs

This file was deleted.

58 changes: 39 additions & 19 deletions Russkyc.GroomWise/Models/Abstractions/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
namespace GroomWise.Models.Abstractions;

public abstract class Repository<T> : Interfaces.Repository.IRepository<T>
where T : class, new()
where T : class, IEquatable<T>, new()
{
private readonly IDatabaseServiceAsync _databaseService;
private readonly Queue<Task> _changes;
private readonly List<T> _collection;
private readonly object _collectionLock = new object();

public Repository(IDatabaseServiceAsync databaseService)
{
Expand All @@ -21,48 +22,67 @@ public Repository(IDatabaseServiceAsync databaseService)

public void Add(T entity)
{
_collection.Add(entity);
_changes.Enqueue(new Task(() => _databaseService.Add(entity)));
lock (_collectionLock)
{
_collection.Add(entity);
_changes.Enqueue(new Task(() => _databaseService.Add(entity)));
}
}

public void AddRange(IEnumerable<T> entities)
{
var collection = entities as T[] ?? entities.ToArray();
_collection.AddRange(collection);
_changes.Enqueue(new Task(() => _databaseService.AddMultiple(collection.ToList())));
lock (_collectionLock)
{
var collection = entities as T[] ?? entities.ToArray();
_collection.AddRange(collection);
_changes.Enqueue(new Task(() => _databaseService.AddMultiple(collection.ToList())));
}
}

public IEnumerable<T> GetAll()
{
return _collection;
lock (_collectionLock)
{
return _collection.ToList();
}
}

public T? Find(Predicate<T> filter)
{
return _collection.Find(filter);
lock (_collectionLock)
{
return _collection.Find(filter);
}
}

public IEnumerable<T> FindAll(Predicate<T> filter)
{
return _collection.FindAll(filter);
lock (_collectionLock)
{
return _collection.FindAll(filter);
}
}

public bool Remove(T entity)
{
var result = _collection.Remove(entity);
if (result)
_changes.Enqueue(
new Task(() => _databaseService.Delete<T>(t => entity.HasSameValues(t)))
);
return result;
lock (_collectionLock)
{
var result = _collection.Remove(entity);
if (result)
_changes.Enqueue(new Task(() => _databaseService.Delete<T>(t => entity == t)));
return result;
}
}

public int RemoveAll(Predicate<T> filter)
{
var result = _collection.RemoveAll(filter);
if (result > 0)
_changes.Enqueue(new Task(() => _databaseService.Delete<T>(t => filter(t))));
return result;
lock (_collectionLock)
{
var result = _collection.RemoveAll(filter);
if (result > 0)
_changes.Enqueue(new Task(() => _databaseService.Delete<T>(t => filter(t))));
return result;
}
}

public void WriteToDb()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ namespace GroomWise.Models.Abstractions;
/// A thread-safe dynamic data collection based on <see cref="ObservableCollection{T}"/>
/// </summary>
/// <typeparam name="T">The type of elements in the collection</typeparam>
public abstract class SynchronizedObservableCollection<T> : DarkObservableCollection<T> { }
public class SynchronizedObservableCollection<T> : DarkObservableCollection<T> { }
11 changes: 0 additions & 11 deletions Russkyc.GroomWise/Models/Collections/NavItemsCollection.cs

This file was deleted.

Loading

0 comments on commit 211f693

Please sign in to comment.