public ClientOutboxCleanerTestsFixture() { Now = DateTime.UtcNow; MessageSession = new TestableMessageSession(); CancellationToken = CancellationToken.None; TimerService = new Mock <ITimerService>(); ClientOutboxMessages = new List <IClientOutboxMessageAwaitingDispatch>(); ClientOutboxMessageV2s = new List <IClientOutboxMessageAwaitingDispatch>(); ClientOutboxStorage = new Mock <IClientOutboxStorage>(); ClientOutboxStorageV2 = new Mock <IClientOutboxStorageV2>(); Settings = new Mock <ReadOnlySettings>(); CriticalError = new Mock <CriticalError>(null); Frequency = TimeSpan.Zero; MaxAge = TimeSpan.FromDays(14); Exception = new Exception(); TimerService.Setup(t => t.Start(It.IsAny <Func <DateTime, CancellationToken, Task> >(), It.IsAny <Action <Exception> >(), Frequency)) .Callback <Func <DateTime, CancellationToken, Task>, Action <Exception>, TimeSpan>((s, e, f) => { TimerServiceSuccessCallback = s; TimerServiceErrorCallback = e; }); ClientOutboxStorage.Setup(o => o.GetAwaitingDispatchAsync()).ReturnsAsync(ClientOutboxMessages); ClientOutboxStorageV2.Setup(o => o.GetAwaitingDispatchAsync()).ReturnsAsync(ClientOutboxMessageV2s); Settings.Setup(s => s.GetOrDefault <TimeSpan?>("Persistence.Sql.Outbox.FrequencyToRunDeduplicationDataCleanup")).Returns(Frequency); Settings.Setup(s => s.GetOrDefault <TimeSpan?>("Persistence.Sql.Outbox.TimeToKeepDeduplicationData")).Returns(MaxAge); Cleaner = new TestableClientOutboxCleaner(TimerService.Object, ClientOutboxStorage.Object, ClientOutboxStorageV2.Object, Settings.Object, CriticalError.Object); }
public async Task OnlyPublishesOnceForSecondGameweekWhenFirstGameweekIsCurrent() { var fakeSettingsClient = A.Fake <IGlobalSettingsClient>(); var gameweek1 = new Gameweek { IsCurrent = true, IsNext = false, Deadline = new DateTime(2021, 8, 15, 10, 0, 0) }; var gameweek2 = new Gameweek { IsCurrent = false, IsNext = true, Deadline = new DateTime(2021, 8, 22, 10, 0, 0) }; var globalSettings = new GlobalSettings { Gameweeks = new List <Gameweek> { gameweek1, gameweek2 } }; A.CallTo(() => fakeSettingsClient.GetGlobalSettings()).Returns(globalSettings); var session = new TestableMessageSession(); var dontCareLogger = A.Fake <ILogger <NearDeadLineMonitor> >(); var dateTimeUtils = new DateTimeUtils { NowUtcOverride = new DateTime(2021, 8, 21, 10, 0, 0) }; var handler = new NearDeadLineMonitor(fakeSettingsClient, dateTimeUtils, session, dontCareLogger); await handler.EveryMinuteTick(); Assert.Single(session.PublishedMessages); Assert.IsType <TwentyFourHoursToDeadline>(session.PublishedMessages[0].Message); }
public UnitOfWorkManagerTestsFixture() { Db = new Mock <IDb>(); MessageSession = new TestableMessageSession(); UnitOfWorkContext = new Mock <IUnitOfWorkContext>(); Outbox = new Mock <IOutbox>(); Settings = new Mock <ReadOnlySettings>(); OutboxTransaction = new Mock <IOutboxTransaction>(); EndpointName = "SFA.DAS.NServiceBus"; Events = new List <Event> { new FooEvent(), new BarEvent() }; Outbox.Setup(o => o.BeginTransactionAsync()).ReturnsAsync(OutboxTransaction.Object); Outbox.Setup(o => o.StoreAsync(It.IsAny <OutboxMessage>(), It.IsAny <IOutboxTransaction>())) .Returns(Task.CompletedTask).Callback <OutboxMessage, IOutboxTransaction>((m, t) => OutboxMessage = m); Settings.Setup(s => s.Get <string>("NServiceBus.Routing.EndpointName")).Returns(EndpointName); UnitOfWorkManager = new UnitOfWorkManager( Db.Object, MessageSession, UnitOfWorkContext.Object, Outbox.Object, Settings.Object); }
private LineupState CreateFixture2RemovedScenario() { var fixtureClient = A.Fake <IFixtureClient>(); A.CallTo(() => fixtureClient.GetFixturesByGameweek(1)).Returns(new List <Fixture> { TestBuilder.NoGoals(1), TestBuilder.NoGoals(2) }).Once().Then.Returns(new List <Fixture>() { TestBuilder.NoGoals(1) }); var scraperFake = A.Fake <IGetMatchDetails>(); _session = new TestableMessageSession(); var globalSettingsClient = A.Fake <IGlobalSettingsClient>(); A.CallTo(() => globalSettingsClient.GetGlobalSettings()).Returns(new GlobalSettings { Teams = new List <Team> { TestBuilder.HomeTeam(), TestBuilder.AwayTeam() }, Players = new List <Player> { TestBuilder.Player().WithStatus(PlayerStatuses.Available) } } ); return(new LineupState(fixtureClient, scraperFake, globalSettingsClient, _session, A.Fake <ILogger <LineupState> >())); }
public async Task OnNoChanges_CallsNothing() { var gameweekClient = A.Fake <IGlobalSettingsClient>(); A.CallTo(() => gameweekClient.GetGlobalSettings()).Returns(GameweeksWithCurrentNowMarkedAsFinished()); var mediator = A.Fake <IMediator>(); var session = new TestableMessageSession(); var action = new GameweekLifecycleMonitor(gameweekClient, A.Fake <ILogger <GameweekLifecycleMonitor> >(), mediator, session); await action.EveryOtherMinuteTick(CancellationToken.None); A.CallTo(() => mediator.Publish(A <GameweekMonitoringStarted> .That.Matches(a => a.CurrentGameweek.Id == 2), CancellationToken.None)).MustHaveHappenedOnceExactly(); A.CallTo(() => mediator.Publish(A <GameweekJustBegan> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); A.CallTo(() => mediator.Publish(A <GameweekCurrentlyOnGoing> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); A.CallTo(() => mediator.Publish(A <GameweekFinished> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); await action.EveryOtherMinuteTick(CancellationToken.None); A.CallTo(() => mediator.Publish(A <GameweekJustBegan> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); A.CallTo(() => mediator.Publish(A <GameweekCurrentlyOnGoing> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); A.CallTo(() => mediator.Publish(A <GameweekFinished> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); await action.EveryOtherMinuteTick(CancellationToken.None); A.CallTo(() => mediator.Publish(A <GameweekJustBegan> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); A.CallTo(() => mediator.Publish(A <GameweekCurrentlyOnGoing> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); A.CallTo(() => mediator.Publish(A <GameweekFinished> ._, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); }
public FileWatcherFixture() { MessageSession = new TestableMessageSession(); TestFileDetails = GetTestFileData(); var fileDetailsProvider = Mock.Of <IProvideFileDetails>(details => details.GetFileInfo(It.IsAny <string>()) == TestFileDetails); SystemUnderTest = new FileHandler(MessageSession, fileDetailsProvider); }
public AggregateNameControllerTests() { var messageSession = new TestableMessageSession(); getAllAggregateNamesQueryMock = new Mock <IGetAllAggregateNamesQuery>(); getAggregateNameByIdQueryMock = new Mock <IGetAggregateNameByIdQuery>(); sut = new AggregateNameController(messageSession, getAllAggregateNamesQueryMock.Object, getAggregateNameByIdQueryMock.Object); }
public void TestSetup() { _eventsApiClientConfiguration = new Mock <IEventsSettings>(MockBehavior.Strict); _log = new Mock <ILog>(); _messageSession = new TestableMessageSession(); _eventsApiClientConfiguration.Setup(s => s.ApiEnabled).Returns(false); _sut = new EventsApiService(_eventsApiClientConfiguration.Object, _log.Object, _messageSession); }
public ProcessOutboxMessagesJobTestsFixture() { Session = new TestableMessageSession(); OutboxMessages = new List <IOutboxMessageAwaitingDispatch>(); Outbox = new Mock <IOutbox>(); Outbox.Setup(o => o.GetAwaitingDispatchAsync()).ReturnsAsync(OutboxMessages); Job = new ProcessOutboxMessagesJob(Session, Outbox.Object); }
public void Subscribe_ShouldTrackSubscriptions() { var session = new TestableMessageSession(); var options = new SubscribeOptions(); session.Subscribe(typeof(MyEvent), options); Assert.AreEqual(1, session.Subscriptions.Length); Assert.AreSame(options, session.Subscriptions[0].Options); Assert.AreEqual(typeof(MyEvent), session.Subscriptions[0].Message); }
public async Task ShouldLogCorrectly() { var testableSession = new TestableMessageSession(); var somethingThatUsesTheMessageSession = new SomethingThatUsesTheMessageSession(testableSession); await somethingThatUsesTheMessageSession.DoSomething(); Assert.AreEqual(1, testableSession.SentMessages.Length); Assert.IsInstanceOf <MyResponse>(testableSession.SentMessages[0].Message); }
public async System.Threading.Tasks.Task Subscribe_ShouldTrackSubscriptionsAsync() { var session = new TestableMessageSession(); var options = new SubscribeOptions(); await session.Subscribe(typeof(MyEvent), options); Assert.AreEqual(1, session.Subscriptions.Length); Assert.AreSame(options, session.Subscriptions[0].Options); Assert.AreEqual(typeof(MyEvent), session.Subscriptions[0].Message); }
public UnitOfWorkTestsFixture() { ClientOutboxStorage = new Mock <IClientOutboxStorageV2>(); MessageSession = new TestableMessageSession(); UnitOfWorkContext = new Mock <IUnitOfWorkContext>(); Settings = new Mock <ReadOnlySettings>(); ClientOutboxTransaction = new Mock <IClientOutboxTransaction>(); EndpointName = "SFA.DAS.NServiceBus"; NextTask = new Mock <Func <Task> >(); Events = new List <object> { new FooEvent(DateTime.UtcNow), new BarEvent(DateTime.UtcNow) }; Commands = new List <object> { new TestCommand(DateTime.UtcNow), new AnotherCommand(DateTime.UtcNow), new TestCommand(DateTime.UtcNow) }; UnitOfWorkContext.Setup(c => c.Get <IClientOutboxTransaction>()).Returns(ClientOutboxTransaction.Object); Settings.Setup(s => s.Get <string>("NServiceBus.Routing.EndpointName")).Returns(EndpointName); ClientOutboxStorage.Setup(o => o.StoreAsync(It.IsAny <ClientOutboxMessageV2>(), It.IsAny <IClientOutboxTransaction>())) .Returns(Task.CompletedTask).Callback <ClientOutboxMessageV2, IClientOutboxTransaction>((m, t) => { if (NextTaskInvoked) { throw new Exception("StoreAsync called too late"); } ClientOutboxMessage = m; }); NextTask.Setup(n => n()).Returns(Task.CompletedTask).Callback(() => { if (MessageSession.PublishedMessages.Any()) { throw new Exception("Publish called too early"); } NextTaskInvoked = true; }); UnitOfWork = new NServiceBus.Features.ClientOutbox.Pipeline.UnitOfWork( ClientOutboxStorage.Object, MessageSession, UnitOfWorkContext.Object, Settings.Object); }
private static State CreateBaseScenario(IFixtureClient fixtureClient, IGlobalSettingsClient settingsClient) { var slackTeamRepository = A.Fake <ISlackTeamRepository>(); A.CallTo(() => slackTeamRepository.GetAllTeams()).Returns(new List <SlackTeam> { TestBuilder.SlackTeam() }); _messageSession = new TestableMessageSession(); return(new State(fixtureClient, settingsClient, _messageSession, A.Fake <ILogger <State> >())); }
public async Task Shares_state_with_message_session() { var messageSession = new TestableMessageSession(); var uniformSession = new TestableUniformSession(messageSession); var component = new MessageSessionComponent(uniformSession); await component.DoSomething(messageSession); Assert.AreEqual(2, uniformSession.PublishedMessages.Length); Assert.AreEqual(2, uniformSession.SentMessages.Length); Assert.AreEqual(2, messageSession.PublishedMessages.Length); Assert.AreEqual(2, messageSession.SentMessages.Length); }
public ProcessLevyDeclarationsJobTestsFixture() { Now = DateTime.UtcNow; Today = Now.Date; Month = new DateTime(Today.Year, Today.Month, 6, 0, 0, 0, 0, DateTimeKind.Utc); PayrollPeriod = Month.AddMonths(-1); MessageSession = new TestableMessageSession(); DateTimeService = new Mock <IDateTimeService>(); Logger = new Mock <ILogger>(); DateTimeService.Setup(s => s.UtcNow).Returns(Now); Job = new ProcessLevyDeclarationsJob(MessageSession, DateTimeService.Object); }
public BillingPaymentMediatorTests() { _mapper = new MapperConfiguration(mc => { mc.AddProfile(new AccountAutomapper()); }).CreateMapper(); _mockBillingPaymentProvider = new Mock <IBillingPaymentProvider>(); _testableMessageSession = new TestableMessageSession(); _billingPaymentMediator = new BillingPaymentMediator( _testableMessageSession, _mockBillingPaymentProvider.Object, _mapper); }
public async Task MessageSession() { var context = new TestableMessageSession(); var subscribeOptions = new SubscribeOptions(); subscribeOptions.RequireImmediateDispatch(); await context.Subscribe(typeof(MyMessage), subscribeOptions); var unsubscribeOptions = new UnsubscribeOptions(); unsubscribeOptions.RequireImmediateDispatch(); await context.Unsubscribe(typeof(MyMessage), unsubscribeOptions); await Verify(context); }
public async Task OnFirstProcess_NoCurrentGameweek_OrchestratesNothing() { var gameweekClient = A.Fake <IGlobalSettingsClient>(); A.CallTo(() => gameweekClient.GetGlobalSettings()).Returns(GlobalSettingsWithGameweeks(new List <Gameweek>())); var mediator = A.Fake <IMediator>(); var session = new TestableMessageSession(); var action = new GameweekLifecycleMonitor(gameweekClient, A.Fake <ILogger <GameweekLifecycleMonitor> >(), mediator, session); await action.EveryOtherMinuteTick(CancellationToken.None); A.CallTo(() => mediator.Publish(null, CancellationToken.None)).WithAnyArguments().MustNotHaveHappened(); Assert.Empty(session.PublishedMessages); }
public async Task OnFirstProcess_OrchestratesInitializeAndGameweekOngoing() { var gameweekClient = A.Fake <IGlobalSettingsClient>(); A.CallTo(() => gameweekClient.GetGlobalSettings()).Returns(GlobalSettingsWithGameweeks(SomeGameweeks())); var mediator = A.Fake <IMediator>(); var session = new TestableMessageSession(); var action = new GameweekLifecycleMonitor(gameweekClient, A.Fake <ILogger <GameweekLifecycleMonitor> >(), mediator, session); await action.EveryOtherMinuteTick(CancellationToken.None); A.CallTo(() => mediator.Publish(A <GameweekMonitoringStarted> .That.Matches(a => a.CurrentGameweek.Id == 2), CancellationToken.None)).MustHaveHappenedOnceExactly(); A.CallTo(() => mediator.Publish(A <GameweekCurrentlyOnGoing> .That.Matches(a => a.Gameweek.Id == 2), CancellationToken.None)).MustHaveHappenedOnceExactly(); }
public async Task Should_send_to_first_destination() { var bus = new TestableMessageSession(); var message = new DummyMessage(); await((IMessageSession)bus).Route(message, Guid.NewGuid(), "foo"); bus.SentMessages.Length.ShouldBe(1); var sentMessage = bus.SentMessages[0]; sentMessage.Options.GetHeaders()[Router.RoutingSlipHeaderKey].ShouldNotBeNull(); sentMessage.Options.GetDestination().ShouldBe("foo"); sentMessage.Message.ShouldBe(message); }
public async Task CustomizationSession() { var testableMessageSession = new TestableMessageSession(); var someCodeUsingTheSession = new SomeCodeUsingTheSession(testableMessageSession); await someCodeUsingTheSession.Execute(); var publishedMessage = testableMessageSession.PublishedMessages.Single(); var customization = publishedMessage.Options.GetNativeMessageCustomization(); var nativeMessage = new Message(); customization(nativeMessage); Assert.AreEqual("abc", nativeMessage.Label); }
private LineupState CreateNewLineupScenario() { var fixtureClient = A.Fake <IFixtureClient>(); var testFixture1 = TestBuilder.NoGoals(1).NotStarted(); var testFixture2 = TestBuilder.NoGoals(2).NotStarted(); A.CallTo(() => fixtureClient.GetFixturesByGameweek(1)).Returns(new List <Fixture> { testFixture1, testFixture2 }); var scraperFake = A.Fake <IGetMatchDetails>(); A.CallTo(() => scraperFake.GetMatchDetails(testFixture1.PulseId)).Returns(TestBuilder.NoLineup(testFixture1.PulseId)); A.CallTo(() => scraperFake.GetMatchDetails(testFixture2.PulseId)).Returns(TestBuilder.NoLineup(testFixture2.PulseId)).Once().Then.Returns(TestBuilder.Lineup(testFixture2.PulseId)); _session = new TestableMessageSession(); return(new LineupState(fixtureClient, scraperFake, A.Fake <IGlobalSettingsClient>(), _session, A.Fake <ILogger <LineupState> >())); }
public async Task OnGameweekTransition_CallsOrchestratorBegin() { var gameweekClient = A.Fake <IGlobalSettingsClient>(); A.CallTo(() => gameweekClient.GetGlobalSettings()) .Returns(GameweeksBeforeTransition()).Once() .Then.Returns(GameweeksAfterTransition()); var mediator = A.Fake <IMediator>(); var session = new TestableMessageSession(); var action = new GameweekLifecycleMonitor(gameweekClient, A.Fake <ILogger <GameweekLifecycleMonitor> >(), mediator, session); await action.EveryOtherMinuteTick(CancellationToken.None); A.CallTo(() => mediator.Publish(A <GameweekMonitoringStarted> .That.Matches(a => a.CurrentGameweek.Id == 2), CancellationToken.None)).MustHaveHappenedOnceExactly(); A.CallTo(() => mediator.Publish(A <GameweekCurrentlyOnGoing> .That.Matches(a => a.Gameweek.Id == 2), CancellationToken.None)).MustHaveHappenedOnceExactly(); await action.EveryOtherMinuteTick(CancellationToken.None); A.CallTo(() => mediator.Publish(A <GameweekJustBegan> .That.Matches(a => a.Gameweek.Id == 3), CancellationToken.None)).MustHaveHappenedOnceExactly(); Assert.Single(session.PublishedMessages); Assert.IsType <Messaging.Contracts.Events.v1.GameweekJustBegan>(session.PublishedMessages[0].Message); }
public IServiceProvider ConfigureServices(IServiceCollection services) { var serviceFabricHostMarker = Environment.GetEnvironmentVariable("ServiceFabricHostMarker"); if (this.CurrentEnvironment.EnvironmentName == "IntegrationTest") { var context = this.CreateInMemoryDbContextBuilder(); services.AddSingleton(context); IntegrationSeed.Execute(context); } else { services.AddDbContext <RegistrationDbContext>( options => options.UseSqlServer(this.Configuration.GetConnectionString("RegistrationDbContext"))); } services.AddSingleton(res => this.Configuration); services.AddScoped <DbContext, RegistrationDbContext>(); services.AddScoped <IEventService, EventService>(); services.AddScoped <IRegistrationService, RegistrationService>(); services.AddCors(); services.AddMvc(); services.AddEventManagementAuthentication( new DefaultEventManagementTokenValidationParameters(this.Configuration)); var builder = new ContainerBuilder(); builder.Populate(services); // Add NServiceBus Handlers EndpointConfiguration endpointConfiguration = null; if (!this.CurrentEnvironment.IsEnvironment("IntegrationTest")) { endpointConfiguration = EndpointConfigurationFactory.ConfigureEndpoint(RegistrationEndpoint.Name, true) .ConfigureSqlPersistence( this.Configuration.GetConnectionString("RegistrationDbContext"), 1, this.CurrentEnvironment.IsDevelopment() && serviceFabricHostMarker == null).ConfigureSqlTransport( this.Configuration.GetConnectionString("TransportDbContext"), (routing) => { routing.RegisterPublisher(typeof(AddEvent), ResouresEndpoint.Name); routing.RegisterPublisher(typeof(DeleteEvent), ResouresEndpoint.Name); routing.RegisterPublisher(typeof(CompletePayment), PaymentEndpoint.Name); routing.RegisterPublisher(typeof(CancelPayment), PaymentEndpoint.Name); }); endpointConfiguration.LicensePath("License.xml"); } builder.Register(x => MessageSession).As <IMessageSession>(); // Build container this.applicationContainer = builder.Build(); // Add NServiceBus if (!this.CurrentEnvironment.IsEnvironment("IntegrationTest")) { endpointConfiguration.UseContainer <AutofacBuilder>( customizations => { customizations.ExistingLifetimeScope(this.applicationContainer); }); MessageSession = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult(); } else { MessageSession = new TestableMessageSession(); } var result = new AutofacServiceProvider(this.applicationContainer); ServiceProvider = result; return(result); }
public TestableUniformSession(TestableMessageSession innerSession) { this.innerSession = innerSession; }
private static State CreateAllMockState() { _messageSession = new TestableMessageSession(); return(new State(A.Fake <IFixtureClient>(), A.Fake <IGlobalSettingsClient>(), _messageSession, A.Fake <ILogger <State> >())); }
public WebHookNotificationMediatorTests() { _mockWebHookNotificationProvider = new Mock <IWebHookNotificationProvider>(); _testableMessageSession = new TestableMessageSession(); _webHookNotificationMediator = new WebHookNotificationMediator(_mockWebHookNotificationProvider.Object, _testableMessageSession); }