How to do BDD using CQRS?

I test my apps using BDD - approach. So far it was simple, because I had one facade and one repository per module. Unit tests of my module (facade) looked like:

In test:

private TaskForm createSimpleTask() {

return new TaskForm("Task1", "Text1");

}

// given

TaskForm form = createSimpleTask();

// when

TaskDto savedTask = taskFacade.save(form);

// then

TaskWithUserDto loadedTask = taskFacade.load(savedTask.getId());

assertNonNull(loadedTask);

assertEquals(loadedTask.getTitle(), "Task1");

assertEquals(loadedTask.getText(), "Text1");

assertEquas(loadedTask.getAuthor(), "Michal");

In taskFacade:

TaskDto save(TaskForm form) {

UserDto currentUser = userFacade.getLoggedUser();

Task task = taskFactory.create(form, currentUser.getId());

return taskRepo.save(task).dto();

}

TaskWithUserDto load(long taskId) {

Task task = taskRepo.findById(taskId);

UserDto user = userFacade.load(task.getUserId());

return new TaskWithUserDto(task.getTitle(), task.getText(), user.getName());

}

I've started using CQRS now and I don't know how to test it....

Read More »

By: StackOverFlow - 5 days ago

Related Posts