コード例 #1
0
 public FixedSegmentMatcher(NonBlankTrimmedString segment)
 {
     if (segment == null)
     {
         throw new ArgumentNullException("segment");
     }
     _segment = segment;
 }
コード例 #2
0
        public RouteBuilder Fixed(NonBlankTrimmedString segment)
        {
            if (segment == null)
            {
                throw new ArgumentNullException("segment");
            }

            return(new RouteBuilder(_segments.Add(segment)));
        }
コード例 #3
0
 public Optional <SegmentMatchResult> Match(NonBlankTrimmedString segment)
 {
     if (segment == null)
     {
         throw new ArgumentNullException("segment");
     }
     return(segment.Value.Equals(_segment.Value, StringComparison.OrdinalIgnoreCase)
                             ? new SegmentMatchResult(valueExtractedFromVariableSegment: null)
                             : null);
 }
コード例 #4
0
        private static Optional <int> ParseInt(NonBlankTrimmedString segment)
        {
            if (segment == null)
            {
                throw new ArgumentNullException("segment");
            }

            int value;

            return(int.TryParse(segment.Value, out value) ? value : Optional <int> .Missing);
        }
コード例 #5
0
            public IBuildRoutesWithVariablesToMatch <TValues> Fixed(NonBlankTrimmedString segment)
            {
                if (segment == null)
                {
                    throw new ArgumentNullException("segment");
                }

                return(new BuilderWithExtractedValues <TValues>(
                           _segmentMatchers.Add(new FixedSegmentMatcher <TValues>(segment)),
                           _extractedValueBuilder
                           ));
            }
コード例 #6
0
            public Optional <SegmentMatchResult> Match(NonBlankTrimmedString segment)
            {
                if (segment == null)
                {
                    throw new ArgumentNullException("segment");
                }

                var parsedValue = _parser(segment);

                return(parsedValue.IsDefined
                                        ? new SegmentMatchResult(valueExtractedFromVariableSegment: parsedValue.Value)
                                        : null);
            }
コード例 #7
0
ファイル: Link.cs プロジェクト: softearth/Bridge.ReactRouting
 public Link(
     UrlDetails url,
     NonBlankTrimmedString text,
     bool caseSensitiveUrlMatching           = false,
     Optional <NonBlankTrimmedString> name   = new Optional <NonBlankTrimmedString>(),
     Optional <NonBlankTrimmedString> target = new Optional <NonBlankTrimmedString>(),
     Optional <ClassName> className          = new Optional <ClassName>(),
     Optional <ClassName> ancestorClassName  = new Optional <ClassName>(),
     Optional <ClassName> selectedClassName  = new Optional <ClassName>(),
     Optional <Action <MouseEvent <Bridge.Html5.HTMLAnchorElement> > > onClick = new Optional <Action <MouseEvent <Bridge.Html5.HTMLAnchorElement> > >(),
     Optional <IInteractWithBrowserRouting> historyHandlerOverride             = new Optional <IInteractWithBrowserRouting>())
     : base(new Props(url, text, caseSensitiveUrlMatching, name, target, className, ancestorClassName, selectedClassName, onClick, historyHandlerOverride))
 {
 }
コード例 #8
0
        public TextBox(string message, double size, Resolution resolution, NonBlankTrimmedString fillStyle = null)
        {
            if (fillStyle != null)
            {
                _fillStyle = fillStyle;
            }
            else
            {
                _fillStyle = new NonBlankTrimmedString("#000");
            }

            _image = new HTMLImageElement()
            {
                Src    = CreateImage(message, size),
                OnLoad = (e) =>
                {
                    Width  = _image.Width;
                    Height = _image.Height;
                }
            };

            _resolution = resolution;
        }
コード例 #9
0
 public UrlPathDetails Segment(NonBlankTrimmedString segment)
 {
     return(_getWithSegment(segment));
 }
