private async Task<ApplicationUser> CreateUser(RegisterViewModel registerViewModel) {
			ApplicationUser user = new ApplicationUser { UserName = registerViewModel.Email, Email = registerViewModel.Email };
			IdentityResult result = await applicationUserManager.CreateAsync(user, registerViewModel.Password);
			if (!result.Succeeded) {
				throw new Exception("Creating new user failed");
			}

			return user;
		}
		public void GetUserName_MethodShouldReturnNameFromEmailAdres() {
			//Arrange
			var email = "*****@*****.**";
			var user = new ApplicationUser { UserName = email };
			
			var expectedResult = "marcin.szyszka";

			//Act
			var result = user.GetUserName();

			//Assert
			Assert.Equal(expectedResult, result);
		}
		public void GetUserName_MethodShouldReturnFullName_WhenNameIsNotEmail()
		{
			//Arrange
			var name = "marcin.szyszka123";
			var user = new ApplicationUser { UserName = name };

			var expectedResult = "marcin.szyszka123";

			//Act
			var result = user.GetUserName();

			//Assert
			Assert.Equal(expectedResult, result);
		}
		private async Task<ApplicationUser> CreateUser(FacebookUserCredentialsResponse facebookResponse) {
			ApplicationUser user = new ApplicationUser { UserName = facebookResponse.email, Email = facebookResponse.email };
			IdentityResult result = await applicationUserManager.CreateAsync(user);
			if (result.Succeeded) {
				IdentityResult loginInfoResult = await applicationUserManager.AddLoginAsync(user, new UserLoginInfo("Facebook", facebookResponse.id, facebookResponse.name));
				if (!loginInfoResult.Succeeded) {
					throw new Exception("Creating new user failed");
				}
			}
			else {
				throw new Exception("Creating new user failed");
			}

			return user;
		}
		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);
		}
		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);
		}
		public void CreateConversation_ConversationIsCreatingAndReturningWithRelatedUsersProperty()
		{
			//Arrange
			var firstUser = new ApplicationUser { UserName = "******" };
			var secondUser = new ApplicationUser { UserName = "******" };
			this.fixture.DbContext.ApplicationUser.Add(firstUser);
			this.fixture.DbContext.Add(secondUser);
			this.fixture.DbContext.SaveChanges();

			//Act
			var conversation = serviceUnderTest.CreateConversation(firstUser.Id, secondUser.Id);

			//Assert
			Assert.NotNull(conversation);
			Assert.True(conversation.ConversationId > 0);
			Assert.NotEmpty(conversation.Users);
			Assert.Equal(2, conversation.Users.Count);
			Assert.Equal(firstUser.Id, conversation.Users[0].UserId);
			Assert.Equal(secondUser.Id, conversation.Users[1].UserId);
			Assert.Equal(2, this.fixture.DbContext.ApplicationUser.Where(a => a.Id == firstUser.Id || a.Id == secondUser.Id).Count());

		}
		public async Task<bool> PasswordIsValid(ApplicationUser user, string password) {
			return await userManager.CheckPasswordAsync(user, password);
		}
		public Task<IdentityResult> AddLoginAsync(ApplicationUser user, UserLoginInfo userLoginInfo) {
			return userManager.AddLoginAsync(user, userLoginInfo);
		}
		public async Task<IdentityResult> CreateAsync(ApplicationUser user, string password) {
			return await userManager.CreateAsync(user, password);
		}
		public Task<IdentityResult> CreateAsync(ApplicationUser user) {
			return userManager.CreateAsync(user);
		}
		private TokenModel GetToken(ApplicationUser user) {
			var handler = new JwtSecurityTokenHandler();

			ClaimsIdentity identity = new ClaimsIdentity(new GenericIdentity(user.Email, "TokenAuth"), new[] { new Claim("UserId", user.Id, ClaimValueTypes.String) });

			var securityToken = handler.CreateToken(GetTokenOptions(identity));

			return new TokenModel { Token = handler.WriteToken(securityToken) };
		}
		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);
		}
		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);
		}