Example #1
0
            public void AbsenceOfKeyThrows()
            {
                // Given
                IDocument             document     = new TestDocument();
                IExecutionContext     context      = new TestExecutionContext();
                ValidateMeta <string> validateMeta = new ValidateMeta <string>("Title");

                // When, Then
                Assert.Throws <AggregateException>(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #2
0
            public void AbsenceOfKeyThrows()
            {
                // Given
                IDocument document = Substitute.For<IDocument>();
                IExecutionContext context = Substitute.For<IExecutionContext>();
                document.Metadata.ContainsKey("Title").Returns(false);
                ValidateMeta<string> validateMeta = new ValidateMeta<string>("Title");

                // When, Then
                Assert.Throws<AggregateException>(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #3
0
            public void AbsenceOfKeyThrows()
            {
                // Given
                IDocument         document = Substitute.For <IDocument>();
                IExecutionContext context  = Substitute.For <IExecutionContext>();

                document.Metadata.ContainsKey("Title").Returns(false);
                ValidateMeta <string> validateMeta = new ValidateMeta <string>("Title");

                // When, Then
                Assert.Throws <AggregateException>(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #4
0
            public void ExistenceOfKeyDoesNotThrow()
            {
                // Given
                IDocument document = Substitute.For<IDocument>();
                IExecutionContext context = Substitute.For<IExecutionContext>();
                document.Metadata.ContainsKey("Title").Returns(true);
                string value;
                document.MetadataAs<string>().TryGetValue("Title", out value).Returns(true);
                ValidateMeta<string> validateMeta = new ValidateMeta<string>("Title");

                // When, Then
                Assert.DoesNotThrow(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #5
0
            public void PassedAssertionDoesNotThrow()
            {
                // Given
                IDocument document = new TestDocument(
                    new MetadataItems
                {
                    { "Title", "Foo" }
                });
                IExecutionContext     context      = new TestExecutionContext();
                ValidateMeta <string> validateMeta = new ValidateMeta <string>("Title").WithAssertion(x => x == "Foo");

                // When, Then
                Assert.DoesNotThrow(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #6
0
            public void FailedAssertionThrows()
            {
                // Given
                IDocument document = new TestDocument(
                    new MetadataItems
                {
                    { "Title", "Foo" }
                });
                IExecutionContext     context      = new TestExecutionContext();
                ValidateMeta <string> validateMeta = new ValidateMeta <string>("Title").WithAssertion(x => x == "Baz");

                // When, Then
                Assert.Throws <AggregateException>(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #7
0
            public void ExistenceOfKeyDoesNotThrow()
            {
                // Given
                IDocument         document = Substitute.For <IDocument>();
                IExecutionContext context  = Substitute.For <IExecutionContext>();

                document.Metadata.ContainsKey("Title").Returns(true);
                string value;

                document.MetadataAs <string>().TryGetValue("Title", out value).Returns(true);
                ValidateMeta <string> validateMeta = new ValidateMeta <string>("Title");

                // When, Then
                Assert.DoesNotThrow(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #8
0
            public void FailedAssertionThrows()
            {
                // Given
                IDocument document = Substitute.For<IDocument>();
                IExecutionContext context = Substitute.For<IExecutionContext>();
                document.Metadata.ContainsKey("Title").Returns(true);
                string value;
                document.MetadataAs<string>().TryGetValue("Title", out value).Returns(x =>
                {
                    x[1] = "Foobar";
                    return true;
                });
                ValidateMeta<string> validateMeta = new ValidateMeta<string>("Title").WithAssertion(x => x == "Baz");

                // When, Then
                Assert.Throws<AggregateException>(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }
Example #9
0
            public void FailedAssertionThrows()
            {
                // Given
                IDocument         document = Substitute.For <IDocument>();
                IExecutionContext context  = Substitute.For <IExecutionContext>();

                document.Metadata.ContainsKey("Title").Returns(true);
                string value;

                document.MetadataAs <string>().TryGetValue("Title", out value).Returns(x =>
                {
                    x[1] = "Foobar";
                    return(true);
                });
                ValidateMeta <string> validateMeta = new ValidateMeta <string>("Title").WithAssertion(x => x == "Baz");

                // When, Then
                Assert.Throws <AggregateException>(() => validateMeta.Execute(new[] { document }, context).ToList());  // Make sure to materialize the result list
            }