Beispiel #1
0
        public async Task TestC_UserNotOwnFlashcard()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

            var serviceProvider = new ServiceCollection()
                                  .AddTransient <ICollectionRepo, CollectionRepo>()
                                  .AddTransient <IFlashcardRepo, FlashcardRepo>()
                                  .AddDbContext <AppDbContext>(options => options.UseSqlServer(MockDatabaseFactory.DbMockConnectionString))
                                  .AddMediatR(typeof(MediatREntryPoint).Assembly)
                                  .BuildServiceProvider();

            var mediator = serviceProvider.GetService <IMediator>();

            var deleteFlashcardC = new DeleteFlashcardC(Guid.Parse("6aa83ba0-1396-428f-adb7-d7ab972459eb"), "fcabcb46-12dc-4013-bc92-6f00aae903b4");

            var actionResult = await mediator.Send(deleteFlashcardC);

            Assert.False(actionResult.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(2, await db.Flashcards.CountAsync());
            }
        }
Beispiel #2
0
        public async Task TestB_FlashcardNotExists()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

            var serviceProvider = new ServiceCollection()
                                  .AddTransient <ICollectionRepo, CollectionRepo>()
                                  .AddTransient <IFlashcardRepo, FlashcardRepo>()
                                  .AddDbContext <AppDbContext>(options => options.UseSqlServer(MockDatabaseFactory.DbMockConnectionString))
                                  .AddMediatR(typeof(MediatREntryPoint).Assembly)
                                  .BuildServiceProvider();

            var mediator = serviceProvider.GetService <IMediator>();

            var deleteFlashcardC = new DeleteFlashcardC(Guid.Parse("00003ba0-1396-428f-adb7-d7ab972459eb"), "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4");

            var actionResult = await mediator.Send(deleteFlashcardC);

            Assert.False(actionResult.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(2, await db.Flashcards.CountAsync());
            }
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteFlashcard(Guid flashcardId)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (String.IsNullOrEmpty(userId))
            {
                return(NotFound());
            }

            var deleteFlashcardC = new DeleteFlashcardC(flashcardId, userId);

            var actionResponse = await _mediator.Send(deleteFlashcardC);

            if (actionResponse.IsSucceed)
            {
                return(Ok());
            }

            return(BadRequest(actionResponse.Message));
        }