Exemple #1
0
        public async Task ShouldHandleRemoveTagCommandRequest()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "ShouldHandleRemoveTagCommandRequest")
                          .Options;

            var mediator = new Mock <IMediator>();

            mediator.Setup(m => m.Publish(It.IsAny <TagRemovedEvent.DomainEvent>(), It.IsAny <CancellationToken>()))
            .Verifiable();

            using (var context = new AppDbContext(options, mediator.Object))
            {
                context.Tags.Add(new Tag()
                {
                    TagId = 1,
                    Name  = "Quinntyne",
                });

                context.SaveChanges();

                var handler = new RemoveTagCommand.Handler(context);

                await handler.Handle(new RemoveTagCommand.Request()
                {
                    TagId = 1
                }, default(CancellationToken));

                Assert.Equal(0, context.Tags.Count());
            }
        }
        public async Task ShouldHandleRemoveTagCommandRequest()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "ShouldHandleRemoveTagCommandRequest")
                          .Options;

            using (var context = new AppDbContext(options))
            {
                context.Tags.Add(new Tag()
                {
                    TagId = 1,
                    Name  = "Quinntyne",
                });

                context.SaveChanges();

                var handler = new RemoveTagCommand.Handler(context);

                await handler.Handle(new RemoveTagCommand.Request()
                {
                    TagId = 1
                }, default(CancellationToken));

                Assert.Equal(0, context.Tags.Count());
            }
        }