Skip to content

Commit

Permalink
Merge pull request #347 from Promact/taskmailenhacement
Browse files Browse the repository at this point in the history
Task mail Enhancement
  • Loading branch information
Ankit Bhanvadia committed May 13, 2017
2 parents 9d9a9c8 + a24e8aa commit 077679d
Show file tree
Hide file tree
Showing 10 changed files with 602 additions and 255 deletions.
Expand Up @@ -24,7 +24,8 @@ public class AttachmentRepository : IAttachmentRepository
#endregion

#region Constructor
public AttachmentRepository(ApplicationUserManager userManager, ISingletonStringLiteral stringConstant, IServiceRepository serviceRepository)
public AttachmentRepository(ApplicationUserManager userManager, ISingletonStringLiteral stringConstant,
IServiceRepository serviceRepository)
{
_userManager = userManager;
_stringConstant = stringConstant.StringConstant;
Expand Down Expand Up @@ -202,6 +203,25 @@ public SlashChatUpdateResponse SlashChatUpdateResponseTransfrom(NameValueCollect
var response = JsonConvert.DeserializeObject<SlashChatUpdateResponse>(decodeResponse);
return response;
}

/// <summary>
/// Method to get task mail in slack message format in string
/// </summary>
/// <param name="taskMailDetails">list of task mail details</param>
/// <returns>task mail in string</returns>
public string GetTaskMailInStringFormat(IEnumerable<TaskMailDetails> taskMailDetails)
{
string body = string.Empty;
int serialNumber = 1;
foreach (var taskMailDetail in taskMailDetails)
{
body += string.Format(_stringConstant.TaskMailUserViewBodyFormat, serialNumber,
taskMailDetail.Description, taskMailDetail.Hours, taskMailDetail.Comment, taskMailDetail.Status.ToString(),
Environment.NewLine);
serialNumber++;
}
return string.Format(_stringConstant.TaskMailUserViewHeaderFormat, Environment.NewLine, body);
}
#endregion
}
}
Expand Up @@ -68,5 +68,12 @@ public interface IAttachmentRepository
/// <param name="value">current context value</param>
/// <returns>SlashChatUpdateResponse</returns>
SlashChatUpdateResponse SlashChatUpdateResponseTransfrom(NameValueCollection value);

/// <summary>
/// Method to get task mail in slack message format in string
/// </summary>
/// <param name="taskMailDetails">list of task mail details</param>
/// <returns>task mail in string</returns>
string GetTaskMailInStringFormat(IEnumerable<TaskMailDetails> taskMailDetails);
}
}

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions Slack.Automation/Promact.Core.Test/AttachmentRepositoryTest.cs
Expand Up @@ -7,6 +7,7 @@
using Promact.Erp.DomainModel.Models;
using Promact.Erp.Util.StringLiteral;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -203,6 +204,26 @@ public void SlashChatUpdateResponseTransfrom()
var response = _attachmentRepository.SlashChatUpdateResponseTransfrom(value);
Assert.Equal(response.User.Id, _stringConstant.UserSlackId);
}

/// <summary>
/// Test case to check method SlashChatUpdateResponseTransfrom of Attachment Repository
/// </summary>
[Fact, Trait("Category", "Required")]
public void GetTaskMailInStringFormat()
{
List<TaskMailDetails> taskMailDetails = new List<TaskMailDetails>()
{
new TaskMailDetails()
{
Description = _stringConstant.TaskMailDescription,
Comment = _stringConstant.TaskMailComment,
Hours = Convert.ToDecimal(_stringConstant.HourSpentForTest),
Status = TaskMailStatus.completed
}
};
var response = _attachmentRepository.GetTaskMailInStringFormat(taskMailDetails);
Assert.NotEqual(response, string.Empty);
}
#endregion
}
}
100 changes: 91 additions & 9 deletions Slack.Automation/Promact.Core.Test/TaskMailRepositoryTest.cs
Expand Up @@ -2,6 +2,7 @@
using Autofac.Extras.NLog;
using Microsoft.AspNet.Identity;
using Moq;
using Promact.Core.Repository.AttachmentRepository;
using Promact.Core.Repository.BotQuestionRepository;
using Promact.Core.Repository.ServiceRepository;
using Promact.Core.Repository.SlackUserRepository;
Expand Down Expand Up @@ -51,10 +52,11 @@ public class TaskMailRepositoryTest
private Question fifthQuestion = new Question();
private Question SixthQuestion = new Question();
private Question SeventhQuestion = new Question();
private Question EighthQuestion = new Question();
private EmailApplication email = new EmailApplication();
private readonly Mock<ILogger> _loggerMock;
private readonly Mock<HttpContextBase> _mockHttpContextBase;

private readonly IAttachmentRepository _attachmentRepository;
#endregion

