public void GetChatsByParticipantId_NormalExecution()
        {
            //Arrange
            var testUserGuid = SWholeRepositoryStub.Users[1].Id;
            var expected = new List<CChatInfo>
            {
                SWholeRepositoryStub.Chats[1],
                SWholeRepositoryStub.Chats[2],
                SWholeRepositoryStub.Chats[3],
            };

            //Act
            var result = _chatDataProvider.GetChatsByParticipantId(testUserGuid);

            //Assert
            Assert.NotNull(result);
            //for (int i = 0; i < result.Count; i++)
            //{
            //    Assert.Equal(expected[i], result[i]);
            //}
            //Xunit.Assert.Equal<CChatInfo>(expected, result);
            //Comparer<CChatInfo>.Create(new Comparison<CChatInfo>()
            var comparer = new CLambdaEqualityComparer<CChatInfo>(
                (x, y) => 
                    x.Id == y.Id && x.IsPersonal == y.IsPersonal && 
                    x.OwnerId == y.OwnerId && String.Equals(x.Title, y.Title) 
                    && x.Type == y.Type, 
                x => x.GetHashCode()
            );
            Xunit.Assert.Equal<CChatInfo>(expected, result, comparer);
        }
예제 #2
0
        public IHttpActionResult GetChats([FromUri] Guid participantId)
        {
            s_log.LogInfo($"{System.Reflection.MethodBase.GetCurrentMethod()}({participantId}) is called");

            if (participantId == Guid.Empty)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({participantId})", new ArgumentNullException(nameof(participantId), "Incoming data is null"));
                ModelState.AddModelError($"{nameof(participantId)}", "Incoming data is null");
                return(BadRequest(ModelState));
            }

            var chatInfos = _chatDataProvider.GetChatsByParticipantId(participantId);

            if (chatInfos == null)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({participantId})", new Exception("Failed to get all chats"));
                return(NotFound());
            }

            return(Ok(chatInfos.Select(x => new CChatDto(x.Id, x.Title, x.OwnerId, x.IsPersonal, x.Type))));
        }