public void CanMatchFailure() { var request = new Request { Name = "Steffen", EMail = "" }; var result = Validation.ValidateInput(request); result.Match( (x, msgs) => { throw new Exception("wrong match case"); }, msgs => { Assert.AreEqual("Email must not be blank", msgs[0]); }); }
public void CanMatchSuccess() { var request = new Request { Name = "Steffen", EMail = "*****@*****.**" }; var result = Validation.ValidateInput(request); result.Match( (x, msgs) => { Assert.AreEqual(request, x); }, msgs => { throw new Exception("wrong match case"); }); }
public static Result<Request, string> ValidateInput(Request input) { if (input.Name == "") return Result<Request, string>.FailWith("Name must not be blank"); if (input.EMail == "") return Result<Request, string>.FailWith("Email must not be blank"); return Result<Request, string>.Succeed(input); }
public void CanCreateSuccess() { var request = new Request { Name = "Steffen", EMail = "*****@*****.**" }; var result = Validation.ValidateInput(request); Assert.AreEqual(request, result.SucceededWith()); }