public void BuyPackage()
        {
            RequestKontext req   = new RequestKontext("POST", "/transactions/packages", "HTTP/1.1", "", "test1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.AreEqual("200 OK", reply.Status);
        }
        public void AddPackages()
        {
            RequestKontext req2   = new RequestKontext("POST", "/packages", "HTTP/1.1", "[{\"Id\":\"test6\", \"Name\":\"WaterGoblin\", \"Damage\": 40.0}, {\"Id\":\"test7\", \"Name\":\"Dragon\", \"Damage\": 100.0}, {\"Id\":\"test8\", \"Name\":\"WaterSpell\", \"Damage\": 40.0}, {\"Id\":\"test9\", \"Name\":\"Ork\", \"Damage\": 90.0}, {\"Id\":\"test10\", \"Name\":\"FireSpell\", \"Damage\": 50.0}]", "testadmin");
            ServerReply    reply2 = ServerReply.HandlingRequest(req2);

            Assert.AreEqual("201 Created", reply2.Status);
        }
        public override Task <ServerReply> Disconnect(ServerRequest request, ServerCallContext context)
        {
            if (!TokenAuthentification(context.RequestHeaders, out string clientTokenValue))
            {
                return(Task.FromResult(new ServerReply()
                {
                    RequestState = true
                }));
            }

            if (!_registredUsers.TryRemove(clientTokenValue, out UserClient userDataInfo))
            {
                return(Task.FromResult(new ServerReply()
                {
                    RequestState = true
                }));
            }

            // stop stream channel
            userDataInfo.CancellationTokenSource.Cancel();

            userDataInfo.UserState = UserState.None;

            var reply = new ServerReply
            {
                RequestState = true
            };

            return(Task.FromResult(reply));
        }
示例#4
0
 public IrcException(ServerReply reply, string v, RawMessage response, RawMessage request)
 {
     Reply    = reply;
     Message  = v;
     Response = response;
     Request  = request;
 }
        public static void LogOut()  //No such User in table game_user, must create user first
        {
            RequestKontext req   = new RequestKontext("POST", "/signout", "HTTP/1.1", "", "test1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "404 Not Found", "Error: User doesn't exist!", "text");
            Assert.AreEqual("200 OK", reply.Status);
        }
示例#6
0
        public void ShowPlayerData()  //Ok
        {
            RequestKontext req   = new RequestKontext("GET", "/users/testadmin", "HTTP/1.1", "", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "200 OK", result, "text");
            Assert.AreEqual("200 OK", reply.Status);
        }
        public void CheckDeals()
        {
            RequestKontext req   = new RequestKontext("GET", "/tradings", "HTTP/1.1", "", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "401 Unauthorized", "User doesn't have a session / invalid Token!", "text");
            Assert.AreEqual("200 OK", reply.Status);
        }
示例#8
0
        public void ShowDeck() //show all acquired cards
        {
            RequestKontext req   = new RequestKontext("GET", "/deck", "HTTP/1.1", "", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "200 OK", "result", "text");
            Assert.AreEqual("200 OK", reply.Status);
        }
示例#9
0
        public void SendMessageBrokenRequest2()
        {
            req.Type    = "POST";
            req.Options = "/messages/2";
            ServerReply sr = SetServerReply();

            Assert.AreEqual(CheckValues(sr, "400 Bad Request", "HTTP/1.1", "", "text"), true);
            Assert.AreEqual(GetNumOfFiles(), 0);
        }
示例#10
0
        public void NotSupportedRequest()
        {
            req.Type    = "PATCH";
            req.Options = "/messages/99";
            req.Body    = "";
            ServerReply sr = SetServerReply();

            Assert.AreEqual(CheckValues(sr, "405 Method Not Allowed", "HTTP/1.1", "", "text"), true);
        }
示例#11
0
        public void PUTMessageNotExisting()
        {
            req.Type    = "PUT";
            req.Options = "/messages/99";
            req.Body    = "";
            ServerReply sr = SetServerReply();

            Assert.AreEqual(CheckValues(sr, "416 Range Not Satisfiable", "HTTP/1.1", "", "text"), true);
        }
示例#12
0
        public void PUTBrokenRequest()
        {
            req.Type    = "PUT";
            req.Options = "/messages";
            req.Body    = "";
            ServerReply sr = SetServerReply();

            Assert.AreEqual(CheckValues(sr, "400 Bad Request", "HTTP/1.1", "", "text"), true);
        }
        public void ShowScoreBoard()
        {
            RequestKontext req   = new RequestKontext("GET", "/stats", "HTTP/1.1", "", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "200 OK", "reply", "text");
            Assert.AreEqual("200 OK", reply.Status);
        }
示例#14
0
        public void EditPlayerData()  //Ok
        {
            RequestKontext req   = new RequestKontext("PUT", "/users/testadmin", "HTTP/1.1", "{\"Name\": \"Test Admin\",  \"Bio\": \"me playin...\", \"Email\": \"[email protected]\"}", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "200 OK", result, "text");
            Assert.AreEqual("200 OK", reply.Status);
        }
        public void TryTradeNotObtainedCard()
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings/1", "HTTP/1.1", "\"test1\"", "test1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            // return new ServerReply(req.Protocol, "409 Conflict", "Error: User doesnt own this card!", "text");
            Assert.AreEqual("409 Conflict", reply.Status);
            Assert.AreEqual("Error: User doesnt own this card!", reply.Data);
        }
        public void TryTradeNonExisitingTrade()
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings/1111", "HTTP/1.1", "\"test6\"", "test1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            // return new ServerReply(req.Protocol, "409 Conflict", "Error: Trade doesn't exists!", "text");
            Assert.AreEqual("409 Conflict", reply.Status);
            Assert.AreEqual("Error: Trade doesn't exists!", reply.Data);
        }
