Пример #1
0
        public ActionResult OpenConversation(string OtherId)
        {
            if (string.IsNullOrWhiteSpace(OtherId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            else
            {
                var userId = User.Identity.GetUserId();
                var privateConversations = dogOwnerService.ConversationBetweenTwoUsers(userId, OtherId);

                return(PartialView(privateConversations));
            }
        }
        public void ShouldReturnOnlyConversationsBetweenTwoUsers()
        {
            //Arrange:
            IEnumerable <PrivateMessageBoard> conversations = new List <PrivateMessageBoard>
            {
                new PrivateMessageBoard {
                    Message = "Something", RrecivedFromID = "UserID", SendFromID = "ID",
                    SenderOfPrivateMessage = appUser, ReceiverOfPrivateMessage = UserToVerifyOrDeny
                },
                new PrivateMessageBoard {
                    Message = "Something", RrecivedFromID = "ID", SendFromID = "UserID",
                    SenderOfPrivateMessage = UserToVerifyOrDeny, ReceiverOfPrivateMessage = appUser
                },
                new PrivateMessageBoard {
                    Message = "Something", RrecivedFromID = "UserID", SendFromID = "ID",
                    SenderOfPrivateMessage = appUser, ReceiverOfPrivateMessage = UserToVerifyOrDeny
                },
                new PrivateMessageBoard {
                    Message = "Something", RrecivedFromID = "ID", SendFromID = "UserID",
                    SenderOfPrivateMessage = UserToVerifyOrDeny, ReceiverOfPrivateMessage = appUser
                },
                new PrivateMessageBoard {
                    Message = "Something", RrecivedFromID = "NotValidID", SendFromID = "NotValidID",
                    SenderOfPrivateMessage = UserToVerifyOrDeny, ReceiverOfPrivateMessage = appUser
                },
            };

            mockPrivateMessageBoardRepo.Setup(x => x.GetMessagesBetweenTwoUsers(
                                                  It.Is <string>(u => u == appUser.Id || u == UserToVerifyOrDeny.Id),
                                                  It.Is <string>(u => u == appUser.Id || u == UserToVerifyOrDeny.Id)))
            .Returns(conversations.Where
                         (x => (x.RrecivedFromID == appUser.Id && x.SendFromID == UserToVerifyOrDeny.Id) ||
                         (x.SendFromID == appUser.Id && x.RrecivedFromID == UserToVerifyOrDeny.Id))).Verifiable();

            //-----------//

            //Act:
            IDogOwnerService dogService = InitializeNewService();
            var result = dogService.ConversationBetweenTwoUsers(appUser.Id, UserToVerifyOrDeny.Id);
            var conversationsResult = result.Conversations.ToList();

            //-----------//

            //Assert
            mockPrivateMessageBoardRepo.Verify(mock => mock.GetMessagesBetweenTwoUsers(
                                                   It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            Assert.That(result, Is.TypeOf(typeof(PrivateConversationBetweenTwoUsers)));
            Assert.That(conversationsResult.Count, Is.EqualTo(4));
            //-----------//
        }