コード例 #10
0
 public UrlPathDetails Accommodation(NonBlankTrimmedString segment)
 {
     return(_getAccommodationWithSegment(segment));
 }
コード例 #11
0
        private static void EqualsTests()
        {
            QUnit.Module("Equals(..)");

            QUnit.Test("An instance of NonBlankTrimmedString is found to be equal to itself", assert =>
            {
                var x = new NonBlankTrimmedString("xyz");
                AssertEqualsViaNonBlankTrimmedStringEqualsCall(assert, x, x, shouldBeEqual: true);
            });

            QUnit.Test("Two instances of NonBlankTrimmedString with the same value are found to be equal when compared as NonBlankTrimmedString", assert =>
            {
                var x = new NonBlankTrimmedString("xyz");
                var y = new NonBlankTrimmedString("xyz");
                AssertEqualsViaNonBlankTrimmedStringEqualsCall(assert, x, y, shouldBeEqual: true);
            });
            QUnit.Test("Two instances of NonBlankTrimmedString with the same value are found to be equal when compared as generic type param of NonBlankTrimmedString", assert =>
            {
                var x = new NonBlankTrimmedString("xyz");
                var y = new NonBlankTrimmedString("xyz");
                AssertEqualsViaSharedGenericTypeEqualsCall(assert, x, y, shouldBeEqual: true);
            });
            QUnit.Test("Two instances of NonBlankTrimmedString with the same value are found to be equal when compared as Object", assert =>
            {
                var x = new NonBlankTrimmedString("xyz");
                var y = new NonBlankTrimmedString("xyz");
                AssertEqualsViaObjectEqualsCall(assert, x, y, shouldBeEqual: true);
            });

            // There was a hack in ProductiveRage.Immutable to help Optional<T>'s Equals implementation work when T is an [ObjectLiteral] but that isn't required with the hacks in this library
            // (so, once I'm happy with this all, I'll remove them from ProductiveRage.Immutable, so 3.2.0 will have the hacks removed that were introduced in 3.1.0 - for now, the tests here
            // are referencing the 3.0.0 NuGet package, which doesn't have the hacks in it)
            QUnit.Test("Two instances of Optional<NonBlankTrimmedString> with the same value are found to be equal when compared as NonBlankTrimmedString", assert =>
            {
                var x = Optional.For(new NonBlankTrimmedString("xyz"));
                var y = Optional.For(new NonBlankTrimmedString("xyz"));
                AssertEqualsViaOptionalNonBlankTrimmedStringEqualsCall(assert, x, y, shouldBeEqual: true);
            });
            QUnit.Test("Two instances of Optional<NonBlankTrimmedString> with the same value are found to be equal when compared as generic type param of NonBlankTrimmedString", assert =>
            {
                var x = Optional.For(new NonBlankTrimmedString("xyz"));
                var y = Optional.For(new NonBlankTrimmedString("xyz"));
                AssertEqualsViaSharedGenericTypeEqualsCall(assert, x, y, shouldBeEqual: true);
            });
            QUnit.Test("Two instances of Optional<NonBlankTrimmedString> with the same value are found to be equal when compared as Object", assert =>
            {
                var x = Optional.For(new NonBlankTrimmedString("xyz"));
                var y = Optional.For(new NonBlankTrimmedString("xyz"));
                AssertEqualsViaObjectEqualsCall(assert, x, y, shouldBeEqual: true);
            });

            QUnit.Test("Two instances of NonBlankTrimmedString with the same value are NOT equal if they are of different types when compared as NonBlankTrimmedString", assert =>
            {
                var x = new NonBlankTrimmedString("xyz");
                var y = new ClassName("xyz");
                AssertEqualsViaNonBlankTrimmedStringEqualsCall(assert, x, y, shouldBeEqual: false);
            });
            QUnit.Test("Two instances of NonBlankTrimmedString with the same value are NOT equal if they are of different types when compared as generic type param of NonBlankTrimmedString", assert =>
            {
                var x = new NonBlankTrimmedString("xyz");
                var y = new ClassName("xyz");
                AssertEqualsViaSharedGenericTypeEqualsCall(assert, x, y, shouldBeEqual: false);
            });
            QUnit.Test("Two instances of NonBlankTrimmedString with the same value are NOT equal if they are of different types when compared as Object", assert =>
            {
                var x = new NonBlankTrimmedString("xyz");
                var y = new ClassName("xyz");
                AssertEqualsViaObjectEqualsCall(assert, x, y, shouldBeEqual: false);
            });

            // This tests a few issues that have been encountered after using [ObjectLiteral] in more places - the FixObjectLiteralEqualsHack approach means that the implicit operator will
            // not reliably be called when comparing an Optional<T> to T (the fix for that is in 4.1.0 of ProductiveRage.Immutable) and FixObjectLiteralEqualsHack now supports "falling
            // through" equality checks if false is returned (so is comparing a NonBlankTrimmedString, which is an [ObjectLiteral], to an Optional<NonBlankTrimmedString> then the Equals
            // check made against the NonBlankTrimmedString's Equals method will return false as it is unaware of Optional's implicit casting support and so other Equals methods need to
            // be give opportunity to run) and it tests a bug with FixObjectLiteralEqualsHack relating to different generic types where the cached Equals lookup for an [ObjectLiteral]
            // generic class would result in type checks against the generic type parameters being incorrect.
            QUnit.Test("Integration tests around NonBlankTrimmedString / Optional / another [ObjectLiteral]", assert =>
            {
                var stringValue           = new NonBlankTrimmedString("test");
                var optionalOfString      = Optional.For(stringValue);
                var resultOrErrorOfString = ResultOrErrorDetails.FromResult(stringValue);

                assert.NotOk(Equals(optionalOfString, resultOrErrorOfString));
                assert.Ok(Equals(optionalOfString, stringValue));
                assert.Ok(Equals(stringValue, optionalOfString));
                assert.Ok(Equals(ResultOrErrorDetails.FromResult("abc"), ResultOrErrorDetails.FromResult("abc")));
                assert.Ok(Equals(ResultOrErrorDetails.FromResult(new NonBlankTrimmedString("abc")), ResultOrErrorDetails.FromResult(new NonBlankTrimmedString("abc"))));
                assert.NotOk(Equals(ResultOrErrorDetails.FromResult(new NonBlankTrimmedString("abc")), ResultOrErrorDetails.FromResult("abc")));
            });
        }
