public async Task GetCategoryByIdQueryHandler_WhenCalled_ReturnGetCategoryByIdLookupModel() { var returnModel = new GetCategoryByIdLookupModel { CategoryId = 1, Name = "Category1" }; _categoryServiceMock .Setup(x => x.GetCategoryByIdAsync(It.IsAny <int>(), CancellationToken.None)) .ReturnsAsync(returnModel); var query = new GetCategoryByIdQuery { CategoryId = 1 }; var container = Registrations(); await using var scope = container.BeginLifetimeScope(); var options = scope.Resolve <DbContextOptions <TechnicalTestDbContext> >(); await using var context = new TechnicalTestDbContext(options); await SeedMockDataAsync(context); var handler = new GetCategoryByIdQueryHandler(_categoryServiceMock.Object); var result = await handler.Handle(query, CancellationToken.None); Assert.AreEqual("Category1", result.Name); }
public async Task GetCategoryByExistedIdTest() { var handler = new GetCategoryByIdQueryHandler(_context, _mapper); var result = await handler.Handle(new GetCategoryByIdQuery { Id = 1 }, CancellationToken.None); result.Id.ShouldBe(1); result.Name.ShouldBe("RPG"); result.ShouldBeOfType <CategoryViewModel>(); }
public async Task GetCategoryByNonExistedIdTest() { var handler = new GetCategoryByIdQueryHandler(_context, _mapper); await Assert.ThrowsAsync <NotFoundException>(async() => await handler.Handle(new GetCategoryByIdQuery { Id = 100 }, CancellationToken.None) ); }
public async Task GetCategoryByIdQueryTestAsync(int categoryId, int?result) { GetCategoryByIdQuery request = new GetCategoryByIdQuery { CategoryId = categoryId, }; GetCategoryByIdQueryHandler handler = new GetCategoryByIdQueryHandler(_fixture.Context); var expectedResult = await handler.Handle(request, new CancellationToken()); Assert.Equal(expectedResult?.Id, result); }