예제 #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 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)
            });