public async void ShouldShowInstructionCorrectly() { var context = new FakeRegistrationDb(); var mediator = MockBuilder.BuildMediatorMock(); var client = new Mock <ISendApiClient>(); var confirmHandler = new Mock <IConfirmSubscriptionMessageHandler>(); var handler = new GatherClassMessageHandler(mediator.Object, client.Object, MockBuilder.BuildFakeTranslator(), confirmHandler.Object, context, MockBuilder.BuildFakeLogger <GatherClassMessageHandler>()); await handler.ShowInstruction(await context.IncompleteUsers.FindAsync("sample-registering-user-with-year")); var expectedMessage = new SendRequest("sample-registering-user-with-year", new Message("class-selection-text", new[] { new QuickReply("1a", new Payload(PayloadType.Class, "sample-class-1a").ToJson()), new QuickReply("1b", new Payload(PayloadType.Class, "sample-class-1b").ToJson()), new QuickReply("1c", new Payload(PayloadType.Class, "sample-class-1c").ToJson()), new QuickReply("1d", new Payload(PayloadType.Class, "sample-class-1d").ToJson()), new QuickReply("1e", new Payload(PayloadType.Class, "sample-class-1e").ToJson()), new QuickReply("1f", new Payload(PayloadType.Class, "sample-class-1f").ToJson()), new QuickReply("1g", new Payload(PayloadType.Class, "sample-class-1g").ToJson()), new QuickReply("1h", new Payload(PayloadType.Class, "sample-class-1h").ToJson()), new QuickReply("1i", new Payload(PayloadType.Class, "sample-class-1i").ToJson()), new QuickReply("1j", new Payload(PayloadType.Class, "sample-class-1j").ToJson()), new QuickReply("cancel-button-text", new Payload(PayloadType.Cancel).ToJson()), new QuickReply("->", new Payload(PayloadType.Class, 1).ToJson()) })); client.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) ), Times.Once); client.VerifyNoOtherCalls(); }
public async void ShouldShowListPageCorrectly() { var context = new FakeRegistrationDb(); var mediator = MockBuilder.BuildMediatorMock(); var client = new Mock <ISendApiClient>(); var confirmHandler = new Mock <IGatherClassMessageHandler>(); var handler = new GatherYearMessageHandler(mediator.Object, client.Object, MockBuilder.BuildFakeTranslator(), confirmHandler.Object, context, MockBuilder.BuildFakeLogger <GatherYearMessageHandler>()); await handler.Handle( await context.IncompleteUsers.FindAsync("sample-registering-user-with-lang"), new Payload(PayloadType.Year, 1) ); var expectedMessage = new SendRequest("sample-registering-user-with-lang", new Message("year-selection-text", new[] { new QuickReply("11", new Payload(PayloadType.Year, "11").ToJson()), new QuickReply("12", new Payload(PayloadType.Year, "12").ToJson()), new QuickReply("cancel-button-text", new Payload(PayloadType.Cancel).ToJson()), new QuickReply("<-", new Payload(PayloadType.Year, 0).ToJson()) })); client.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) )); client.VerifyNoOtherCalls(); }
public async void ShouldCreateSubscriptionCorrectly() { var mediator = MockBuilder.BuildMediatorMock(); var context = new FakeRegistrationDb(); var client = new Mock <ISendApiClient>(); var handler = new ConfirmSubscriptionMessageHandler(context, mediator.Object, client.Object, MockBuilder.BuildFakeTranslator(), new Mock <ILogger <ConfirmSubscriptionMessageHandler> >().Object); await handler.Handle(await context.IncompleteUsers.FindAsync( "sample-registering-user-with-class"), new Payload(PayloadType.Subscribe)); context.IncompleteUsers.Should().NotContain(x => x.Id == "sample-registering-user-with-class"); mediator.Verify(x => x.Send(It.Is <CreateSubscriptionCommand>(y => y.Id == "sample-registering-user-with-class" && y.Platform == FacebookMessengerPlatformClient.PId && y.PreferredLanguage == "en" && y.Class == "sample-class"), It.IsAny <CancellationToken>()), Times.Once); mediator.VerifyNoOtherCalls(); var expectedMessage = new SendRequest("sample-registering-user-with-class", new Message( "congratulations-text", new[] { new QuickReply("cancel-button-text", new Payload(PayloadType.Cancel).ToJson()) }) ); client.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) )); client.VerifyNoOtherCalls(); }
public async void ShouldCancelSubscriptionCorrectly() { var mediator = MockBuilder.BuildMediatorMock(); var apiClient = new Mock <ISendApiClient>(); var message = new Messaging { Sender = new Sender { Id = "sample-subscriber" }, Recipient = new Recipient { Id = "sample-page-id" }, Timestamp = 123456789, Message = new Message { Mid = "sample-message-id", Text = "Cancel", QuickReply = new QuickReply { Payload = new Payload(PayloadType.Cancel).ToJson() } } }; var handler = new CancelSubscriptionMessageHandler(mediator.Object, apiClient.Object, MockBuilder.BuildFakeTranslator(), MockBuilder.BuildFakeLogger <CancelSubscriptionMessageHandler>()); await handler.Handle(message); mediator.Verify( x => x.Send( It.Is <GetSubscriberQuery>(y => y.Id == "sample-subscriber" && y.Platform == FacebookMessengerPlatformClient.PId), It.IsAny <CancellationToken>()), Times.Once); mediator.Verify( x => x.Send( It.Is <CancelSubscriptionCommand>(y => y.Id == "sample-subscriber" && y.Platform == FacebookMessengerPlatformClient.PId), It.IsAny <CancellationToken>()), Times.Once); mediator.VerifyNoOtherCalls(); var expectedMessage = new SendRequest("sample-subscriber", new FacebookMessenger.SendAPIClient.Requests.Message("subscription-cancelled-text") ); apiClient.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) )); apiClient.VerifyNoOtherCalls(); }
public async void ShouldUpdateUserCorrectly() { var context = new FakeRegistrationDb(); var client = new Mock <ISendApiClient>(); var yearHandler = new Mock <IGatherYearMessageHandler>(); var handler = new GatherLanguageMessageHandler(MockBuilder.BuildFakeConfiguration(), client.Object, MockBuilder.BuildFakeTranslator(), yearHandler.Object, context, MockBuilder.BuildFakeLogger <GatherLanguageMessageHandler>()); await handler.Handle(await context.IncompleteUsers.FindAsync("sample-registering-user"), new Payload(PayloadType.Lang, "pl")); context.IncompleteUsers.Should().ContainSingle(x => x.Id == "sample-registering-user" && x.PreferredLanguage == "pl" && x.LastPage == 0 && x.Stage == Stage.GatheredLanguage); yearHandler.Verify(x => x.ShowInstruction(It.Is <IncompleteUser>(y => y.Id == "sample-registering-user"), 0), Times.Once); yearHandler.VerifyNoOtherCalls(); }
public async void ShouldCancelRegistrationCorrectly() { var context = new FakeRegistrationDb(); var apiClient = new Mock <ISendApiClient>(); var message = new Messaging { Sender = new Sender { Id = "sample-registering-user" }, Recipient = new Recipient { Id = "sample-page-id" }, Timestamp = 123456789, Message = new Message { Mid = "sample-message-id", Text = "sample-message-text", QuickReply = new QuickReply { Payload = new Payload(PayloadType.Cancel).ToJson() } } }; var handler = new CancelRegistrationMessageHandler(context, apiClient.Object, MockBuilder.BuildFakeTranslator(), new Mock <ILogger <CancelRegistrationMessageHandler> >().Object); await handler.Handle(message); context.IncompleteUsers.Should().NotContain(x => x.Id == "sample-registering-user"); var expectedMessage = new SendRequest( "sample-registering-user", new FacebookMessenger.SendAPIClient.Requests.Message("subscription-cancelled-text") ); apiClient.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) )); apiClient.VerifyNoOtherCalls(); }
public async void ShouldHandleUnsupportedCommandCorrectly() { var mediator = MockBuilder.BuildMediatorMock(); var context = new FakeRegistrationDb(); var client = new Mock <ISendApiClient>(); var handler = new ConfirmSubscriptionMessageHandler(context, mediator.Object, client.Object, MockBuilder.BuildFakeTranslator(), new Mock <ILogger <ConfirmSubscriptionMessageHandler> >().Object); await handler.Handle(await context.IncompleteUsers.FindAsync("sample-registering-user-with-class"), new Payload()); var expectedMessage = new SendRequest("sample-registering-user-with-class", new Message("unsupported-command-text", new[] { new QuickReply("cancel-button-text", new Payload(PayloadType.Cancel).ToJson()), new QuickReply("subscribe-button-text", new Payload(PayloadType.Subscribe).ToJson()) })); client.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) )); client.VerifyNoOtherCalls(); }
public async void ShouldShowInstructionCorrectly() { var context = new FakeRegistrationDb(); var client = new Mock <ISendApiClient>(); var yearHandler = new Mock <IGatherYearMessageHandler>(); var handler = new GatherLanguageMessageHandler(MockBuilder.BuildFakeConfiguration(), client.Object, MockBuilder.BuildFakeTranslator(), yearHandler.Object, context, MockBuilder.BuildFakeLogger <GatherLanguageMessageHandler>()); await handler.ShowInstruction(await context.IncompleteUsers.FindAsync("sample-registering-user")); var expectedMessage = new SendRequest("sample-registering-user", new Message("greeting-text", new[] { new QuickReply("EN", new Payload(PayloadType.Lang, "en").ToJson()), new QuickReply("PL", new Payload(PayloadType.Lang, "pl").ToJson()), new QuickReply("cancel-button-text", new Payload(PayloadType.Cancel).ToJson()) })); client.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) )); client.VerifyNoOtherCalls(); }
public async void ShouldShowInstructionCorrectly() { var context = new FakeRegistrationDb(); var mediator = MockBuilder.BuildMediatorMock(); var client = new Mock <ISendApiClient>(); var confirmHandler = new Mock <IGatherClassMessageHandler>(); var handler = new GatherYearMessageHandler(mediator.Object, client.Object, MockBuilder.BuildFakeTranslator(), confirmHandler.Object, context, MockBuilder.BuildFakeLogger <GatherYearMessageHandler>()); await handler.ShowInstruction(await context.IncompleteUsers.FindAsync("sample-registering-user-with-lang")); context.IncompleteUsers.Should().ContainSingle(x => x.Id == "sample-registering-user-with-lang" && x.PreferredLanguage == "en" && x.LastPage == 0 && x.Stage == Stage.GatheredLanguage); var expectedMessage = new SendRequest("sample-registering-user-with-lang", new Message("year-selection-text", new[] { new QuickReply("1", new Payload(PayloadType.Year, "1").ToJson()), new QuickReply("2", new Payload(PayloadType.Year, "2").ToJson()), new QuickReply("3", new Payload(PayloadType.Year, "3").ToJson()), new QuickReply("4", new Payload(PayloadType.Year, "4").ToJson()), new QuickReply("5", new Payload(PayloadType.Year, "5").ToJson()), new QuickReply("6", new Payload(PayloadType.Year, "6").ToJson()), new QuickReply("7", new Payload(PayloadType.Year, "7").ToJson()), new QuickReply("8", new Payload(PayloadType.Year, "8").ToJson()), new QuickReply("9", new Payload(PayloadType.Year, "9").ToJson()), new QuickReply("10", new Payload(PayloadType.Year, "10").ToJson()), new QuickReply("cancel-button-text", new Payload(PayloadType.Cancel).ToJson()), new QuickReply("->", new Payload(PayloadType.Year, 1).ToJson()) })); client.Verify(x => x.Send( It.Is <SendRequest>(y => y.IsEquivalentTo(expectedMessage)) )); client.VerifyNoOtherCalls(); }
public async void ShouldUpdateUserCorrectly() { var context = new FakeRegistrationDb(); var confirmHandler = new Mock <IConfirmSubscriptionMessageHandler>(); var handler = new GatherClassMessageHandler(MockBuilder.BuildMediatorMock().Object, new Mock <ISendApiClient>().Object, MockBuilder.BuildFakeTranslator(), confirmHandler.Object, context, MockBuilder.BuildFakeLogger <GatherClassMessageHandler>()); await handler.Handle(await context.IncompleteUsers.FindAsync("sample-registering-user-with-year"), new Payload(PayloadType.Class, "sample-class-1a")); context.IncompleteUsers.Should().ContainSingle(x => x.Id == "sample-registering-user-with-year" && x.PreferredLanguage == "en" && x.Year == 1 && x.ClassId == "sample-class-1a" && x.LastPage == 0 && x.Stage == Stage.GatheredClass); confirmHandler.Verify( x => x.ShowInstruction( It.Is <IncompleteUser>(y => y.Id == "sample-registering-user-with-year") ), Times.Once); confirmHandler.VerifyNoOtherCalls(); }
public PlatformClientBuilder() { ApiClientMock = new Mock <ISendApiClient>(); PlatformClient = new FacebookMessengerPlatformClient(ApiClientMock.Object, MockBuilder.BuildMediatorMock().Object, MockBuilder.BuildFakeTranslator(), MockBuilder.BuildFakeLogger <FacebookMessengerPlatformClient>()); }