Ejemplo n.º 1
0
        public async Task TestC_UserNotOwnCollection()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

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

            var inputModel = new FlashcardInsertModel()
            {
                CollectionId = Guid.Parse("82c3a0d1-a73c-41e2-a8f3-ef525e5f0ffa"),
                Foreign      = "Foreign ok",
                Native       = "Native ok"
            };

            var insertFlashcardC = new InsertFlashcardC(inputModel, "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4");

            var actionResult = await service.Send(insertFlashcardC, new System.Threading.CancellationToken());

            Assert.False(actionResult.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(2, await db.Flashcards.CountAsync());
                Assert.Equal(4, await db.FlashcardProgresses.CountAsync());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> InsertFlashcard([FromBody] FlashcardInsertModel flashcard)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

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

            var insertFlashcardCommand = new InsertFlashcardC(flashcard, userId);

            var actionReponse = await _mediator.Send(insertFlashcardCommand);

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

            return(BadRequest(actionReponse.Message));
        }