コード例 #12
0
        private static void AssertEqualsViaNonBlankTrimmedStringEqualsCall(Assert assert, NonBlankTrimmedString x, NonBlankTrimmedString y, bool shouldBeEqual)
        {
            if ((x == null) && (y == null))
            {
                return;
            }

            assert.Ok((x != null) && (y != null), "Unless both x and y are null, they must both NOT be null in order to be equal");
            var result = x.Equals(y);

            if (shouldBeEqual)
            {
                assert.Ok(x.Equals(y));
            }
            else
            {
                assert.NotOk(x.Equals(y));
            }
        }
コード例 #13
0
 public NavigateToItem(NonBlankTrimmedString id)
 {
     this.CtorSet(_ => _.Id, id);
 }
コード例 #14
0
 public NavigateToAccommodationSection(NonBlankTrimmedString segment)
 {
     Segment = segment;
 }
コード例 #15
0
 public void Item(NonBlankTrimmedString name)
 {
     _navigateToItem(name);
 }
 public UrlPathDetails Item(NonBlankTrimmedString name)
 {
     return(_getItem(name));
 }
コード例 #17
0
 public RequestedAccommodationSectionDetails(NonBlankTrimmedString segment, DateTime requestedAt)
 {
     this.CtorSet(_ => _.Segment, segment);
     this.CtorSet(_ => _.RequestedAt, requestedAt);
 }