-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAS-121 Clean up and add mailcontroller tests
- Loading branch information
Showing
15 changed files
with
295 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
using MailChimp.Net.Core; | ||
using MailChimp.Net.Interfaces; | ||
using MailChimp.Net.Models; | ||
using MAS.Models; | ||
using MAS.Services; | ||
using MAS.Tests.Infrastructure; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Controllers; | ||
using Microsoft.AspNetCore.Mvc.ViewFeatures; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Web.Mvc; | ||
using Xunit; | ||
using Source = MAS.Models.Source; | ||
|
||
namespace MAS.Tests.IntergrationTests | ||
{ | ||
public class FakeController : Microsoft.AspNetCore.Mvc.Controller | ||
{ | ||
|
||
} | ||
|
||
public class DailyEmailTests : TestBase | ||
{ | ||
IMailService MailService; | ||
|
||
public DailyEmailTests(IMailService mailService) | ||
{ | ||
|
||
MailService = mailService; | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
|
||
} | ||
|
||
Item exampleItem = new Item() | ||
{ | ||
Id = "123", | ||
Title = "Some Title", | ||
Slug = "abc", | ||
ShortSummary = "Some short summary", | ||
ResourceLinks = "", | ||
Comment = "", | ||
Specialities = new List<Speciality> | ||
{ | ||
new Speciality() | ||
{ | ||
Key = "1a", | ||
Title = "Some speciality", | ||
|
||
} | ||
}, | ||
EvidenceType = new EvidenceType() | ||
{ | ||
Key = "1b", | ||
Title = "Some evidence type" | ||
}, | ||
Source = new Source() | ||
{ | ||
Id = "1c", | ||
Title = "Some source" | ||
} | ||
}; | ||
Item exampleItem2 = new Item() | ||
{ | ||
Id = "123", | ||
Title = "Some Title", | ||
Slug = "abc", | ||
ShortSummary = "Some short summary", | ||
ResourceLinks = "", | ||
Comment = "", | ||
Specialities = new List<Speciality> | ||
{ | ||
new Speciality() | ||
{ | ||
Key = "1a", | ||
Title = "Some speciality 2", | ||
|
||
} | ||
}, | ||
EvidenceType = new EvidenceType() | ||
{ | ||
Key = "1c", | ||
Title = "Some evidence type 2" | ||
}, | ||
Source = new Source() | ||
{ | ||
Id = "1c", | ||
Title = "Some source" | ||
} | ||
}; | ||
|
||
//[Fact] | ||
//public void CanCreateSingleItemEmail() | ||
//{ | ||
|
||
// var items = new List<Item> { exampleItem }; | ||
// var actualHtml = this.MailService.CreateDailyEmailBody(items, mockController.Object); | ||
|
||
// actualHtml.ShouldMatchApproved(); | ||
|
||
//} | ||
|
||
//[Fact] | ||
//public void CanCreateEmailWithTwoItemsSharingEvidenceType() | ||
//{ | ||
// var items = new List<Item> { exampleItem, exampleItem }; | ||
// var actualHtml = this.MailService.CreateDailyEmailBody(items, new FakeController()); | ||
|
||
// actualHtml.ShouldMatchApproved(); | ||
|
||
//} | ||
|
||
//[Fact] | ||
//public void CanCreateEmailWithTwoItemsDifferentEvidenceType() | ||
//{ | ||
// var items = new List<Item> { exampleItem, exampleItem2 }; | ||
// var actualHtml = ""; | ||
// try | ||
// { | ||
// actualHtml = this.MailService.CreateDailyEmailBody(items, new FakeController()); | ||
// } | ||
// catch(Exception e) | ||
// { | ||
// var p = e.Message; | ||
// } | ||
|
||
|
||
// actualHtml.ShouldMatchApproved(); | ||
|
||
//} | ||
|
||
//[Fact] | ||
//public void ItemsWithManySpecialitiesRenderCorrectly() | ||
//{ | ||
// exampleItem.Specialities.Add(new Speciality() { Key = "abcd", Title = "Another speciality" }); | ||
// var items = new List<Item> { exampleItem }; | ||
// var actualHtml = this.MailService.CreateDailyEmailBody(items, new FakeController()); | ||
|
||
// actualHtml.ShouldMatchApproved(); | ||
|
||
//} | ||
|
||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
lambda/MAS.Tests/UnitTests/Controllers/MailControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using MAS.Controllers; | ||
using MAS.Models; | ||
using MAS.Services; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using Shouldly; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace MAS.Tests.UnitTests.Controllers | ||
{ | ||
public class MailControllerTests | ||
{ | ||
[Fact] | ||
public async void GetDailyItemsForToday() | ||
{ | ||
|
||
var mockContentService = new Mock<IContentService>(); | ||
var mailService = new MailController(Mock.Of<IMailService>(), mockContentService.Object, Mock.Of<IViewRenderer>(), Mock.Of<ILogger<MailService>>()); | ||
|
||
//Act | ||
await mailService.PutMailAsync(); | ||
|
||
//Assert | ||
mockContentService.Verify(mock => mock.GetDailyItemsAsync(null), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public async void GetDailyItemsForSpecificDate() | ||
{ | ||
DateTime date = new DateTime(2020, 1, 15); | ||
var mockContentService = new Mock<IContentService>(); | ||
var mailService = new MailController(Mock.Of<IMailService>(), mockContentService.Object, Mock.Of<IViewRenderer>(), Mock.Of<ILogger<MailService>>()); | ||
|
||
//Act | ||
await mailService.PutMailAsync(date); | ||
|
||
//Assert | ||
mockContentService.Verify(mock => mock.GetDailyItemsAsync(date), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public async void RendersDailyViewWithContentItems() | ||
{ | ||
var items = new List<Item>() { }.AsEnumerable(); | ||
var mockContentService = new Mock<IContentService>(); | ||
mockContentService.Setup(x => x.GetDailyItemsAsync(null)).ReturnsAsync(items); | ||
|
||
var mockViewRenderer = new Mock<IViewRenderer>(); | ||
|
||
var mailController = new MailController(Mock.Of<IMailService>(), mockContentService.Object, mockViewRenderer.Object, Mock.Of<ILogger<MailService>>()); | ||
|
||
//Act | ||
await mailController.PutMailAsync(); | ||
|
||
//Assert | ||
mockViewRenderer.Verify(mock => mock.RenderViewAsync(mailController, "~/Views/MAD.cshtml", items, false), Times.Once()); | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
...ts/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsDifferentEvidenceType.approved.txt
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...ests/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsSharingEvidenceType.approved.txt
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateSingleItemEmail.approved.txt
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...MAS.Tests/UnitTests/DailyEmailTests.ItemsWithManySpecialitiesRenderCorrectly.approved.txt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
fb9a9cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity MAS / MAS Build 1.1.0.555-MAS-129_121__112_Dai outcome was FAILURE
Summary: Artifacts size 172 KB is 95% different from 3.6 MB in build #1.1.0.554-rD5C282E Build time: 00:00:41
fb9a9cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity MAS / MAS Build 1.1.0.556-MAS-129_121__112_Dai outcome was FAILURE
Summary: Artifacts size 172 KB is 95% different from 3.6 MB in build #1.1.0.554-rD5C282E Build time: 00:00:35