#region Constructor
Expand All @@ -74,6 +76,7 @@ public TaskMailRepositoryTest()
_mockServiceRepository = _componentContext.Resolve<Mock<IServiceRepository>>();
_taskMailReportRepository = _componentContext.Resolve<ITaskMailReportRepository>();
_mockHttpContextBase = _componentContext.Resolve<Mock<HttpContextBase>>();
_attachmentRepository = _componentContext.Resolve<IAttachmentRepository>();
Initialize();
}
#endregion
Expand Down Expand Up @@ -321,8 +324,6 @@ public async Task QuestionAndAnswerForthNotAnsweredOrWrongAnswerAsync()
await _taskMailDetailsDataRepository.SaveChangesAsync();
var response = await _taskMailRepository.QuestionAndAnswerAsync(null, _stringConstant.FirstNameForTest);
var expectedReply = forthQuestion.QuestionStatement;
expectedReply += string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
Environment.NewLine, _stringConstant.TaskMailRestartSuggestionMessage, _stringConstant.RequestToStartTaskMail.ToLower());
Assert.Equal(response, expectedReply);
}

Expand All @@ -336,16 +337,15 @@ public async Task QuestionAndAnswerAfterForthAnswerAsync()
await _slackUserRepository.AddSlackUserAsync(slackUserDetails);
await _botQuestionRepository.AddQuestionAsync(forthQuestion);
await _botQuestionRepository.AddQuestionAsync(fifthQuestion);
await _botQuestionRepository.AddQuestionAsync(EighthQuestion);
_taskMailDataRepository.Insert(taskMail);
await _taskMailDataRepository.SaveChangesAsync();
taskMailDetails.TaskId = taskMail.Id;
taskMailDetails.QuestionId = forthQuestion.Id;
_taskMailDetailsDataRepository.Insert(taskMailDetails);
await _taskMailDetailsDataRepository.SaveChangesAsync();
var response = await _taskMailRepository.QuestionAndAnswerAsync(_stringConstant.StatusOfWorkForTest, _stringConstant.FirstNameForTest);
var expectedReply = _stringConstant.FifthQuestionForTest;
expectedReply += string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
Environment.NewLine, _stringConstant.TaskMailRestartSuggestionMessage, _stringConstant.RequestToStartTaskMail.ToLower());
var expectedReply = _stringConstant.EighthQuestionTaskMail;
Assert.Equal(response, expectedReply);
}

Expand Down Expand Up @@ -385,8 +385,12 @@ public async Task QuestionAndAnswerAfterFifthAnswerForYesAsync()
taskMailDetails.QuestionId = fifthQuestion.Id;
_taskMailDetailsDataRepository.Insert(taskMailDetails);
await _taskMailDetailsDataRepository.SaveChangesAsync();
var taskMailDetail = _taskMailDetailsDataRepository.GetAll();
var expectedReply = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
_attachmentRepository.GetTaskMailInStringFormat(taskMailDetail), Environment.NewLine, Environment.NewLine);
expectedReply += _stringConstant.SixthQuestionForTest;
var response = await _taskMailRepository.QuestionAndAnswerAsync(_stringConstant.SendEmailYesForTest, _stringConstant.FirstNameForTest);
Assert.Equal(response, _stringConstant.SixthQuestionForTest);
Assert.Equal(response, expectedReply);
}

/// <summary>
Expand Down Expand Up @@ -933,9 +937,14 @@ public async Task QuestionAndAnswerAfterSecondAnswerExceedHoursAsync()
newTaskMailDetails.QuestionId = secondQuestion.Id;
_taskMailDetailsDataRepository.Insert(newTaskMailDetails);
await _taskMailDetailsDataRepository.SaveChangesAsync();
var expectedResponse = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat, _stringConstant.HourLimitExceed, Environment.NewLine, SixthQuestion.QuestionStatement);
var taskMailDetail = await _taskMailDetailsDataRepository.FetchAsync(x => x.Status == TaskMailStatus.completed);
var expectedResponse = string.Format(_stringConstant.HourLimitExceed, Convert.ToDecimal(_stringConstant.TaskMailMaximumTime));
expectedResponse += Environment.NewLine;
expectedResponse += string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
_attachmentRepository.GetTaskMailInStringFormat(taskMailDetail), Environment.NewLine, Environment.NewLine);
expectedResponse += SixthQuestion.QuestionStatement;
var response = await _taskMailRepository.QuestionAndAnswerAsync(_stringConstant.HourSpentForTesting, _stringConstant.FirstNameForTest);
Assert.Equal(response, expectedResponse);
Assert.NotEqual(response, string.Empty);
}


