public void MaintainsValueOfIsSafePropertyInNewObjects(bool methodIsSafe)
            {
                var directive = new ConditionalRequestDirective(methodIsSafe);

                var result = directive.SplitETag(3, t => null);

                Assert.All(result, d =>
                {
                    Assert.Equal(methodIsSafe, d.IsSafe);
                });
            }
            public void WhenDirectiveHasNoPropertiesSet_ReturnsExpectedNumberOfNewDirectivesWithNoPropertiesSet(int count)
            {
                var directive = new ConditionalRequestDirective(true);

                var result = directive.SplitETag(count, t => null);

                Assert.Equal(count, result.Length);
                Assert.All(result, d =>
                {
                    Assert.NotNull(d);
                    Assert.NotSame(directive, d);
                    Assert.Null(d.IfModifiedSince);
                    Assert.Null(d.IfUnmodifiedSince);
                    Assert.Empty(d.IfMatch);
                    Assert.Empty(d.IfNoneMatch);
                });
            }
            public void WhenDirectiveHasPropertiesSet_ReturnsExpectedNumberOfNewDirectivesWithPropertiesSet()
            {
                var dateTime1 = new DateTimeOffset(2015, 10, 1, 1, 2, 3, TimeSpan.Zero);
                var dateTime2 = new DateTimeOffset(2015, 11, 1, 1, 2, 3, TimeSpan.Zero);
                var directive = new ConditionalRequestDirective(true);
                directive.IfModifiedSince = dateTime1;
                directive.IfUnmodifiedSince = dateTime2;
                directive.IfMatch.Add(new ETag("ifMatch1", isWeak: false));
                directive.IfMatch.Add(new ETag("ifMatch2", isWeak: false));
                directive.IfNoneMatch.Add(new ETag("ifNoneMatch1", isWeak: false));
                directive.IfNoneMatch.Add(new ETag("ifNoneMatch2", isWeak: false));

                var result = directive.SplitETag(2, t =>
                {
                    return new[] { new ETag(t.Value + "copy1", false), new ETag(t.Value + "copy2", false) };
                });


                Assert.All(result, d =>
                {
                    Assert.NotNull(d);
                    Assert.NotSame(directive, d);
                    Assert.Equal(dateTime1, d.IfModifiedSince);
                    Assert.Equal(dateTime2, d.IfUnmodifiedSince);
                });

                Assert.Collection(result,
                    d1 =>
                    {
                        Assert.Equal(new[] { new ETag("ifMatch1copy1", false), new ETag("ifMatch2copy1", false) }, d1.IfMatch.ToArray());
                        Assert.Equal(new[] { new ETag("ifNoneMatch1copy1", false), new ETag("ifNoneMatch2copy1", false) }, d1.IfNoneMatch.ToArray());
                    },
                    d2 =>
                    {
                        Assert.Equal(new[] { new ETag("ifMatch1copy2", false), new ETag("ifMatch2copy2", false) }, d2.IfMatch.ToArray());
                        Assert.Equal(new[] { new ETag("ifNoneMatch1copy2", false), new ETag("ifNoneMatch2copy2", false) }, d2.IfNoneMatch.ToArray());
                    });
            }
            public void WhenMatchConditionContainsAnyTag_DoesNotInvokeSplitterFunction_AndReturnsDuplicatesWithAnyTag()
            {
                var directive = new ConditionalRequestDirective(true);
                directive.IfMatch.Add(ETag.Any);
                directive.IfNoneMatch.Add(ETag.Any);

                var result = directive.SplitETag(2, t => { throw new Exception("Should not be called"); });

                Assert.All(result, d =>
                {
                    Assert.Equal(ETag.Any, d.IfMatch.Single());
                    Assert.Equal(ETag.Any, d.IfNoneMatch.Single());
                });
            }
            public void WhenSplitterFunctionReturnsUnexpectedNumber_Throws()
            {
                var directive = new ConditionalRequestDirective(true);
                directive.IfNoneMatch.Add(new ETag("abc", false));

                var ex = Assert.Throws<InvalidOperationException>(() => directive.SplitETag(2, e => new ETag[3]));

                Assert.Equal("The tag \"abc\" was split into an unexpected number of components. Expected 2 and received 3.", ex.Message);
            }
            public void WhenSplitterFunctionReturnsNull_Throws()
            {
                var directive = new ConditionalRequestDirective(true);
                directive.IfNoneMatch.Add(new ETag("abc", false));

                var ex = Assert.Throws<InvalidOperationException>(() => directive.SplitETag(2, e => null));

                Assert.Equal("The result of a tag split cannot be null.", ex.Message);
            }