Ejemplo n.º 1
0
        public Card GetCard(Guid guid)
        {
            string statement = "SELECT * FROM mtcg.\"Card\" " +
                               "WHERE \"Guid\"=@guid";

            using (NpgsqlCommand cmd = new NpgsqlCommand(statement, PostgreSQLSingleton.GetInstance.Connection))
            {
                cmd.Parameters.Add("guid", NpgsqlDbType.Uuid).Value = guid;
                cmd.Prepare();
                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        reader.Read();
                        CardDto cardDto = new CardDto()
                        {
                            CardType = reader["Type"].ToString(),
                            Damage   = (double)reader["Damage"],
                            Element  = reader["Element"].ToString(),
                            Name     = reader["Name"].ToString()
                        };
                        Card card = cardDto.ToObject();
                        card.Guid = Guid.Parse(reader["Guid"].ToString());
                        return(card);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void Test_CardDtoToObjectReturnsCorrectProperties(CardDto testDto, Card result)
        {
            Card card = testDto.ToObject();

            Assert.AreEqual(result?.Name, card?.Name);
            Assert.AreEqual(result?.Damage, card?.Damage);
            Assert.AreEqual(result?.Element, card?.Element);
        }
Ejemplo n.º 3
0
        public void Test_CardDtoToObjectReturnsCorrectCardType(string typename, Type expectedType)
        {
            CardDto cardDto = new CardDto()
            {
                CardType = typename,
                Damage   = 20,
                Name     = "Testcard"
            };

            Type t = cardDto.ToObject().GetType();

            Assert.AreEqual(expectedType, t);
        }
Ejemplo n.º 4
0
        public ResponseContext Post(Dictionary <string, object> param)
        {
            RequestContext request = (RequestContext)param["request"];

            if (!request.Headers.ContainsKey("Content-Type") || request.Headers["Content-Type"] != "application/json")
            {
                return(new ResponseContext(request, new KeyValuePair <StatusCode, object>(StatusCode.UnsupportedMediaType, "")));
            }

            CardDto cardDto = JsonSerializer.Deserialize <CardDto>(request.Payload);
            Card    card;

            if (cardDto == null || string.IsNullOrWhiteSpace(cardDto.CardType) || string.IsNullOrWhiteSpace(cardDto.Name) || (card = cardDto.ToObject()) == null)
            {
                return(new ResponseContext(request,
                                           new KeyValuePair <StatusCode, object>(StatusCode.BadRequest,
                                                                                 "Either the card type or the name is empty or the given type or the element does not exist")));
            }

            return(new ResponseContext(request, _cardController.CreateCard(card)));
        }