public async Task ShouldSucceed() { var services = new ServiceCollection(); _ = services.AddScoped <ILoggerFactory>(_ => this.Log); _ = services.AddLogging(); var databaseName = Guid.NewGuid().ToString(); _ = services.AddTransient(_ => new DbContextOptionsBuilder <FakeDbContext>() .UseInMemoryDatabase(databaseName: databaseName) .Options); MediatrHelpers.RegisterMediatrWithExplicitTypes( services, null, new MediatRServiceConfiguration(), new FakeMediatrRegistration()); var serviceProvider = services.BuildServiceProvider(); var dbContextOptions = serviceProvider.GetService <DbContextOptions <FakeDbContext> >(); using (var dbContext = new FakeDbContext(dbContextOptions !)) { var entityCount = dbContext.FakeAddAudit.Count(); Assert.Equal(0, entityCount); entityCount = dbContext.FakeAddPreProcessAudit.Count(); Assert.Equal(0, entityCount); entityCount = dbContext.FakeAddPostProcessAudit.Count(); Assert.Equal(0, entityCount); } var mediator = serviceProvider.GetService <IMediator>(); const int expected = 987654321; var request = new FakeCrudAddCommand(expected, ClaimsPrincipal.Current !); var sendResult = await mediator !.Send(request).ConfigureAwait(false); Assert.Equal(expected, sendResult); using (var dbContext = new FakeDbContext(dbContextOptions !)) { var entityCount = dbContext.FakeAddAudit.Count(); Assert.Equal(1, entityCount); entityCount = dbContext.FakeAddPreProcessAudit.Count(); Assert.Equal(1, entityCount); entityCount = dbContext.FakeAddPostProcessAudit.Count(); Assert.Equal(1, entityCount); } var notification = new FakeNotification(); await mediator.Publish(notification) .ConfigureAwait(false); }
public void CreateNotification(int eventId, int before, int timeUnitId) { var notification = new FakeNotification { EventId = eventId, Before = before, TimeUnit = (Business.Models.NotifyTimeUnit)Enum.ToObject(typeof(Business.Models.NotifyTimeUnit), timeUnitId), }; var fakeEvent = FakeRepository.Get.Events.SingleOrDefault(e => e.Id.Equals(eventId)); fakeEvent.Notification = notification; }
public async Task Publish_Always_ExecutesAllNotificationHandlers() { var serviceProvider = new ServiceCollection() .AddTransient <INotificationHandler <FakeNotification>, FakeNotificationHandler1>() .AddTransient <INotificationHandler <FakeNotification>, FakeNotificationHandler2>() .BuildServiceProvider(); var mediator = new ParallelMediator(t => serviceProvider.GetService(t)); var notification = new FakeNotification(); await mediator.Publish(notification); notification.TriggeredHandlers.Should().BeEquivalentTo(typeof(FakeNotificationHandler1), typeof(FakeNotificationHandler2)); }
public Notification GetExamples() { return FakeNotification.GetFake_master(); }
public List<Notification> GetExamples() { return FakeNotification.GetFake_List(); }
public Notification GetExamples() { return(FakeNotification.GetFake_Master()); }