Exemple #1
0
        public async Task <OutlawDTO> AddOutlaw(OutlawDTO outlaw)
        {
            try
            {
                Outlaw newOutlaw = _mapper.Map <Outlaw>(outlaw);
                newOutlaw.GangOutlaws = new List <GangOutlaw>();
                if (outlaw.Gangs != null)
                {
                    foreach (var GangId in outlaw.Gangs)
                    {
                        newOutlaw.GangOutlaws.Add(new GangOutlaw()
                        {
                            GangId = GangId
                        });
                    }
                }

                await _outlawRepository.AddOutlaw(newOutlaw);

                return(outlaw);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public async Task <ActionResult <OutlawDTO> > AddOutlawAsync(OutlawDTO outlaw)
 {
     try {
         return(new OkObjectResult(await _outlawService.AddOutlaw(outlaw)));
     }
     catch (Exception ex) {
         throw new ArgumentException(ex.Message);
     }
 }
        public async Task Add_Outlaw()
        {
            var outlaw = new OutlawDTO()
            {
                OutlawUri    = "https://dbpedia.org/resource/Jesse_James",
                Name         = "Henry Newton Brown",
                BirthDate    = null,
                DeathDate    = "1884-04-30",
                DeathCauseId = Guid.Parse("b82f1cde-d0bc-46f8-bf90-f8092349a861"),
                Gangs        = null,
                Description  = "Henry Newton Brown (1857 – April 30, 1884) was an American Old West gunman who played the roles of both lawman and outlaw during his life. Brown was raised in Cold Springs Township, in Phelps County, ten miles south of Rolla, Missouri. An orphan, he lived there with his uncle Jasper and aunt Aldamira Richardson until the age of seventeen, when he left home and headed west. He drifted through various cowboy jobs in Colorado and Texas, supposedly killing a man in a gunfight in the Texas Panhandle."
            };

            string json     = JsonConvert.SerializeObject(outlaw);
            var    response = await Client.PostAsync("/outlaw", new StringContent(json, Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var createdOutlaw = JsonConvert.DeserializeObject <OutlawDTO>(await response.Content.ReadAsStringAsync());

            Assert.NotNull(createdOutlaw);
            Assert.Equal <string>("Henry Newton Brown", createdOutlaw.Name);
        }