public async Task <List <FlashcardModel> > Handle(GetFlashcardsListQ request, CancellationToken cancellationToken) { var getCollectionById = new GetCollectionByIdWithDailyStatsQ(request.CollectionId, request.UserId); var collection = await _mediator.Send(getCollectionById); if (collection == null) { return(new List <FlashcardModel>()); } return(await _flashcardRepo.GetWhereCollectionId(request.CollectionId)); }
public async Task <IActionResult> GetFlashcards(Guid collectionId) { var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (String.IsNullOrEmpty(userId)) { return(NotFound()); } var getFlashcardsListCommand = new GetFlashcardsListQ(collectionId, userId); var actionResponse = await _mediator.Send(getFlashcardsListCommand); return(Ok(_mapper.Map <List <FlashcardGetModel> >(actionResponse))); }
public async Task TestB_UserNotOwnCollection() { 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 getFlashcardsListQ = new GetFlashcardsListQ(Guid.Parse("82c3a0d1-a73c-41e2-a8f3-ef525e5f0ffa"), "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4"); var flashcardsList = await mediator.Send(getFlashcardsListQ); Assert.Empty(flashcardsList); }
public async Task TestB_CollectionNotExists() { 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 getFlashcardsListQ = new GetFlashcardsListQ(Guid.Parse("00008f79-291b-4532-8f22-b693e61d6bb5"), "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4"); var flashcardsList = await mediator.Send(getFlashcardsListQ); Assert.Empty(flashcardsList); }