public async Task ShouldGetCategory() { // Arrange var listCategoriesCommand = new ListCategoriesCommand(1, WorkContext.WorkingLanguageId, true); var categoryId = (await _listCategoriesQuery.Query(listCategoriesCommand)).Items .FirstOrDefault(o => o.Route.AngularComponent.Code == AngularComponents.ProductCategoryComponent).Id; var getCategoryCommand = new GetCategoryCommand(7, WorkContext.WorkingLanguageId); var listProductsByCategoryCommand = new ListProductsByCategoryCommand(7, WorkContext.WorkingLanguageId, pageIndex: 1, pageSize: 24); // Act var categoryDto = (await _getCategoryQueryHandler.Handle(getCategoryCommand)).Object; var productsDto = (await _listProductsByCategoryQueryHandler.Handle(listProductsByCategoryCommand)); // Assert Assert.IsNotNull(categoryDto); Assert.IsNotNull(productsDto); }
public async Task Get_Category() { using (var context = GetContextWithData()) { var handler = new GetCategoryQueryHandler(context); var category = context.Categories.First(); var result = await handler.Handle(new GetCategoryQuery { Id = category.Id }, CancellationToken.None); Assert.IsType <GetCategoryModel>(result); Assert.Equal(result.Id, category.Id); Assert.Equal(result.Name, category.Name); } }
public async Task GetCategoryHandler_Returns_Category() { var category = await GetRandomCategory(); var message = new GetCategoryQuery() { Id = category.Id }; var handlerContext = TestContext.CreateHandlerContext <CategoryViewModel>(RequestDbContext); var handler = new GetCategoryQueryHandler(handlerContext); var result = await handler.Handle(message, CancellationToken.None); Assert.Equal(category.Id, result.Payload.Id); }
public async Task Category_GetQuery_Success() { //Arrange GetCategoryQuery query = new GetCategoryQuery(); _categoryRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <Category, bool> > >())) .ReturnsAsync(new Category() //propertyler buraya yazılacak //{ //CategoryId = 1, //CategoryName = "Test" //} ); GetCategoryQueryHandler handler = new GetCategoryQueryHandler(_categoryRepository.Object, _mediator.Object); //Act var x = await handler.Handle(query, new System.Threading.CancellationToken()); //Asset Assert.That(x.Success, Is.True); //Assert.That(x.Data.CategoryId, Is.EqualTo(1)); }