public void ValidateSection2_WithMultileSubValidators_ShouldRunSection2() { //Arrange var doubleLeft = new TestSimpleValidator <SomeModel>(); doubleLeft.ValidateFunc = x => { doubleLeft.Start(new ValidationInfoBase(_guid)); doubleLeft.Pass(); }; var doubleRight = new TestSimpleValidator <SomeModel>(); doubleRight.ValidateFunc = x => { doubleRight.Start(new ValidationInfoBase(_guid2)); doubleRight.Fail(); }; _sut = new TestSectionedValidator <SomeModel>(); _sut.Init(() => { _sut.Section(Section, m => _sut.RunValidator(doubleLeft, m.Some)); _sut.Section(Section2, m => _sut.RunValidator(doubleRight, m.Some)); }); //Act var result = _sut.ValidateSection(Section2, _model); //Assert Assert.IsFalse(result.Passes.Any()); Assert.IsTrue(result.Fails.Count() == 1); Assert.IsTrue(result.Fails.First().Guid == _guid2); }
public async Task ValidateSectionAsync_WithSyncSection_ShouldReturnSomething() { //Arrange _sut = new TestSectionedValidator <SomeModel>(); _sut.Init(() => _sut.Section(Section, m => {})); //Act var result = await _sut.ValidateSectionAsync(Section, _model); //Assert Assert.NotNull(result); }
public async Task ValidateAsync_ShouldInvokeDoValidate() { //Arrange var isRun = false; _sut = new TestSectionedValidator <SomeModel>(); _sut.Init(() => _sut.Section(Section, m => isRun = true)); //Act await _sut.ValidateAsync(_model); //Assert Assert.IsTrue(isRun); }
public void ValidateSection2_ShouldTestOnlySection2() { //Arrange _sut = new TestSectionedValidator <SomeModel>(); _sut.Init(() => { _sut.Section(Section, x => { _sut.Start(new ValidationInfoBase(_guid)); _sut.Pass(); }); _sut.Section(Section2, x => { _sut.Start(new ValidationInfoBase(_guid2)); _sut.Fail(); }); }); //Act var result = _sut.ValidateSection(Section2, _model); //Assert Assert.IsFalse(result.Passes.Any()); Assert.IsTrue(result.Fails.Count() == 1); Assert.IsTrue(result.Fails.First().Guid == _guid2); }
public void Validate_WithSubValidator_ShouldRun() { //Arrange var sub1 = new TestSimpleValidator <SomeModel>(); sub1.ValidateFunc = x => { sub1.Start(new ValidationInfoBase(_guid)); sub1.Pass(); }; _sut = new TestSectionedValidator <SomeModel>(); _sut.Init(() => _sut.Section(Section, m => _sut.RunValidator(sub1, m.Some))); //Act var result = _sut.Validate(_model); //Assert Assert.IsTrue(result.Passes.Count() == 1); Assert.IsTrue(result.Passes.First().Guid == _guid); Assert.IsFalse(result.Fails.Any()); }