示例#17
0
        public void EditPlayerInvalidToken()  //INvalid Token
        {
            RequestKontext req   = new RequestKontext("PUT", "/users/asd", "HTTP/1.1", "{\"Name\": \"Test Admin\",  \"Bio\": \"me playin...\", \"Email\": \"[email protected]\"}", "asd");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "401 Unauthorized", "Error: Not logged in or invalid token", "text");
            Assert.AreEqual("401 Unauthorized", reply.Status);
            Assert.AreEqual("Error: Not logged in or invalid token", reply.Data);
        }
        public void TryTradeInvalidToken()
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings/1", "HTTP/1.1", "\"test10\"", "teasdst1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            // return new ServerReply(req.Protocol, "401 Unauthorized", "Error: Not logged in or invalid token", "text");
            Assert.AreEqual("401 Unauthorized", reply.Status);
            Assert.AreEqual("Error: Not logged in or invalid token", reply.Data);
        }
        public void ShowScoreBoardInvalidToken()
        {
            RequestKontext req   = new RequestKontext("GET", "/stats", "HTTP/1.1", "", "asd");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "401 Unauthorized", "Error: Not logged in or invalid token", "text");
            Assert.AreEqual("401 Unauthorized", reply.Status);
            Assert.AreEqual("Error: User is not logged in / Invalid Token!", reply.Data);
        }
        public void Trade()
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings/1", "HTTP/1.1", "\"test10\"", "test1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "200 OK", "Treaded successfully!", "text");
            Assert.AreEqual("200 OK", reply.Status);
            Assert.AreEqual("Treaded successfully!", reply.Data);
        }
