-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RSN-37] - Created services for Event Tag Parameter Interest Image (#42)
* Created CRUD services for Parameter, Status, Tag and C&U for Event * created CRUD Image, Interest, Event and Parameter Services Also added geting all elements and by filter(not done properly yet) * changed delete services to void isnted of bool * Fixed GetByFilter service in Event, Image, Intrest, Parameter, Status and Tag Services * little changes * fixing build issue and changing list to ienumerable * Fixing EventServices and standardizing syntax issues * created test for interest status parameter and tag * Created ImageServicesTests * Updated Parameter, Tag, Status services Checked if any of Parameters, Tags or Statuses are used before delating/updating. * fixed bug in imageservicetest * one more fix * Updated services and tests Changed delete methods to bool, updated mocks on tests. * Updated services * Updates after scafoled nr 1 * Updated services Changed using bridge tables to using colections in EF. * Updated EventService added a logic for parameters in event * working event services * created mappers and small fixes * finished mappers * Added exceptions in services * fixed mappers according to our convension * Changed exceptions directory location * fixed build error * Exceptions changes * Unit tests fix * updated services * Slug creating method updated * Update ImageService.cs * Update ImageService.cs * updated image services and tests also updated slug method for event services * event service delete method updated * refactor and fixes * refactor * Update EventService.cs * last refactor * removing spaces * added geteventbyslug method to eventservice * Update ImageService.cs * refactor * changed list to Enumerable * changed list to enumerable * folder refactor * updated services * Update EventService.cs * changes * Update EventServicesTest.cs * updates * Update EventService.cs * Update EventService.cs * Update ImageService.cs * Updates * Update EventMapper.cs * changes * Update ImageServiceTests.cs * changes * Formating * Update EventService.cs * Update EventService.cs * changes * Created AddEventComment method * Update EventService.cs * fixed updating and creating event * Update EventService.cs * changed create slug and text for event --------- Co-authored-by: Maciej Koperdowski <[email protected]>
- Loading branch information
Showing
23 changed files
with
2,283 additions
and
144 deletions.
There are no files selected for viewing
331 changes: 331 additions & 0 deletions
331
Server/ReasnAPI/ReasnAPI.Tests/Services/EventServicesTest.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,331 @@ | ||
using ReasnAPI.Models.DTOs; | ||
using ReasnAPI.Services; | ||
using ReasnAPI.Models.Database; | ||
using Moq; | ||
using Moq.EntityFrameworkCore; | ||
using ReasnAPI.Models.Enums; | ||
using ReasnAPI.Exceptions; | ||
|
||
|
||
namespace ReasnAPI.Tests.Services | ||
{ | ||
[TestClass] | ||
public class EventServicesTest | ||
{ | ||
|
||
[TestMethod] | ||
public void UpdateEvent_EventExists_EventUpdated() | ||
{ | ||
var tagDto = new TagDto() { Name = "tesTag" }; | ||
var tagList = new List<TagDto> | ||
{ | ||
tagDto | ||
}; | ||
var eventDto = new EventDto() | ||
{ | ||
Name = "name1", | ||
AddressId = 1, | ||
Description = "description2", | ||
OrganizerId = 1, | ||
StartAt = DateTime.Now, | ||
EndAt = DateTime.Now, | ||
CreatedAt = DateTime.Now, | ||
UpdatedAt = DateTime.Now, | ||
Slug = "name1", | ||
Status = EventStatus.Completed, | ||
Tags = tagList, | ||
}; | ||
|
||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Events).ReturnsDbSet(new List<Event>{ | ||
new Event() | ||
{ | ||
Id = 1, | ||
Name = "name", | ||
AddressId = 1, | ||
Description = "description", | ||
OrganizerId = 1, | ||
StartAt = DateTime.Now, | ||
EndAt = DateTime.Now, | ||
CreatedAt = DateTime.Now, | ||
Slug = "name1", | ||
UpdatedAt = DateTime.Now, | ||
Status = EventStatus.Completed, | ||
}}); | ||
mockContext.Setup(c => c.Tags).ReturnsDbSet(new List<Tag>()); | ||
|
||
mockContext.Setup(c => c.Addresses).ReturnsDbSet(new List<Address>{ | ||
new Address() | ||
{ | ||
Id = 1, | ||
City = "city", | ||
Country = "country", | ||
State = "state", | ||
Street = "street", | ||
ZipCode = "test123" | ||
}}); | ||
mockContext.Setup(c => c.Users).ReturnsDbSet(new List<User>{ | ||
new User() | ||
{ | ||
Id = 1, | ||
Name = "test", | ||
Email = "[email protected]", | ||
AddressId = 1, | ||
CreatedAt = DateTime.Now, | ||
IsActive = true, Role = UserRole.Admin, | ||
Password ="test123", | ||
Phone = "123123123", | ||
Surname ="test", | ||
Username ="test", | ||
UpdatedAt =DateTime.Now }}); | ||
|
||
mockContext.Setup(c => c.Parameters).ReturnsDbSet(new List<Parameter>()); | ||
mockContext.Setup(c => c.Comments).ReturnsDbSet(new List<Comment>()); | ||
mockContext.Setup(c => c.Participants).ReturnsDbSet(new List<Participant>()); | ||
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object)); | ||
|
||
var result = eventService.UpdateEvent(1, eventDto); | ||
Assert.AreEqual("name1", result.Name); | ||
Assert.AreEqual("description2", result.Description); | ||
Assert.AreEqual(1, result.Tags.Count); | ||
Check warning on line 90 in Server/ReasnAPI/ReasnAPI.Tests/Services/EventServicesTest.cs GitHub Actions / dotnet-tests (ubuntu-latest)
Check warning on line 90 in Server/ReasnAPI/ReasnAPI.Tests/Services/EventServicesTest.cs GitHub Actions / dotnet-tests (macos-latest)
|
||
|
||
} | ||
|
||
[TestMethod] | ||
public void UpdateEvent_EventDoesNotExist_NullReturned() | ||
{ | ||
var tagDto = new TagDto() { Name = "tesTag" }; | ||
var tagList = new List<TagDto> | ||
{ | ||
tagDto | ||
}; | ||
var eventDto = new EventDto() | ||
{ | ||
Name = "name1", | ||
AddressId = 1, | ||
Description = "description2", | ||
OrganizerId = 1, | ||
StartAt = DateTime.Now, | ||
EndAt = DateTime.Now, | ||
CreatedAt = DateTime.Now, | ||
UpdatedAt = DateTime.Now, | ||
Status = EventStatus.Completed, | ||
Tags = tagList, | ||
}; | ||
|
||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Events).ReturnsDbSet(new List<Event>()); | ||
mockContext.Setup(c => c.Tags).ReturnsDbSet(new List<Tag>()); | ||
|
||
mockContext.Setup(c => c.Addresses).ReturnsDbSet(new List<Address>{ | ||
new Address() | ||
{ | ||
Id = 1, | ||
City = "city", | ||
Country = "country", | ||
State = "state", | ||
Street = "street", | ||
ZipCode = "test123" | ||
}}); | ||
mockContext.Setup(c => c.Users).ReturnsDbSet(new List<User>{ | ||
new User() | ||
{ | ||
Id = 1, | ||
Name = "test", | ||
Email = "[email protected]", | ||
AddressId = 1, | ||
CreatedAt = DateTime.Now, | ||
IsActive = true, | ||
Role = UserRole.Admin, | ||
Password ="test123", | ||
Phone = "123123123", | ||
Surname ="test", | ||
Username ="test", | ||
UpdatedAt =DateTime.Now | ||
}}); | ||
|
||
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object)); | ||
|
||
Assert.ThrowsException<NotFoundException>(() => eventService.UpdateEvent(1, eventDto)); | ||
} | ||
|
||
[TestMethod] | ||
public void GetEventById_EventExists_EventReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Events).ReturnsDbSet(new List<Event> | ||
{ | ||
new Event() | ||
{ | ||
Id = 1, | ||
Name = "name", | ||
Slug = "name", | ||
AddressId = 1, | ||
Description = "description", | ||
OrganizerId = 1, | ||
StartAt = DateTime.Now, | ||
EndAt = DateTime.Now, | ||
CreatedAt = DateTime.Now, | ||
UpdatedAt = DateTime.Now, | ||
Status = EventStatus.Completed, | ||
}}); | ||
mockContext.Setup(c => c.Tags).ReturnsDbSet(new List<Tag> | ||
{ | ||
new Tag() | ||
{ | ||
Id = 1, | ||
Name = "name" | ||
} | ||
}); | ||
|
||
mockContext.Setup(c => c.Addresses).ReturnsDbSet(new List<Address>{ | ||
new Address() | ||
{ | ||
Id = 1, | ||
City = "city", | ||
Country = "country", | ||
State = "state", | ||
Street = "street", | ||
ZipCode = "test123" | ||
}}); | ||
mockContext.Setup(c => c.Users).ReturnsDbSet(new List<User>{ | ||
new User() | ||
{ | ||
Id = 1, | ||
Name = "test", | ||
Email = "[email protected]", | ||
AddressId = 1, | ||
CreatedAt = DateTime.Now, | ||
IsActive = true, | ||
Role = UserRole.User, | ||
Password ="test123", | ||
Phone = "123123123", | ||
Surname ="test", | ||
Username ="test", | ||
UpdatedAt =DateTime.Now }}); | ||
|
||
|
||
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object)); | ||
|
||
var result = eventService.GetEventById(1); | ||
Assert.IsNotNull(result); | ||
|
||
} | ||
|
||
[TestMethod] | ||
|
||
public void GetEventById_EventDoesNotExist_NullReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Events).ReturnsDbSet(new List<Event>()); | ||
mockContext.Setup(c => c.Tags).ReturnsDbSet(new List<Tag>()); | ||
|
||
mockContext.Setup(c => c.Addresses).ReturnsDbSet(new List<Address> | ||
{ | ||
new Address() | ||
{ | ||
Id = 1, | ||
City = "city", | ||
Country = "country", | ||
State = "state", | ||
Street = "street", | ||
ZipCode = "test123" | ||
}}); | ||
mockContext.Setup(c => c.Users).ReturnsDbSet(new List<User> | ||
{ | ||
new User() | ||
{ | ||
Id = 1, | ||
Name = "test", | ||
Email = "[email protected]", | ||
AddressId = 1, | ||
CreatedAt = DateTime.Now, | ||
IsActive = true, | ||
Role = UserRole.Admin, | ||
Password ="test123", | ||
Phone = "123123123", | ||
Surname ="test", | ||
Username ="test", | ||
UpdatedAt =DateTime.Now | ||
}}); | ||
|
||
|
||
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object)); | ||
|
||
Assert.ThrowsException<NotFoundException>(() => eventService.GetEventById(1)); | ||
} | ||
|
||
[TestMethod] | ||
|
||
public void DeleteEvent_EventExists_EventDeleted() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Events).ReturnsDbSet(new List<Event> | ||
{ | ||
new Event() | ||
{ | ||
Id = 1, | ||
Name = "name", | ||
Slug = "name", | ||
AddressId = 1, | ||
Description = "description", | ||
OrganizerId = 1, | ||
StartAt = DateTime.Now, | ||
EndAt = DateTime.Now, | ||
CreatedAt = DateTime.Now, | ||
UpdatedAt = DateTime.Now, | ||
Status = EventStatus.Completed, | ||
Tags = new List<Tag> { new Tag { Id = 1, Name = "name" } }, | ||
Parameters = new List<Parameter> { new Parameter { Key = "key", Value = "value" } }, | ||
Comments = new List<Comment> { new Comment { Id = 1, Content = "content" } }, | ||
Participants = new List<Participant> { new Participant { Id = 1, UserId = 1 } } | ||
} | ||
}); | ||
mockContext.Setup(c => c.Tags).ReturnsDbSet(new List<Tag> | ||
{ | ||
new Tag() | ||
{ | ||
Id = 1, | ||
Name = "name" | ||
} | ||
}); | ||
mockContext.Setup(c => c.Addresses).ReturnsDbSet(new List<Address> | ||
{ | ||
new Address() | ||
{ | ||
Id = 1, | ||
City = "city", | ||
Country = "country", | ||
State = "state", | ||
Street = "street", | ||
ZipCode = "test123" | ||
} | ||
}); | ||
mockContext.Setup(c => c.Users).ReturnsDbSet(new List<User>{ | ||
new User() | ||
{ | ||
Id = 1, | ||
Name = "test", | ||
Email = "[email protected]", | ||
AddressId = 1, | ||
CreatedAt = DateTime.Now, | ||
IsActive = true, | ||
Role = UserRole.User, | ||
Password ="test123", | ||
Phone = "123123123", | ||
Surname ="test", | ||
Username ="test", | ||
UpdatedAt =DateTime.Now }}); | ||
mockContext.Setup(c => c.Parameters).ReturnsDbSet(new List<Parameter>()); | ||
mockContext.Setup(c => c.Comments).ReturnsDbSet(new List<Comment>()); | ||
mockContext.Setup(c => c.Participants).ReturnsDbSet(new List<Participant>()); | ||
|
||
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object)); | ||
|
||
eventService.DeleteEvent(1); | ||
|
||
mockContext.Verify(c => c.SaveChanges(), Times.AtLeastOnce); | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.