コード例 #1
0
		public Conversation CreateConversation(string userId, string addresseeId)
		{
			var conversation = new Conversation();
			conversation.Users.Add(new UserToConversation { Conversation = conversation, UserId = userId });
			conversation.Users.Add(new UserToConversation { Conversation = conversation, UserId = addresseeId });

			this.dbContext.Conversation.Add(conversation);
			this.dbContext.SaveChanges();

			return conversation;
		}
コード例 #2
0
		public void SaveMessage_CorrectSaveEntityAndReturnIt_WithNavigationProperty_Author()
		{
			//Arrange
			var firstUser = new ApplicationUser { UserName = "******" };
			var conversation = new Conversation();
			conversation.Users.Add(new UserToConversation { Conversation = conversation, User = firstUser });
			this.fixture.DbContext.Conversation.Add(conversation);
			this.fixture.DbContext.SaveChanges();
			var chatMessageToSave = new ChatMessage { AuthorId = firstUser.Id, ConversationId = conversation.ConversationId, Received = true };

			//Act
			var savedChatMessage = serviceUnderTest.SaveMessage(chatMessageToSave);

			//Assert
			Assert.NotNull(savedChatMessage);
			Assert.NotNull(savedChatMessage.Author);
			Assert.Equal(firstUser.UserName, savedChatMessage.Author.UserName);
			Assert.True(savedChatMessage.AuthorId == firstUser.Id);
			Assert.True(savedChatMessage.Received);
		}
コード例 #3
0
		public void GetConversationByUsers_ReturnConversationBetweenUsers_ByTheirIds()
		{
			//Arrange
			var firstUser = new ApplicationUser { UserName = "******" };
			var secondUser = new ApplicationUser { UserName = "******" };
			this.fixture.DbContext.ApplicationUser.Add(firstUser);
			this.fixture.DbContext.Add(secondUser);

			var conversation = new Conversation();
			conversation.Users.Add(new UserToConversation { Conversation = conversation, UserId = firstUser.Id });
			conversation.Users.Add(new UserToConversation { Conversation = conversation, UserId = secondUser.Id });
			this.fixture.DbContext.Conversation.Add(conversation);
			this.fixture.DbContext.SaveChanges();

			//Act
			var conversationResult = this.serviceUnderTest.GetConversationByUsers(firstUser.Id, secondUser.Id);

			//Assert
			Assert.NotNull(conversationResult);
			Assert.Equal(conversation.ConversationId, conversationResult.ConversationId);
			Assert.Equal(2, conversationResult.Users.Count);
		}
コード例 #4
0
		public void GetMessagesInConversation_ReturnedMessagesHasIncludedAuthor()
		{
			//Arrange
			var pageNumber = 0;
			var user = new ApplicationUser { UserName = "******" };
			this.fixture.DbContext.ApplicationUser.Add(user);
			var messageDate = new DateTime(2000, 01, 01);
			var conversation = new Conversation();
			conversation.Messages.Add(new ChatMessage { Author = user, Date = messageDate });
			this.fixture.DbContext.Conversation.Add(conversation);
			this.fixture.DbContext.SaveChanges();

			//Act
			var messages = this.serviceUnderTest.GetMessagesInConversation(conversation.ConversationId, pageNumber);

			//Assert
			Assert.NotNull(messages[0].Author);
			Assert.Equal(user.Id, messages[0].Author.Id);
		}
コード例 #5
0
		public void GetMessagesInConversation_PageNumberIs1_Skip20MessagesAndReturn20NextOnesNewestMessages()
		{
			//Arrange
			var pageNumber = 1;
			var user = new ApplicationUser { UserName = "******" };
			this.fixture.DbContext.ApplicationUser.Add(user);
			var messageDate = new DateTime(2000, 01, 01);
			var conversation = new Conversation();
			for (int i = 0; i < 40; i++)
			{
				conversation.Messages.Add(new ChatMessage { Author = user, Date = messageDate.AddDays(i) });
			}
			this.fixture.DbContext.Conversation.Add(conversation);
			this.fixture.DbContext.SaveChanges();

			//Act
			var messages = this.serviceUnderTest.GetMessagesInConversation(conversation.ConversationId, pageNumber);

			//Assert
			Assert.Equal(20, messages.Count);
			Assert.Equal(new DateTime(2000, 01, 20), messages[0].Date);
			Assert.Equal(new DateTime(2000, 01, 01), messages[19].Date);
		}