Пример #1
0
        public async void Return_TRt__When_Asyncs_Invoked_Serially_Successful()
        {
            var svc = new AsyncService();
            var r   = await Async("Sheik")
                      .Map(svc.Greet)
                      .Map(svc.GeoPoint)
                      .Map(svc.GivePriority);

            Assert.True(r.HasValue);
        }
Пример #2
0
        public async void Return_TRr__When_Asyncs_Include_Sync()
        {
            var svc = new AsyncService();
            var r   = await "Sheik"
                      .Pipe(svc.Greet)
                      .Map(svc.JustNormalHello);
            var actual = r.Match
                             (pass: m => m,
                             fail: e => "None");

            Assert.Equal("Your greet message is Hello, Sheik", actual);
        }
Пример #3
0
        public async void Return_TRr__When_Asyncs_Starts_Tt_With_Pipe()
        {
            var svc = new AsyncService();
            var r   = await "Sheik"
                      .Pipe(svc.Welcome)
                      .Map(svc.Greet)
                      .Map(svc.GeoPoint)
                      .Map(svc.GivePriority);
            var actual = r.Match
                             (pass: i => 1,
                             fail: e => 0);

            Assert.Equal(1, actual);
        }
Пример #4
0
        public async void Return_TRe__When_Asyncs_Invoked_Serially_Broken()
        {
            var svc = new AsyncService();
            var r   = await "Sheik"
                      .Pipe(svc.Greet)
                      .Map(svc.KickOff)
                      .Map(svc.GeoPoint)
                      .Map(svc.GivePriority);
            var result = r.Match
                             (pass: i => 1,
                             fail: e => e.Exception.Message.Contains("kicked") ? -1: 0);

            Assert.Equal(-1, result);
        }
Пример #5
0
        public async void Return_TRr__When_Sync_FollowedBy_Asyncs()
        {
            var svc = new AsyncService();
            var nameShouldBeProvided = Spec <string>(s => !string.IsNullOrEmpty(s));
            var r = await Result("Sheik")
                    .Map(nameShouldBeProvided, () => Error.Of(1012))
                    .Map(svc.Greet)
                    .Map(svc.JustNormalHello);

            var actual = r.Match
                             (pass: m => m,
                             fail: e => "None");

            Assert.Equal("Your greet message is Hello, Sheik", actual);
        }