测试案例完成

This commit is contained in:
编码猿
2025-09-17 01:52:10 +08:00
parent 61c84b0842
commit 858018e43d
19 changed files with 431 additions and 22 deletions

View File

@@ -8,7 +8,8 @@ export default defineComponent({
<>
<div id="nav">
<RouterLink to="/"></RouterLink> |
<RouterLink to="/about"></RouterLink>
<RouterLink to="/about"></RouterLink> |
<RouterLink to="/Products"></RouterLink>
</div>
<RouterView></RouterView>
</>

View File

@@ -0,0 +1,38 @@
import { ProductApplicationService } from "../../domains/product/application/services/ProductApplicationService";
import { HttpProductRepository } from "../../domains/product/infr/api/HttpProductRepository";
import { ProductRepository } from "../../domains/product/ports/repositories/ProductRepository";
/**
* 商品领域的依赖注入配置
* 将 接口 与 具体实现 绑定
*
* 优点:是一个依赖工厂,它隐藏了对象创建的细节,
* 让业务代码只需要关心 “做什么”,而不用关心 “依赖从哪里来”
* 所有依赖关系都在di目录下集中配置一目了然后续维护时能快速找到所有依赖的创建逻辑。
*
* 松耦合:
* 业务代码ProductApplicationService只依赖抽象接口ProductRepository
* 不依赖具体实现。如果未来需要改用其他数据来源(比如 WebSocket
* 只需修改bindProductRepository的返回值无需改动业务逻辑。
*
* 易于测试:
* 测试时可以临时替换为模拟实现
* productModule.bindProductRepository = () => new MockProductRepository();
* 这样测试就可以脱离真实 API使用预设的模拟数据。
*/
export const productModule = {
// 绑定 仓储抽象接口 到 HTTP具体实现
bindProductRepository: (): ProductRepository => {
// return new MockProductRepository 直接从真实接口数据改为测试模拟数据
return new HttpProductRepository;
},
// 创建应用服务实例
createProductApplicationService: (): ProductApplicationService => {
return new ProductApplicationService(
productModule.bindProductRepository()
);
}
}

View File

@@ -1,24 +1,30 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { productRouter } from '@features/product/router'
const baseRouter: Array<RouteRecordRaw> = [
{
path: '/',
name: 'home',
component: () => import('../views/Home'),
},
{
path: '/about',
name: 'about',
component: () => import('../views/About'),
},
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('../views/NotFound')
}
];
// 聚合所有功能模块的路由
const routes: RouteRecordRaw[] = [...baseRouter, ...productRouter];
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: () => import('../views/Home'),
},
{
path: '/about',
name: 'about',
component: () => import('../views/About'),
},
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('../views/NotFound')
}
],
routes,
})
export default router