Example #1
0
        public void Invoke_EmptyUsersGuid_ReturnsNull()
        {
            // prepare
            var mockedUserRepository     = new Mock <IUserRepository>();
            var mockedRoomRepository     = new Mock <IRoomRepository>();
            var mockedUserRoomRepository = new Mock <IUserRoomRepository>();
            var mockedDomainRepository   = new Mock <IDomainRepository>();
            var mockedUnitOfWork         = new Mock <IUnitOfWork>();

            var action = new AddNewPrivateConversation(mockedRoomRepository.Object, mockedUserRepository.Object,
                                                       mockedUserRoomRepository.Object, mockedDomainRepository.Object, mockedUnitOfWork.Object);

            // action
            var result = action.Invoke(Guid.NewGuid(), new List <Guid> {
                Guid.NewGuid(), new Guid()
            });

            // assert
            mockedUserRepository.Verify(r => r.GetPrivateConversationsTargets(It.IsAny <Guid>()), Times.Never);
            mockedUserRepository.Verify(r => r.GetById(It.IsAny <Guid>()), Times.Never);
            mockedUserRepository.Verify(r => r.GetAll(), Times.Never);
            mockedDomainRepository.Verify(r => r.GetDomainByUserId(It.IsAny <Guid>()), Times.Never);
            mockedUnitOfWork.Verify(r => r.Save(), Times.Never);
            mockedUnitOfWork.Verify(r => r.Save(), Times.Never);
            Assert.Null(result);
        }
Example #2
0
        public void Invoke_UserRoomWithOneUserFromUserList_ReturnsCorrectModel()
        {
            // prepare
            var issuerId = Guid.NewGuid();

            var issuer = new DataAccess.Models.User
            {
                Id   = issuerId,
                Name = "IssuerName"
            };

            var user1 = new DataAccess.Models.User
            {
                Id   = Guid.NewGuid(),
                Name = "User1"
            };

            var user2 = new DataAccess.Models.User
            {
                Id   = Guid.NewGuid(),
                Name = "User2"
            };

            var users = new List <Guid> {
                user1.Id, user2.Id
            };

            // UserRoom with user2
            var userRoomList = new List <DataAccess.Models.UserRoom>
            {
                new DataAccess.Models.UserRoom
                {
                    User = user2,
                    Room = new DataAccess.Models.Room
                    {
                        IsPrivateConversation = true,
                        IsPublic = false
                    }
                }
            };

            var mockedUserRepository = new Mock <IUserRepository>();

            mockedUserRepository.Setup(r => r.GetById(It.IsAny <Guid>()))
            .Returns(issuer);

            mockedUserRepository.Setup(r => r.GetAll())
            .Returns(new List <DataAccess.Models.User> {
                user1, user2
            }.AsQueryable);

            mockedUserRepository.Setup(r => r.GetPrivateConversationsTargets(issuerId))
            .Returns(userRoomList.AsQueryable);

            var mockedRoomRepository     = new Mock <IRoomRepository>();
            var mockedUserRoomRepository = new Mock <IUserRoomRepository>();
            var mockedDomainRepository   = new Mock <IDomainRepository>();
            var mockedUnitOfWork         = new Mock <IUnitOfWork>();

            var action = new AddNewPrivateConversation(mockedRoomRepository.Object, mockedUserRepository.Object,
                                                       mockedUserRoomRepository.Object, mockedDomainRepository.Object, mockedUnitOfWork.Object);

            // action
            var result = action.Invoke(issuerId, users);

            // check
            mockedUserRepository.Verify(r => r.GetPrivateConversationsTargets(It.IsAny <Guid>()), Times.Once);
            mockedUserRepository.Verify(r => r.GetById(It.IsAny <Guid>()), Times.Once);
            mockedUserRepository.Verify(r => r.GetAll(), Times.Once);
            mockedDomainRepository.Verify(r => r.GetDomainByUserId(It.IsAny <Guid>()), Times.Once);
            mockedUnitOfWork.Verify(r => r.Save(), Times.Once);
            mockedUnitOfWork.Verify(r => r.Save(), Times.Once);
            Assert.NotNull(result);
            Assert.True(result.IsPrivateConversation);
            Assert.False(result.IsPublic);
            Assert.Equal("IssuerName", result.Owner.Name);
            Assert.Equal("User1, User2, IssuerName", result.Name);
        }