Skip to content

Commit

Permalink
add service mock and refine API tests (microsoft#426)
Browse files Browse the repository at this point in the history
* add service mock and refine API tests

* add some comments
  • Loading branch information
ChengxianMo authored Dec 14, 2018
1 parent 3c45afa commit ee98f81
Show file tree
Hide file tree
Showing 11 changed files with 592 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using Google.Apis.Auth.OAuth2.Responses;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Requests;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using GoogleCalendarService = Google.Apis.Calendar.v3.CalendarService;

namespace CalendarSkill.ServiceClients.GoogleAPI
namespace CalendarSkill.ServiceClients
{
/// <summary>
/// The Google Calendar API service.
Expand Down Expand Up @@ -149,7 +150,7 @@ public async Task DeleteEventById(string id)
private Event UpdateEventById(Event updateEvent)
{
var request = service.Events.Patch(updateEvent, "primary", updateEvent.Id);
var gevent = request.Execute();
var gevent = ((IClientServiceRequest<Event>)request).Execute();
return gevent;
}

Expand All @@ -164,7 +165,7 @@ private Events RequestEventsByTime(DateTime startTime, DateTime endTime)
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

// List events.
var events = request.Execute();
var events = ((IClientServiceRequest<Events>)request).Execute();
return events;
}

Expand All @@ -179,7 +180,7 @@ private Events RequestEventsByStartTime(DateTime startTime)
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

// List events.
var events = request.Execute();
var events = ((IClientServiceRequest<Events>)request).Execute();
return events;
}

Expand All @@ -194,7 +195,7 @@ private Events GetEvents()
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

// List events.
var events = request.Execute();
var events = ((IClientServiceRequest<Events>)request).Execute();
return events;
}

Expand All @@ -211,13 +212,15 @@ private Event GetNextEvent()

private Event CreateEvent(Event newEvent)
{
return service.Events.Insert(newEvent, "primary").Execute();
var request = service.Events.Insert(newEvent, "primary");
var gevent = ((IClientServiceRequest<Event>)request).Execute();
return gevent;
}

private string DeleteEvent(string id)
{
var request = service.Events.Delete("primary", id);
var result = request.Execute();
var result = ((IClientServiceRequest<string>)request).Execute();
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Microsoft.Bot.Solutions.Skills;

namespace CalendarSkill.ServiceClients.GoogleAPI
namespace CalendarSkill.ServiceClients
{
public class GoogleClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CalendarSkill.ServiceClients.GoogleAPI;
using CalendarSkill.ServiceClients;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Responses;
Expand All @@ -16,7 +16,7 @@
using GooglePerson = Google.Apis.People.v1.Data.Person;
using MsPerson = Microsoft.Graph.Person;

namespace CalendarSkill
namespace CalendarSkill.ServiceClients
{
/// <summary>
/// The Google People API service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using Microsoft.Graph;

namespace CalendarSkill
namespace CalendarSkill.ServiceClients
{
public class MSGraphCalendarAPI : ICalendar
{
Expand Down Expand Up @@ -181,22 +181,6 @@ public async Task<Event> UpdateEvent(Event updateEvent)
return updatedEvet;
}

// Get events in all the current user's mail folders.
private async Task<List<Event>> GetMyEvents()
{
var items = new List<Event>();

// Get events.
var events = await _graphClient.Me.Events.Request().GetAsync();

if (events?.Count > 0)
{
items.AddRange(events);
}

return items;
}

// Get events in all the current user's mail folders.
private async Task<List<Event>> GetMyStartTimeEvents(DateTime startTime)
{
Expand Down Expand Up @@ -295,22 +279,5 @@ private async Task<Event> CreateEvent(Event newEvent)
var createdEvent = await _graphClient.Me.Events.Request().AddAsync(newEvent);
return createdEvent;
}

// Get a specified event.
private async Task<List<Event>> GetEvent(string id)
{
var items = new List<Event>();

// Get the event.
var retrievedEvent = await _graphClient.Me.Events[id].Request().GetAsync();

if (retrievedEvent != null)
{
// Get event properties.
items.Add(retrievedEvent);
}

return items;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using CalendarSkill.ServiceClients;
using CalendarSkill.ServiceClients.GoogleAPI;
using Microsoft.Bot.Solutions.Skills;

namespace CalendarSkill
Expand Down
Loading

0 comments on commit ee98f81

Please sign in to comment.