コード例 #1
0
            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);
            }
コード例 #2
0
        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;
        }
コード例 #3
0
        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));
        }
コード例 #4
0
 public Notification GetExamples()
 {
     return FakeNotification.GetFake_master();
 }
コード例 #5
0
 public List<Notification> GetExamples()
 {
     return FakeNotification.GetFake_List();
 }
コード例 #6
0
 public Notification GetExamples()
 {
     return(FakeNotification.GetFake_Master());
 }