Esempio n. 1
0
        public async Task <Item> CreateItem(Guid id, NewItem item)
        {
            Player pelaaja = await _repository.Get(id);

            try
            {
                var  rand   = new Random();
                Item tavara = new Item();

                tavara.Id = Guid.NewGuid();

                tavara.Level = rand.Next(99 + 1);

                int arpa = rand.Next(3);

                if (arpa == 0)
                {
                    tavara.Itemtype = ItemType.POTION;
                }

                if (arpa == 1)
                {
                    tavara.Itemtype = ItemType.SHIELD;
                }

                if (arpa == 2)
                {
                    if (pelaaja.Level >= 3)
                    {
                        tavara.Itemtype = ItemType.SWORD;
                    }

                    else
                    {
                        //Console.WriteLine(errorHandling.errorString());


                        customExceptionFilterAttribute.OnException(InvalidLevelException(pelaaja.Level));
                    }
                }


                DateTime start = new DateTime(1995, 1, 1);
                int      range = (DateTime.Today - start).Days;

                DateTime now = DateTime.Now.AddDays(rand.Next(range));
                tavara.CreationDate = now;
                items.Add(tavara);
                pelaaja.Items.Add(tavara);

                await _repository.CreateItem(id, item);      //sano sit ku oot valmis testaamaan

                return(tavara);
            }

            catch (HttpStatusCodeException ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task Set_404_Response_StatusCode_When_NotFoundException_Occurs()
        {
            var notFoundException = new NotFoundException("Entity name");
            var exceptionContext  = CustomExceptionFilterTestHelper.GetExceptionContext(notFoundException);

            CustomExceptionFilterAttribute.OnException(exceptionContext);

            Assert.AreEqual((int)HttpStatusCode.NotFound, exceptionContext.HttpContext.Response.StatusCode);
        }