Expand Down Expand Up @@ -980,7 +989,75 @@ private async Task mockAndUserCreate()
await _userManager.CreateAsync(user);
await _userManager.AddLoginAsync(user.Id, info);
}
/// <summary>
/// Test case for conduct task mail after started for task mail started for restart task
/// </summary>
[Fact, Trait("Category", "Required")]
public async Task QuestionAndAnswerRestartTaskAsync()
{
await mockAndUserCreateAsync();
await _slackUserRepository.AddSlackUserAsync(slackUserDetails);
await _botQuestionRepository.AddQuestionAsync(firstQuestion);
await _botQuestionRepository.AddQuestionAsync(EighthQuestion);
await _botQuestionRepository.AddQuestionAsync(fifthQuestion);
await _botQuestionRepository.AddQuestionAsync(SeventhQuestion);
_taskMailDataRepository.Insert(taskMail);
await _taskMailDataRepository.SaveChangesAsync();
taskMailDetails.TaskId = taskMail.Id;
taskMailDetails.QuestionId = EighthQuestion.Id;
_taskMailDetailsDataRepository.Insert(taskMailDetails);
await _taskMailDetailsDataRepository.SaveChangesAsync();
var response = await _taskMailRepository.QuestionAndAnswerAsync(_stringConstant.SendEmailYesForTest, _stringConstant.FirstNameForTest);
var text = firstQuestion.QuestionStatement;
Assert.Equal(response, text);
}

/// <summary>
/// Test case for conduct task mail after started for task mail started for restart task with answer no
/// </summary>
[Fact, Trait("Category", "Required")]
public async Task QuestionAndAnswerRestartTaskForNextStepAsync()
{
await mockAndUserCreateAsync();
await _slackUserRepository.AddSlackUserAsync(slackUserDetails);
await _botQuestionRepository.AddQuestionAsync(EighthQuestion);
await _botQuestionRepository.AddQuestionAsync(fifthQuestion);
await _botQuestionRepository.AddQuestionAsync(SeventhQuestion);
_taskMailDataRepository.Insert(taskMail);
await _taskMailDataRepository.SaveChangesAsync();
taskMailDetails.TaskId = taskMail.Id;
taskMailDetails.QuestionId = EighthQuestion.Id;
_taskMailDetailsDataRepository.Insert(taskMailDetails);
await _taskMailDetailsDataRepository.SaveChangesAsync();
var response = await _taskMailRepository.QuestionAndAnswerAsync(_stringConstant.SendEmailNoForTest, _stringConstant.FirstNameForTest);
var text = fifthQuestion.QuestionStatement;
text += string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
Environment.NewLine, _stringConstant.TaskMailRestartSuggestionMessage, _stringConstant.RequestToStartTaskMail.ToLower());
Assert.Equal(response, text);
}

/// <summary>
/// Test case for conduct task mail after started for task mail started for restart task with null answer
/// </summary>
[Fact, Trait("Category", "Required")]
public async Task QuestionAndAnswerRestartTaskForNullAnswerAsync()
{
await mockAndUserCreateAsync();
await _slackUserRepository.AddSlackUserAsync(slackUserDetails);
await _botQuestionRepository.AddQuestionAsync(EighthQuestion);
await _botQuestionRepository.AddQuestionAsync(fifthQuestion);
_taskMailDataRepository.Insert(taskMail);
await _taskMailDataRepository.SaveChangesAsync();
taskMailDetails.TaskId = taskMail.Id;
taskMailDetails.QuestionId = EighthQuestion.Id;
_taskMailDetailsDataRepository.Insert(taskMailDetails);
await _taskMailDetailsDataRepository.SaveChangesAsync();
var response = await _taskMailRepository.QuestionAndAnswerAsync(null, _stringConstant.FirstNameForTest);
var text = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
_stringConstant.SendTaskMailConfirmationErrorMessage,
Environment.NewLine, EighthQuestion.QuestionStatement);
Assert.Equal(response, text);
}
#endregion

#region Initialisation
Expand Down Expand Up @@ -1062,6 +1139,11 @@ public void Initialize()
email.Subject = _stringConstant.TaskMailSubject;
var accessTokenForTest = Task.FromResult(_stringConstant.AccessTokenForTest);
_mockServiceRepository.Setup(x => x.GerAccessTokenByRefreshToken(_stringConstant.AccessTokenForTest)).Returns(accessTokenForTest);

EighthQuestion.CreatedOn = DateTime.UtcNow;
EighthQuestion.OrderNumber = QuestionOrder.RestartTask;
EighthQuestion.QuestionStatement = _stringConstant.EighthQuestionTaskMail;
EighthQuestion.Type = BotQuestionType.TaskMail;
}

private void LoggerMocking()
Expand Down
Expand Up @@ -117,7 +117,8 @@ public enum QuestionOrder
TaskMailSend = 7,
Yesterday = 8,
Today = 9,
RoadBlock = 10
RoadBlock = 10,
RestartTask = 11
}

public enum TaskMailCondition
Expand Down

0 comments on commit 077679d

Please sign in to comment.