示例#21
0
        public void EditPlayerDataOfSomeoneElse()  //NOt possible
        {
            RequestKontext req   = new RequestKontext("PUT", "/users/testadmin", "HTTP/1.1", "{\"Name\": \"Test Admin\",  \"Bio\": \"me playin...\", \"Email\": \"[email protected]\"}", "test1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "401 Unauthorized", "Error: You can't change the data of someone else!", "text");
            Assert.AreEqual("401 Unauthorized", reply.Status);
            Assert.AreEqual("Error: You can't change the data of someone else!", reply.Data);
        }
        public void TryTradeWithWrongCard()
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings/1", "HTTP/1.1", "\"test6\"", "test1");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "409 Conflict", "Error: This Card doesn't match the required Card!", "text");
            Assert.AreEqual("409 Conflict", reply.Status);
            Assert.AreEqual("Error: This Card doesn't match the required Card!", reply.Data);
        }
        public void CreatePackageNotAdmin()  // NOt an admin
        {
            RequestKontext req2   = new RequestKontext("POST", "/packages", "HTTP/1.1", "[{\"Id\":\"test1\", \"Name\":\"WaterGoblin\", \"Damage\": 10.0}, {\"Id\":\"test2\", \"Name\":\"Dragon\", \"Damage\": 50.0}, {\"Id\":\"test3\", \"Name\":\"WaterSpell\", \"Damage\": 20.0}, {\"Id\":\"test4\", \"Name\":\"Ork\", \"Damage\": 45.0}, {\"Id\":\"test5\", \"Name\":\"FireSpell\", \"Damage\": 25.0}]", "test1");
            ServerReply    reply2 = ServerReply.HandlingRequest(req2);

            Assert.IsNotNull(reply2);
            //return new ServerReply(req.Protocol, "401 Unauthorized", "Error: You are not authorized!", "text");
            Assert.AreEqual("401 Unauthorized", reply2.Status);
            Assert.AreEqual("Error: You are not authorized!", reply2.Data);
        }
        public void CreatePackageCardsAlreadyInStore()  // should not be added in store cause already exists
        {
            RequestKontext req2   = new RequestKontext("POST", "/packages", "HTTP/1.1", "[{\"Id\":\"test1\", \"Name\":\"WaterGoblin\", \"Damage\": 10.0}, {\"Id\":\"test2\", \"Name\":\"Dragon\", \"Damage\": 50.0}, {\"Id\":\"test3\", \"Name\":\"WaterSpell\", \"Damage\": 20.0}, {\"Id\":\"test4\", \"Name\":\"Ork\", \"Damage\": 45.0}, {\"Id\":\"test5\", \"Name\":\"FireSpell\", \"Damage\": 25.0}]", "testadmin");
            ServerReply    reply2 = ServerReply.HandlingRequest(req2);

            Assert.IsNotNull(reply2);
            //return new ServerReply(req.Protocol, "409 Conflict", "Error: One or more cards already exists in Store!", "text");
            Assert.AreEqual("409 Conflict", reply2.Status);
            Assert.AreEqual("Error: One or more cards already exists in Store!", reply2.Data);
        }
        public void TryTradeWithYourself()
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings/1", "HTTP/1.1", "\"test3\"", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "409 Conflict", "Error: Can't trade with yourself!", "text");
            Assert.AreEqual("409 Conflict", reply.Status);
            Assert.AreEqual("Error: Can't trade with yourself!", reply.Data);
        }
        public void CreatePackageEmptyPayload()  // No Session Created
        {
            RequestKontext req   = new RequestKontext("POST", "/packages", "HTTP/1.1", "", "");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "204 No Content", "Error: No Content", "text");
            Assert.AreEqual("204 No Content", reply.Status);
            Assert.AreEqual("Error: No Content", reply.Data);
        }
        public void CreateDeal()
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings", "HTTP/1.1", "{\"Id\": \"1\", \"CardToTrade\": \"test5\", \"Type\": \"spell\", \"MinimumDamage\": 15}", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);

            Assert.AreEqual("201 Created", reply.Status);
            Assert.AreEqual("Treade Created", reply.Data);
        }
        public void CreateDealWithInvalidToken() //should fail
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings", "HTTP/1.1", "{\"Id\": \"1\", \"CardToTrade\": \"test5\", \"Type\": \"spell\", \"MinimumDamage\": 15}", "asdf");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "401 Unauthorized", "Error: Not logged in or invalid token", "text");
            Assert.AreEqual("401 Unauthorized", reply.Status);
            Assert.AreEqual("Error: Not logged in or invalid token", reply.Data);
        }
        public void CreateDealWithNotObtainedCard() //should fail
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings", "HTTP/1.1", "{\"Id\": \"1\", \"CardToTrade\": \"asddwasd-sdgsd\", \"Type\": \"spell\", \"MinimumDamage\": 15}", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "409 Conflict", "Error: User doesnt own this card!", "text");
            Assert.AreEqual("409 Conflict", reply.Status);
            Assert.AreEqual("Error: User doesnt own this card!", reply.Data);
        }
        public void CreateDealWithCardInDeck() //should fail
        {
            RequestKontext req   = new RequestKontext("POST", "/tradings", "HTTP/1.1", "{\"Id\": \"1\", \"CardToTrade\": \"test1\", \"Type\": \"spell\", \"MinimumDamage\": 15}", "testadmin");
            ServerReply    reply = ServerReply.HandlingRequest(req);

            Assert.IsNotNull(reply);
            //return new ServerReply(req.Protocol, "409 Conflict", "Error: User is not allowed to have the card in his deck!", "text");
            Assert.AreEqual("409 Conflict", reply.Status);
            Assert.AreEqual("Error: User is not allowed to have the card in his deck!", reply.Data);
        }
 internal ArticleNotFoundEventArgs(ServerReply reply, string messageId, ulong articleId)
     : base(reply)
 {
     MessageId = messageId;
 }
示例#32
0
 internal NntpClientEventArgs(ServerReply reply)
 {
     this.reply = reply;
 }