Skip to content

Commit

Permalink
Code quality - Add at least one assertion to the test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavminhas committed Jul 28, 2024
1 parent 0ae7bde commit 7a07bcd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
25 changes: 17 additions & 8 deletions GmailAPIHelper.CORE.Tests/GmailTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace GmailAPIHelper.CORE.Tests
{
Expand Down Expand Up @@ -75,7 +76,8 @@ public void Test_GetGmailService_TokenPath_Home()
destPath = Environment.GetEnvironmentVariable("HOME") + "/" + "token.json";
Directory.CreateDirectory(destPath);
File.Copy(sourcePath, destPath + "/Google.Apis.Auth.OAuth2.Responses.TokenResponse-user", overwrite: true);
GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.HOME);
var service = GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.HOME);
Assert.IsTrue(service.GetType() == typeof(Google.Apis.Gmail.v1.GmailService));
Directory.Delete(destPath, recursive: true);
}

Expand All @@ -90,7 +92,8 @@ public void Test_GetGmailService_TokenPath_Custom()
credPath = Environment.CurrentDirectory + "/" + "token.json";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
credPath = Environment.CurrentDirectory + "/" + "token.json";
GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.CUSTOM, credPath);
var service = GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.CUSTOM, credPath);
Assert.IsTrue(service.GetType() == typeof(Google.Apis.Gmail.v1.GmailService));
}

[TestMethod]
Expand Down Expand Up @@ -365,6 +368,7 @@ public void Test_SendMessage_PlainText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/PlainEmail.txt";
var body = File.ReadAllText(path);
Assert.IsFalse(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
GmailHelper.GetGmailService(ApplicationName)
.SendMessage(GmailHelper.EmailContentType.PLAIN, TestEmailId, cc: TestEmailId, bcc: TestEmailId, subject: "EMAIL WITH PLAIN TEXT", body: body);
}
Expand All @@ -381,6 +385,7 @@ public void Test_SendMessage_HtmlText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/HTMLEmail.txt";
var body = File.ReadAllText(path);
Assert.IsTrue(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
GmailHelper.GetGmailService(ApplicationName)
.SendMessage(GmailHelper.EmailContentType.HTML, TestEmailId, cc: TestEmailId, bcc: TestEmailId, subject: "EMAIL WITH HTML TEXT", body: body);
}
Expand Down Expand Up @@ -463,6 +468,7 @@ public void Test_SendMessage_Attachments_PlainText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/PlainEmail.txt";
var body = File.ReadAllText(path);
Assert.IsFalse(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
var attachmentPath = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
attachmentPath = Environment.CurrentDirectory + "\\TestFiles\\Attachments\\";
Expand Down Expand Up @@ -499,6 +505,7 @@ public void Test_SendMessage_Attachments_HtmlText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/HTMLEmail.txt";
var body = File.ReadAllText(path);
Assert.IsTrue(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
var attachmentPath = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
attachmentPath = Environment.CurrentDirectory + "\\TestFiles\\Attachments\\";
Expand Down Expand Up @@ -1484,18 +1491,20 @@ public void Test_ListUserLabels()
[TestCategory("TestCleanup")]
public void Inbox_CleanUp()
{
GmailHelper.GetGmailService(ApplicationName)
var mesagesMoved = 0;
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: $"[from:{TestEmailId}]in:inbox is:unread");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: $"[from:{TestEmailId}]in:spam is:unread");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETCORE MESSAGE AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETFRAMEWORK MESSAGE AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETCORE MESSAGES AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETFRAMEWORK MESSAGES AS READ']in:inbox is:read");
Assert.IsTrue(mesagesMoved >= 0);
}
}
}
19 changes: 13 additions & 6 deletions GmailAPIHelper.NET.Tests/GmailTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;

namespace GmailAPIHelper.NET.Tests
{
Expand Down Expand Up @@ -284,6 +285,7 @@ public void Test_GetMessagesAttachments_NoMatchingEmail()
public void Test_SendMessage_PlainText()
{
var body = File.ReadAllText(Environment.CurrentDirectory + "\\TestFiles\\PlainEmail.txt");
Assert.IsFalse(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
GmailHelper.GetGmailService(ApplicationName)
.SendMessage(GmailHelper.EmailContentType.PLAIN, TestEmailId, cc: TestEmailId, bcc: TestEmailId, subject: "EMAIL WITH PLAIN TEXT", body: body);
}
Expand All @@ -293,6 +295,7 @@ public void Test_SendMessage_PlainText()
public void Test_SendMessage_HtmlText()
{
var body = File.ReadAllText(Environment.CurrentDirectory + "\\TestFiles\\HTMLEmail.txt");
Assert.IsTrue(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
GmailHelper.GetGmailService(ApplicationName)
.SendMessage(GmailHelper.EmailContentType.HTML, TestEmailId, cc: TestEmailId, bcc: TestEmailId, subject: "EMAIL WITH HTML TEXT", body: body);
}
Expand Down Expand Up @@ -369,6 +372,7 @@ public void Test_SendMessage_Attachments_PlainText()
{
var path = Environment.CurrentDirectory + "\\TestFiles\\PlainEmail.txt";
var body = File.ReadAllText(path);
Assert.IsFalse(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
var attachmentPath = Environment.CurrentDirectory + "\\TestFiles\\Attachments\\";
var attachments = new List<string>
{
Expand All @@ -393,6 +397,7 @@ public void Test_SendMessage_Attachments_HtmlText()
{
var path = Environment.CurrentDirectory + "\\TestFiles\\HTMLEmail.txt";
var body = File.ReadAllText(path);
Assert.IsTrue(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
var attachmentPath = Environment.CurrentDirectory + "\\TestFiles\\Attachments\\";
var attachments = new List<string>
{
Expand Down Expand Up @@ -1261,18 +1266,20 @@ public void Test_ListUserLabels()
[TestCategory("TestCleanup")]
public void Inbox_CleanUp()
{
GmailHelper.GetGmailService(ApplicationName)
var mesagesMoved = 0;
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: $"[from:{TestEmailId}]in:inbox is:unread");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: $"[from:{TestEmailId}]in:spam is:unread");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETCORE MESSAGE AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETFRAMEWORK MESSAGE AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETCORE MESSAGES AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETFRAMEWORK MESSAGES AS READ']in:inbox is:read");
Assert.IsTrue(mesagesMoved >= 0);
}
}
}

0 comments on commit 7a07bcd

Please sign in to comment.