Skip to content

Commit

Permalink
Release 1.1.4.0
Browse files Browse the repository at this point in the history
修復呼叫 API 有機會出現 Process terminated. Assertion Failed

bug: #21
  • Loading branch information
ChengYen-Tang committed Jan 22, 2021
1 parent 16198ed commit 3a50cdc
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 83 deletions.
67 changes: 33 additions & 34 deletions MicrosoftGraphAPIBot.dgml

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions MicrosoftGraphAPIBot/MicrosoftGraph/CalendarApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Graph;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -37,7 +36,7 @@ public async Task<bool> CallCreateCalendarAsync()

IUserCalendarsCollectionPage calendars = await ListCalendarAsync(graphClient);
bool isCreate = calendars.CurrentPage.Any(item => item.Id == calendar.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

await DeleteCalendarAsync(graphClient, calendar.Id);
return true;
Expand All @@ -63,12 +62,12 @@ public async Task<bool> CallUpdateCalendarAsync()

IUserCalendarsCollectionPage calendars = await ListCalendarAsync(graphClient);
bool isCreate = calendars.CurrentPage.Any(item => item.Id == calendar.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

Calendar newCalendar = await UpdateCalendarAsync(graphClient, calendar.Id);
calendars = await ListCalendarAsync(graphClient);
bool isUpdate = calendars.CurrentPage.Any(item => item.Id == calendar.Id && item.Name == newCalendar.Name);
Trace.Assert(isUpdate);
Utils.Assert(isUpdate);

await DeleteCalendarAsync(graphClient, calendar.Id);
return true;
Expand Down
11 changes: 5 additions & 6 deletions MicrosoftGraphAPIBot/MicrosoftGraph/OneDriveApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Graph;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -37,7 +36,7 @@ public async Task<bool> CallCreateFolderAsync()
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);

bool isCreate = items.CurrentPage.Any(driveItem => driveItem.Id == item.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

await FileApi.DeleteDriveItemAsync(graphClient, item.Id);
return true;
Expand All @@ -63,13 +62,13 @@ public async Task<bool> CallUpdateDriveItemAsync()
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);

bool isCreate = items.CurrentPage.Any(driveItem => driveItem.Name == folderItem.Name);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

DriveItem newFolderItem = await FileApi.UpdateDriveItemAsync(graphClient, folderItem.Id);
items = await FileApi.ListDriveItemAsync(graphClient);

bool isUpdate = items.CurrentPage.Any(driveItem => driveItem.Name == newFolderItem.Name);
Trace.Assert(isUpdate);
Utils.Assert(isUpdate);

await FileApi.DeleteDriveItemAsync(graphClient, folderItem.Id);
return true;
Expand All @@ -96,13 +95,13 @@ public async Task<bool> CallMoveDriveItemAsync()
folderItem[1] = await FileApi.CreateFolderAsync(graphClient);
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);
bool isUpdate = items.CurrentPage.Count(driveItem => folderItem.Select(c => c.Id).Contains(driveItem.Id)) == 2;
Trace.Assert(isUpdate);
Utils.Assert(isUpdate);

await FileApi.MoveDriveItemAsync(graphClient, folderItem[0].Id, folderItem[1].Id);

IDriveItemChildrenCollectionPage folder1Items = await FileApi.GetDriveItemAsync(graphClient, folderItem[0].Id);
bool isMove = folder1Items.CurrentPage.Any(driveItem => driveItem.Id == folderItem[1].Id);
Trace.Assert(isMove);
Utils.Assert(isMove);

await FileApi.DeleteDriveItemAsync(graphClient, folderItem[0].Id);
return true;
Expand Down
11 changes: 5 additions & 6 deletions MicrosoftGraphAPIBot/MicrosoftGraph/OutlookApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Graph;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -37,7 +36,7 @@ public async Task<bool> CallCreateMessageAsync()
Message message = await CreateMessageAsync(graphClient);
Message message1 = await GetMessageAsync(graphClient, message.Id);

Trace.Assert(message.Id == message1.Id);
Utils.Assert(message.Id == message1.Id);

await DeleteMessageAsync(graphClient, message.Id);
return true;
Expand All @@ -62,12 +61,12 @@ public async Task<bool> CallUpdateMessageAsync()
Message message = await CreateMessageAsync(graphClient);
Message message1 = await GetMessageAsync(graphClient, message.Id);

Trace.Assert(message.Id == message1.Id);
Utils.Assert(message.Id == message1.Id);

Guid id = await UpdateMessageAsync(graphClient, message.Id);
message1 = await GetMessageAsync(graphClient, message.Id);

