Ejemplo n.º 1
0
        public DataProviderFixture()
        {
            // Instantiate providers and necessary validation/mocking rules
            ValidCardProvider = new Faker <CardTemplate>()
                                .CustomInstantiator(f => CardTemplate.NewTemplate(
                                                        f.PickRandomParam(RanksEnumeration.List.ToArray()),
                                                        f.PickRandomParam(SuitsEnumeration.List.ToArray())
                                                        ))
                                .RuleFor(o => o.ImageUrl, f => f.Image.LoremPixelUrl(LoremPixelCategory.Cats));

            //.StrictMode(false) // can ensure all properties covered by rules

            CardTemplates = new List <CardTemplate>();
            foreach (var suit in SuitsEnumeration.List)
            {
                foreach (var rank in RanksEnumeration.List)
                {
                    var template = CardTemplate.NewTemplate(rank, suit);
                    template.CardName = "Unit test runtime value: " + rank.Name + " of " + suit.Name;
                    template.ImageUrl = ValidCardProvider.Generate().ImageUrl;
                    CardTemplates.Add(template);
                }
            }

            Standard52CardDeck = Deck.Standard52CardDeck(CardTemplates);
            ZeroCardDeck       = Deck.FromCards(null);

            InvalidCardProvider = new Faker <CardTemplate>()
                                  .StrictMode(false) // can ensure all properties covered by rules
                                  .RuleFor(o => o.Suit, f => null)
                                  .RuleFor(o => o.Rank, f => null)
                                  .RuleFor(o => o.CardName, f => string.Empty);
        }
Ejemplo n.º 2
0
        public override Deck ReadJson(JsonReader reader, Type objectType, Deck existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            JObject jObject = JObject.Load(reader);
            string  debug   = jObject.ToString();
            Guid    id      = Guid.Parse(jObject["@metadata"]["@id"].Value <string>());
            // Manual LINQ token conversion, but could also reuse DTO's from below
            IList <PlayingCard> ravenCards = jObject["Cards"]
                                             .Children()
                                             .Select(x => new PlayingCard(x["Id"].Value <string>(),
                                                                          CardTemplate.NewTemplate(RanksEnumeration.FromValue(x["Rank"].Value <ushort>()),
                                                                                                   SuitsEnumeration.FromValue(x["Suit"].Value <ushort>())))).ToList();
            var serializedDeck = Deck.FromCards(ravenCards);

            return(serializedDeck);
        }