public async Task WhenAskedItShouldGetTimesheets() { var sender = new ChatEventMessageSender(); var space = new ChatEventSpace(); var message = new ChatEventMessage { Sender = sender }; var chat = new ChatEvent { Space = space, Message = message }; var responder = Substitute.For <IHangoutsChatConnector>(); var timesheet = new Timesheet { Name = "A", UserName = "******", UserEmail = "[email protected]", DepartmentName = "F", Total = 20 }; var info = new TextDeconstructionInformation("Get unsubmited timesheets", null, SentenceTypes.Command); _connector.GetUnsubmittedTimesheetsAsync(DateTime.MinValue).ReturnsForAnyArgs(new[] { timesheet }); // Act var result = await _processor.ProcessCommandAsync(info, chat, responder); // Test System.Threading.Thread.Sleep(150); Assert.AreEqual(null, result.Text); responder .Received() .SendMessageAsync( null, Arg.Is <GoogleChatAddress>(it => it.Sender == sender && it.Space == space), Arg.Any <Card[]>()); }
public async Task WhenAskedItShouldRepeatAsync() { var sender = new ChatEventMessageSender(); var space = new ChatEventSpace(); var message = new ChatEventMessage { Sender = sender }; var chat = new ChatEvent { Space = space, Message = message }; var responder = Substitute.For <IAsyncResponder>(); var info = new TextDeconstructionInformation( "Repeat delay 100 Test", "Time", SentenceTypes.Unknown, new Dictionary <string, string[]> { { "Time", new[] { "100" } } }, null, 1.0); var result = await _processor.ProcessCommandAsync(info, chat, responder, null); responder .DidNotReceive() .SendMessageAsync("Test", Arg.Any <GoogleChatAddress>()); Thread.Sleep(150); responder .Received() .SendMessageAsync("Test", Arg.Is <GoogleChatAddress>(it => it.Space == space && it.Sender == sender)); }
/// <summary>Initializes a new instance of the <see cref="GoogleChatAddress"/> class.</summary> public GoogleChatAddress(string spaceName, string spaceDisplayName, string spaceType, string senderName, string senderDisplayName) { Space = new ChatEventSpace { Name = spaceName, DisplayName = spaceDisplayName, Type = spaceType }; Sender = new ChatEventMessageSender { Name = senderName, DisplayName = senderDisplayName }; }
private static ChatEvent CreateEvent(string senderEmail) { var sender = new ChatEventMessageSender() { Email = senderEmail }; var space = new ChatEventSpace(); var message = new ChatEventMessage { Sender = sender }; return(new ChatEvent { Space = space, Message = message }); }
public async Task WhenAskedItShouldRepeatAsync() { var sender = new ChatEventMessageSender(); var space = new ChatEventSpace(); var message = new ChatEventMessage { Sender = sender }; var chat = new ChatEvent { Space = space, Message = message }; var responder = Substitute.For <IAsyncResponder>(); var info = new TextDeconstructionInformation("Repeat delay 1000 Test", null, SentenceTypes.Command); var result = await _processor.ProcessCommandAsync(info, chat, responder); responder.Received().SendMessageAsync("Test", space, null, sender); }
public async Task ChatConnectorCreatesMessage() { var space = new ChatEventSpace { Name = "S1", DisplayName = "S2" }; var sender = new ChatEventMessageSender { Name = "U1", DisplayName = "U2" }; var clientService = Substitute.For <IClientService>(); var service = Substitute.ForPartsOf <HangoutsChatService>(); var spaces = Substitute.ForPartsOf <SpacesResource>(clientService); var messages = Substitute.ForPartsOf <SpacesResource.MessagesResource>(clientService); service.Spaces.Returns(spaces); spaces.Messages.Returns(messages); messages.Create(null, null).ReturnsForAnyArgs((SpacesResource.MessagesResource.CreateRequest)null); var connector = new HangoutsChatConnector(new Lazy <HangoutsChatService>(service)); await connector.SendMessageAsync("A", space, null, sender); messages.Received().Create(Arg.Any <Message>(), "S1"); }
/// <summary>Initializes a new instance of the <see cref="GoogleChatAddress"/> class.</summary> public GoogleChatAddress(ChatEventSpace space, ChatEventMessageSender sender) { Space = space; Sender = sender; }
/// <inheritdoc/> /// ChatEventSpace space, ChatEventMessageThread thread, ChatEventMessageSender sender public Task SendMessageAsync(string text, ChatEventSpace space, ChatEventMessageThread thread, ChatEventMessageSender sender) { if (space == null || sender == null) { throw new InvalidOperationException("When async responder is called, space and sender are requireired."); } ////_logger.LogDebug($"Send a message asynchronius {text} to '{space.DisplayName}' by {sender.DisplayName} '{thread?.Name}'."); var messages = _serviceProvider.Value.Spaces.Messages; var message = new Message { Sender = new User { Name = sender.Name, DisplayName = sender.DisplayName }, Space = new Space { Name = space.Name, DisplayName = space.DisplayName, Type = space.Type }, Text = text }; if (thread != null) { message.Thread = new Thread { Name = thread.Name }; } var createRequest = messages.Create(message, space.Name); return(createRequest?.ExecuteAsync() ?? Task.CompletedTask); }