public static ValueResult <Id> Create(int value) { if (value <= 0) { return(ValueResult <Id> .Fail( ErrorMessages.Id.IdCannotBeNonPositive)); } return(ValueResult <Id> .Ok(new Id(value))); }
public static ValueResult <Student> Create(string name) { var nameResult = NonEmptyText.Create(name); if (nameResult.IsFailure) { return(ValueResult <Student> .Fail(nameResult.Error)); } return(ValueResult <Student> .Ok(new Student(nameResult.Value))); }
public static ValueResult <NonEmptyText> Create(string textValue) { if (string.IsNullOrWhiteSpace(textValue)) { return(ValueResult <NonEmptyText> .Fail( ErrorMessages.NonEmptyText.TextValueCannotBeEmpty)); } return(ValueResult <NonEmptyText> .Ok( new NonEmptyText(textValue))); }
public static ValueResult <Student> Create(string name, int id) { var idResult = ValueObjects.Id.Create(id); if (idResult.IsFailure) { return(ValueResult <Student> .Fail(idResult.Error)); } var studentResult = Create(name); if (studentResult.IsFailure) { return(ValueResult <Student> .Fail(studentResult.Error)); } return(ValueResult <Student> .Ok(new Student(idResult.Value, studentResult.Value.Name))); }
public void ShouldGetValueCorrectlyForSuccessResult() { var okResult = ValueResult <int> .Ok(int.MinValue); Assert.AreEqual(int.MinValue, okResult.Value); }