Exemplo n.º 1
0
            public static void IsFirstWhyNot3()
            {
                var value = OneOf <int, NoElements, MoreThanOneElement> .FromT1(default(NoElements));

                var whyNot = value.WhyNot();

                Assert.IsTrue(whyNot is NoElements);
            }
Exemplo n.º 2
0
        public CsvResult(string fileName, IAsyncEnumerable <T> records)
            : this(fileName)
        {
            if (records == null)
            {
                throw new ArgumentNullException(nameof(records));
            }

            _records = OneOf <IEnumerable <T>, IAsyncEnumerable <T> > .FromT1(records);
        }
Exemplo n.º 3
0
            public static void DoesNotHaveValue2()
            {
                var value = OneOf <int, NoElements> .FromT1(default(NoElements));

                Assert.Throws <InvalidOperationException>(
                    () => value.Value());
                //Fails presently, pending https://github.com/mcintyre321/OneOf/issues/29
                //Assert.Throws<InvalidOperationException>(
                //    () =>
                //    {
                //        var _ = value.Value;
                //    }, "because parity");
            }
Exemplo n.º 4
0
        protected OneOf <string, RenderFragment> GetShowValue(SelectOption option)
        {
            if (option.IsSearch || option.IsTag)
            {
                return(option.Value);
            }

            return(OptionLabelProp switch
            {
                "children" => option?.ChildContent,
                "value" => option?.Value ?? option.Label,
                "label" => option?.Label ?? option.Value,
                _ => SelectMode == SelectMode.Default ? OneOf <string, RenderFragment> .FromT1((option?.ChildContent)) : option?.Label ?? option.Value,
            });
Exemplo n.º 5
0
        private async Task <Option <OneOf <PostReadModel, NotApprovedResult <PostReadModel> > > > FindApprovedPost(Expression <Func <PostEntity, bool> > predicate)
        {
            var postEntity = await CreateBasePostQuery().FirstOrDefaultAsync(predicate);

            if (postEntity == null)
            {
                return(Option.None <OneOf <PostReadModel, NotApprovedResult <PostReadModel> > >());
            }
            else
            {
                var claims = await GetCreatorClaims(postEntity.CreatedBy.Id);

                var post   = postEntity.ToReadModel(claims);
                var result = post.IsApproved ?
                             OneOf <PostReadModel, NotApprovedResult <PostReadModel> > .FromT0(post) :
                             OneOf <PostReadModel, NotApprovedResult <PostReadModel> > .FromT1(new NotApprovedResult <PostReadModel>(post));

                return(Option.Some(result));
            }
        }
Exemplo n.º 6
0
        internal static OneOf <Wardrobe, IFailure> CreateForUser(string user)
        {
            // Parse clothes for user
            var garments = Users.GarmentsFor(user);
            IEnumerable <Garment> grm;

            if (garments.IsT0)
            {
                grm = garments.AsT0;
            }
            else
            {
                return(OneOf <Wardrobe, IFailure> .FromT1(garments.AsT1));
            }

            // Parse profile color
            var clr = Users.ColorFor(user);

            // Parse profile icon
            var icn = Users.IconFor(user);

            return(new Wardrobe(grm, user, clr, icn));
        }
Exemplo n.º 7
0
        private void InsertHandlerForPacket(PacketIdentifier packet, IPacketHandler <T> handler)
        {
            // TODO: Throw improved exception (show conflicting packets)
            var identifier = packet.Identifier;

            var handlers = this.packetHandlers;

            for (int i = 0; i < identifier.Count; i++)
            {
                bool isLastIdentifier = i == identifier.Count - 1;
                bool identifierExists = handlers.ContainsKey(identifier[i]);

                if (isLastIdentifier)
                {
                    if (identifierExists)
                    {
                        throw new ConflictingPacketHandlersException(packet);
                    }

                    var value = OneOf <PacketToHandlerDictionary, IPacketHandler <T> > .FromT1(handler);

                    handlers.Add(identifier[i], value);
                }
                else if (identifierExists)
                {
                    handlers = handlers[identifier[i]].Match(
                        dictionary => dictionary,
                        _ => throw new ConflictingPacketHandlersException(packet));
                }
                else
                {
                    var nestedHandlers = new PacketToHandlerDictionary();
                    handlers.Add(identifier[i], nestedHandlers);
                    handlers = nestedHandlers;
                }
            }
        }
Exemplo n.º 8
0
            public static void DoesNotHaveValue3()
            {
                var value = OneOf <int, NoElements, NoElements> .FromT1(default(NoElements));

                Assert.IsFalse(value.IsSuccess());
            }