Trace.Assert(message1.Subject == id.ToString());
Utils.Assert(message1.Subject == id.ToString());

await DeleteMessageAsync(graphClient, message.Id);
return true;
Expand All @@ -92,13 +91,13 @@ public async Task<bool> CallSendMessageAsync()
Message message = await CreateMessageAsync(graphClient);
Message message1 = await GetMessageAsync(graphClient, message.Id);

Trace.Assert(message.Id == message1.Id);
Utils.Assert(message.Id == message1.Id);

await SendMessageAsync(graphClient, message.Id);

IList<Message> messages = await ListMessageAsync(graphClient);
IEnumerable<Message> messages1 = messages.Where(item => item.Subject.Contains(message.Subject));
Trace.Assert(messages1.Any());
Utils.Assert(messages1.Any());

foreach (Message message2 in messages1)
await DeleteMessageAsync(graphClient, message2.Id);
Expand Down
27 changes: 13 additions & 14 deletions MicrosoftGraphAPIBot/MicrosoftGraph/PermissionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Graph;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -36,13 +35,13 @@ public async Task<bool> CallCreateShareLinkAsync()
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);

bool isCreate = items.CurrentPage.Any(driveItem => driveItem.Id == item.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

Permission link = await CreateShareLinkAsync(graphClient, item.Id);
var links = await ListShareLinkAsync(graphClient, item.Id);

isCreate = links.CurrentPage.Any(linkItem => linkItem.Id == link.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

await FileApi.DeleteDriveItemAsync(graphClient, item.Id);
return true;
Expand All @@ -68,16 +67,16 @@ public async Task<bool> CallAccessingShareLinkAsync()
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);

bool isCreate = items.CurrentPage.Any(driveItem => driveItem.Id == item.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

Permission link = await CreateShareLinkAsync(graphClient, item.Id);
var links = await ListShareLinkAsync(graphClient, item.Id);

isCreate = links.CurrentPage.Any(linkItem => linkItem.Id == link.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

SharedDriveItem sharedItem = await AccessingSharedLinkAsync(graphClient, link.Link.WebUrl);
Trace.Assert(sharedItem.Name == item.Name);
Utils.Assert(sharedItem.Name == item.Name);

await FileApi.DeleteDriveItemAsync(graphClient, item.Id);
return true;
Expand All @@ -101,11 +100,11 @@ public async Task<bool> CallGetSharingLinkAsync()
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);

bool isCreate = items.CurrentPage.Any(driveItem => driveItem.Id == item.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

Permission link = await CreateShareLinkAsync(graphClient, item.Id);
Permission linkInfo = await GetShareLinkAsync(graphClient, item.Id, link.Id);
Trace.Assert(string.Join(',', link.Roles) == string.Join(',', linkInfo.Roles));
Utils.Assert(string.Join(',', link.Roles) == string.Join(',', linkInfo.Roles));

await FileApi.DeleteDriveItemAsync(graphClient, item.Id);
return true;
Expand All @@ -125,17 +124,17 @@ public async Task<bool> CallUpdateSharingLinkAsync()
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);

bool isCreate = items.CurrentPage.Any(driveItem => driveItem.Id == item.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

Permission link = await CreateShareLinkAsync(graphClient, item.Id);
var links = await ListShareLinkAsync(graphClient, item.Id);

isCreate = links.CurrentPage.Any(linkItem => linkItem.Id == link.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

link = await UpdateShareLinkAsync(graphClient, item.Id, link.Id);
Permission linkInfo = await GetShareLinkAsync(graphClient, item.Id, link.Id);
Trace.Assert(string.Join(',', link.Roles) == string.Join(',', linkInfo.Roles));
Utils.Assert(string.Join(',', link.Roles) == string.Join(',', linkInfo.Roles));

await FileApi.DeleteDriveItemAsync(graphClient, item.Id);
return true;
Expand All @@ -161,19 +160,19 @@ public async Task<bool> CallDeleteSharingLinkAsync()
IDriveItemChildrenCollectionPage items = await FileApi.ListDriveItemAsync(graphClient);

bool isCreate = items.CurrentPage.Any(driveItem => driveItem.Id == item.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

Permission link = await CreateShareLinkAsync(graphClient, item.Id);
var links = await ListShareLinkAsync(graphClient, item.Id);

isCreate = links.CurrentPage.Any(linkItem => linkItem.Id == link.Id);
Trace.Assert(isCreate);
Utils.Assert(isCreate);

await DeleteShareLinkAsync(graphClient, item.Id, link.Id);
links = await ListShareLinkAsync(graphClient, item.Id);

isCreate = links.CurrentPage.Any(linkItem => linkItem.Id == link.Id);
Trace.Assert(!isCreate);
Utils.Assert(!isCreate);

await FileApi.DeleteDriveItemAsync(graphClient, item.Id);
return true;
Expand Down
7 changes: 3 additions & 4 deletions MicrosoftGraphAPIBot/MicrosoftGraph/PersonalContactsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Graph;
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace MicrosoftGraphAPIBot.MicrosoftGraph
Expand Down Expand Up @@ -34,7 +33,7 @@ public async Task<bool> CallCreateContactAsync()
{
Contact contact = await CreateContact(graphClient);
Contact contact1 = await GetContact(graphClient, contact.Id);
Trace.Assert(contact.DisplayName == contact1.DisplayName);
Utils.Assert(contact.DisplayName == contact1.DisplayName);

await DeleteContact(graphClient, contact.Id);
return true;
Expand All @@ -58,11 +57,11 @@ public async Task<bool> CallUpdateContactAsync()
{
Contact contact = await CreateContact(graphClient);
Contact contact1 = await GetContact(graphClient, contact.Id);
Trace.Assert(contact.DisplayName == contact1.DisplayName);
Utils.Assert(contact.DisplayName == contact1.DisplayName);

Contact updateContact = await UpdateContact(graphClient, contact.Id);
contact1 = await GetContact(graphClient, contact.Id);
Trace.Assert(updateContact.DisplayName == contact1.DisplayName);
Utils.Assert(updateContact.DisplayName == contact1.DisplayName);

await DeleteContact(graphClient, contact.Id);
return true;
Expand Down
22 changes: 9 additions & 13 deletions MicrosoftGraphAPIBot/MicrosoftGraphAPIBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,35 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="HangFire.Core" Version="1.7.18" />
<PackageReference Include="HangFire.SqlServer" Version="1.7.18" />
<PackageReference Include="HangFire.Core" Version="1.7.19" />
<PackageReference Include="HangFire.SqlServer" Version="1.7.19" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="3.3.2">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
<PackageReference Include="Microsoft.Graph" Version="3.21.0" />
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.15.0.24505">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.16.0.25740">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
12 changes: 12 additions & 0 deletions MicrosoftGraphAPIBot/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Threading.Tasks;

Expand Down Expand Up @@ -113,6 +114,17 @@ private static async Task<bool> CheckNeedUpdateAsync(IServiceProvider servicePro
}
}

/// <summary>
/// 條件不符投擲例外訊息
/// </summary>
/// <param name="condition"></param>
/// <param name="lineNumber"></param>
/// <param name="caller"></param>
public static void Assert(bool condition, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null)
{
if (!condition)
throw new BotException($"Caller: {caller}, Line number: {lineNumber}, Assertion Failed");
}
#region Config

private static readonly string[] configKeys = new string[]
Expand Down
15 changes: 15 additions & 0 deletions MicrosoftGraphBotTests/BotUtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MicrosoftGraphAPIBot;
using MicrosoftGraphAPIBot.Models;
using MicrosoftGraphAPIBot.Telegram;
using Moq;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down Expand Up @@ -111,6 +113,19 @@ public async Task TestPushNoApiResultAsync()
await MicrosoftGraphAPIBot.Utils.PushApiResultAsync(serviceProvider);
}

[TestMethod]
public void TestAssertTrue()
{
MicrosoftGraphAPIBot.Utils.Assert(true);
}

[TestMethod]
[ExpectedException(typeof(BotException))]
public void TestAssertFalse()
{
MicrosoftGraphAPIBot.Utils.Assert(false);
}

[TestCleanup]
public async Task Cleanup()
{
Expand Down
2 changes: 1 addition & 1 deletion MicrosoftGraphBotTests/MSGraphAuthApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace MicrosoftGraphBotTests
[TestClass]
public class MSGraphAuthApiTests
{
private AuthCodeController authCodeController;
private readonly AuthCodeController authCodeController;

public MSGraphAuthApiTests()
{
Expand Down
8 changes: 8 additions & 0 deletions ReleaseNotes/1.1.4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## 新功能:

## 變更:

## Bug 修復:
Process terminated. Assertion Failed [(#21)](https://github.com/NTUT-SELab/MicrosoftGraphBot/issues/21)

## 文檔:
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variables:
buildConfiguration: 'Release'
version: '1.1.2.0'
version: '1.1.4.0'

stages:
- stage: Build_and_Test
Expand Down

0 comments on commit 3a50cdc

Please sign in to comment.