Skip to content

Commit

Permalink
Add unit tests for the new classes and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaavila committed Jul 27, 2023
1 parent f1bca0c commit 5cc1614
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,80 @@ void CaptureSend(Activity[] arg)
Assert.Equal("10101010", activitiesToSend[0].Text);
}

[Fact]
public async Task TestMeetingParticipantsAddedEvent()
{
// Arrange
var activity = new Activity
{
ChannelId = Channels.Msteams,
Type = ActivityTypes.Event,
Name = "application/vnd.microsoft.meetingParticipantsAdded",
Value = JObject.Parse(@"{
ParticipantsAdded: [
{Id: 'id', Name: 'name'}
]
}"),
};

Activity[] activitiesToSend = null;
void CaptureSend(Activity[] arg)
{
activitiesToSend = arg;
}

var turnContext = new TurnContext(new SimpleAdapter(CaptureSend), activity);

// Act
var bot = new TestActivityHandler();
await ((IBot)bot).OnTurnAsync(turnContext);

// Assert
Assert.Equal(2, bot.Record.Count);
Assert.Equal("OnEventActivityAsync", bot.Record[0]);
Assert.Equal("OnTeamsMeetingParticipantsAddedAsync", bot.Record[1]);
Assert.NotNull(activitiesToSend);
Assert.Single(activitiesToSend);
Assert.Equal("id", activitiesToSend[0].Text);
}

[Fact]
public async Task TestMeetingParticipantsRemovedEvent()
{
// Arrange
var activity = new Activity
{
ChannelId = Channels.Msteams,
Type = ActivityTypes.Event,
Name = "application/vnd.microsoft.meetingParticipantsRemoved",
Value = JObject.Parse(@"{
ParticipantsRemoved: [
{Id: 'id', Name: 'name'}
]
}"),
};

Activity[] activitiesToSend = null;
void CaptureSend(Activity[] arg)
{
activitiesToSend = arg;
}

var turnContext = new TurnContext(new SimpleAdapter(CaptureSend), activity);

// Act
var bot = new TestActivityHandler();
await ((IBot)bot).OnTurnAsync(turnContext);

// Assert
Assert.Equal(2, bot.Record.Count);
Assert.Equal("OnEventActivityAsync", bot.Record[0]);
Assert.Equal("OnTeamsMeetingParticipantsRemovedAsync", bot.Record[1]);
Assert.NotNull(activitiesToSend);
Assert.Single(activitiesToSend);
Assert.Equal("id", activitiesToSend[0].Text);
}

[Fact]
public async Task TestMessageUpdateActivityTeamsMessageEdit()
{
Expand Down Expand Up @@ -1536,6 +1610,20 @@ protected override Task OnTeamsReadReceiptAsync(ReadReceiptInfo readReceiptInfo,
return Task.CompletedTask;
}

protected override Task OnTeamsMeetingParticipantsAddedAsync(MeetingParticipantsAddedEventDetails meeting, ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
{
Record.Add(MethodBase.GetCurrentMethod().Name);
turnContext.SendActivityAsync(meeting.ParticipantsAdded[0].Id);
return base.OnTeamsMeetingParticipantsAddedAsync(meeting, turnContext, cancellationToken);
}

protected override Task OnTeamsMeetingParticipantsRemovedAsync(MeetingParticipantsRemovedEventDetails meeting, ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
{
Record.Add(MethodBase.GetCurrentMethod().Name);
turnContext.SendActivityAsync(meeting.ParticipantsRemoved[0].Id);
return base.OnTeamsMeetingParticipantsRemovedAsync(meeting, turnContext, cancellationToken);
}

// Invoke
protected override Task<InvokeResponse> OnInvokeActivityAsync(ITurnContext<IInvokeActivity> turnContext, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright(c) Microsoft Corporation.All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Microsoft.Bot.Schema.Teams;
using Xunit;

namespace Microsoft.Bot.Schema.Tests.Teams
{
public class MeetingParticipantsAddedEventDetailsTests
{
[Fact]
public void MeetingParticipantsAddedEventDetailsInits()
{
// Arrange
var meetingId = "meetingId";
var meetingJoinUrl = new Uri("http://meetingJoinUrl");
var meetingTitle = "meetingTitle";
var meetingType = "meetingType";
var participant = new TeamsChannelAccount("id", "name", "givenName", "surname", "email", "userPrincipalName");
var participantsAdded = new List<TeamsChannelAccount>() { participant };

// Act
var meeting = new MeetingParticipantsAddedEventDetails(meetingId, meetingJoinUrl, meetingTitle, meetingType, participantsAdded);

// Assert
Assert.NotNull(meeting);
Assert.IsType<MeetingParticipantsAddedEventDetails>(meeting);
Assert.Equal(meetingId, meeting.Id);
Assert.Equal(meetingJoinUrl, meeting.JoinUrl);
Assert.Equal(meetingTitle, meeting.Title);
Assert.Equal(meetingType, meeting.MeetingType);
Assert.StrictEqual(participantsAdded, meeting.ParticipantsAdded);
}

[Fact]
public void MeetingParticipantsAddedEventDetailsInitsWithNoArgs()
{
// Act
var meeting = new MeetingParticipantsAddedEventDetails();

// Assert
Assert.NotNull(meeting);
Assert.IsType<MeetingParticipantsAddedEventDetails>(meeting);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Microsoft.Bot.Schema.Teams;
using Xunit;

namespace Microsoft.Bot.Schema.Tests.Teams
{
public class MeetingParticipantsRemovedEventDetailsTests
{
[Fact]
public void MeetingParticipantsRemovedEventDetailsInits()
{
// Arrange
var meetingId = "meetingId";
var meetingJoinUrl = new Uri("http://meetingJoinUrl");
var meetingTitle = "meetingTitle";
var meetingType = "meetingType";
var participant = new TeamsChannelAccount("id", "name", "givenName", "surname", "email", "userPrincipalName");
var participantsRemoved = new List<TeamsChannelAccount>() { participant };

// Act
var meeting = new MeetingParticipantsRemovedEventDetails(meetingId, meetingJoinUrl, meetingTitle, meetingType, participantsRemoved);

// Assert
Assert.NotNull(meeting);
Assert.IsType<MeetingParticipantsRemovedEventDetails>(meeting);
Assert.Equal(meetingId, meeting.Id);
Assert.Equal(meetingJoinUrl, meeting.JoinUrl);
Assert.Equal(meetingTitle, meeting.Title);
Assert.Equal(meetingType, meeting.MeetingType);
Assert.StrictEqual(participantsRemoved, meeting.ParticipantsRemoved);
}

[Fact]
public void MeetingParticipantsRemovedEventDetailsInitsWithNoArgs()
{
// Act
var meeting = new MeetingParticipantsRemovedEventDetails();

// Assert
Assert.NotNull(meeting);
Assert.IsType<MeetingParticipantsRemovedEventDetails>(meeting);
}
}
}

0 comments on commit 5cc1614

Please sign in to comment.