|
|
|
@@ -0,0 +1,88 @@ |
|
|
|
using Diligent.WebAPI.Business.Interfaces; |
|
|
|
using Diligent.WebAPI.Data.Entities; |
|
|
|
using Diligent.WebAPI.Data.HelperModels; |
|
|
|
using Diligent.WebAPI.Host.Exceptions; |
|
|
|
using Diligent.WebAPI.Host.Mediator.Chat.Handlers; |
|
|
|
using Diligent.WebAPI.Host.Mediator.Rooms.Commands; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Moq; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
namespace Tests |
|
|
|
{ |
|
|
|
[TestFixture] |
|
|
|
public class RoomTests |
|
|
|
{ |
|
|
|
private Mock<IRoomRepository> _roomRepositoryMock; |
|
|
|
|
|
|
|
[SetUp] |
|
|
|
|
|
|
|
public void SetUp() |
|
|
|
{ |
|
|
|
_roomRepositoryMock = new Mock<IRoomRepository>(); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public async Task RemoveUserFromGroup_ObjectIsNull_ThrowsNotFoundException() |
|
|
|
{ |
|
|
|
var command = new RemoveUserFromGroupCommand(null, null); |
|
|
|
var handler = new RemoveUserFromGroupHandler(_roomRepositoryMock.Object); |
|
|
|
|
|
|
|
Assert.That(async () => await handler.Handle(command, new CancellationToken()), Throws.Exception.TypeOf<NotFoundException>()); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public async Task RemoveUserFromGroup_UserConnectionIsNull_ThrowsNotFoundException() |
|
|
|
{ |
|
|
|
_roomRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny<string>())) |
|
|
|
.ReturnsAsync(new Room |
|
|
|
{ |
|
|
|
Name = "Room1", |
|
|
|
Customers = new List<CustomerDTO> |
|
|
|
{ |
|
|
|
new CustomerDTO { CustomerId = "user", DateOfEnteringRoom = DateTime.Now} |
|
|
|
}, |
|
|
|
CreatedBy = "User1" |
|
|
|
}); |
|
|
|
var command = new RemoveUserFromGroupCommand("room1", "user1"); |
|
|
|
var handler = new RemoveUserFromGroupHandler(_roomRepositoryMock.Object); |
|
|
|
|
|
|
|
Assert.That(async () => await handler.Handle(command, new CancellationToken()), Throws.Exception.TypeOf<NotFoundException>()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
public async Task RemoveUserFromGroup_UserConnectionIsNotNull_ObjectIsNotNull() |
|
|
|
{ |
|
|
|
var userConnection = new CustomerDTO { CustomerId = "user1", DateOfEnteringRoom = DateTime.Now }; |
|
|
|
|
|
|
|
var room = new Room |
|
|
|
{ |
|
|
|
Name = "Room1", |
|
|
|
Customers = new List<CustomerDTO> |
|
|
|
{ |
|
|
|
userConnection |
|
|
|
}, |
|
|
|
CreatedBy = "User1" |
|
|
|
}; |
|
|
|
|
|
|
|
_roomRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny<string>())) |
|
|
|
.ReturnsAsync(room); |
|
|
|
|
|
|
|
_roomRepositoryMock.Setup(x => x.LeaveChatRoom(It.IsAny<Room>(), It.IsAny<CustomerDTO>())); |
|
|
|
|
|
|
|
var command = new RemoveUserFromGroupCommand("room1", "user1"); |
|
|
|
var handler = new RemoveUserFromGroupHandler(_roomRepositoryMock.Object); |
|
|
|
|
|
|
|
var result = await handler.Handle(command, new CancellationToken()); |
|
|
|
|
|
|
|
_roomRepositoryMock.Verify(mock => mock.LeaveChatRoom(room, userConnection)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |