Beispiel #1
0
        public Task <GetOrderByIdResult> ExecuteAsync(GetOrderByIdParameters parameters, CancellationToken cancellationToken = default)
        {
            var data = new Order
            {
                Id                 = Guid.Parse("77a33260-0000-441f-ba60-b0a833803fab"),
                Description        = "Hallo1",
                MyTime             = DateTimeOffset.Parse("2020-10-12T21:22:23"),
                MyEmail            = "*****@*****.**",
                MyNullableDateTime = DateTimeOffset.Parse("2020-10-12T21:22:23"),
                MyDateTime         = DateTimeOffset.Parse("2020-10-12T21:22:23"),
                MyNumber           = 20.2,
                MyInteger          = 42,
                MyBool             = true,
                MyUri              = new Uri("http://www.dr.dk"),
                MyByte             = "Hallo10",
                MyStringList       = null,
                MyLong             = 42,
                DeliveryAddress    = new Address
                {
                    StreetName   = "Hallo",
                    StreetNumber = "Hallo1",
                    PostalCode   = "Hallo2",
                    CityName     = "Hallo3",
                    MyCountry    = new Country
                    {
                        Name       = "Hallo1",
                        Alpha2Code = "Ha",
                        Alpha3Code = "Hal",
                    },
                },
            };

            return(Task.FromResult(GetOrderByIdResult.Ok(data)));
        }
        public Task <ActionResult> GetOrderByIdAsync(GetOrderByIdParameters parameters, [FromServices] IGetOrderByIdHandler handler, CancellationToken cancellationToken)
        {
            if (handler is null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            return(InvokeGetOrderByIdAsync(parameters, handler, cancellationToken));
        }
        public Task <GetOrderByIdResult> ExecuteAsync(GetOrderByIdParameters parameters, CancellationToken cancellationToken = default)
        {
            if (parameters is null)
            {
                throw new System.ArgumentNullException(nameof(parameters));
            }

            return(InvokeExecuteAsync(parameters, cancellationToken));
        }
        public async Task <GetOrderByIdResult> ExecuteAsync(GetOrderByIdParameters parameters, CancellationToken cancellationToken = default)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            return(parameters.Id.ToString() switch
            {
                "77a33260-0007-441f-ba60-b0a833803fab" => await Task.FromResult(GetOrderByIdResult.NotFound($"Could not find order with id={parameters.Id}")),
                "77a33260-0008-441f-ba60-b0a833803fab" => throw new Exception("Crash! Boom! Bang! # " + parameters.Id),
                "77a33260-0009-441f-ba60-b0a833803fab" => throw new InvalidOperationException("Crash! Boom! Bang! # " + parameters.Id),
                "77a33260-0010-441f-ba60-b0a833803fab" => throw new UnauthorizedAccessException("Crash! Boom! Bang! # " + parameters.Id),
                "77a33260-0011-441f-ba60-b0a833803fab" => throw new NotImplementedException("Crash! Boom! Bang! # " + parameters.Id),
                _ => await InvokeExecuteAsync(parameters, cancellationToken)
            });
 private static async Task <ActionResult> InvokeGetOrderByIdAsync(GetOrderByIdParameters parameters, IGetOrderByIdHandler handler, CancellationToken cancellationToken)
 {
     return(await handler.ExecuteAsync(parameters, cancellationToken));
 }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        private async Task <GetOrderByIdResult> InvokeExecuteAsync(GetOrderByIdParameters parameters, CancellationToken cancellationToken)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            throw new System.NotImplementedException();
        }