Browse Source

Lets get some tests

main
Julio Biason 3 years ago
parent
commit
d858191fe3
  1. 1214
      Cargo.lock
  2. 9
      lib/src/domain/command.rs
  3. 28
      lib/src/domain/project/create_project.rs

1214
Cargo.lock generated

File diff suppressed because it is too large Load Diff

9
lib/src/domain/command.rs

@ -16,6 +16,13 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/// Trait that all commands must implement.
pub trait Command {
fn execute(&self) -> Result<(), ()>;
fn execute(&self) -> Result<(), CommandError>;
}
/// Errors produced by invalid commands
pub enum CommandError {
/// The request identified used in the command is already used.
IdentifierAlreadyUsed(String),
}

28
lib/src/domain/project/create_project.rs

@ -17,11 +17,35 @@
*/
use crate::domain::command::Command;
use crate::domain::command::CommandError;
struct CreateProject(String);
struct CreateProject {
code: String,
name: String,
}
impl CreateProject {
fn new(code: &str, name: &str) -> Self {
Self {
code: code.into(),
name: name.into(),
}
}
}
impl Command for CreateProject {
fn execute(&self) -> Result<(), ()> {
fn execute(&self) -> Result<(), CommandError> {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_create_project() {
let command = CreateProject::new("project", "some project");
assert!(command.execute().is_ok());
}
}

Loading…
Cancel
Save