Esempio n. 1
0
        public async Task <KindResponse> AddKindAsync(AddKindRequest request)
        {
            Kind kind = await _mapper.From(request).AdaptToTypeAsync <Kind>();

            Kind result = _kindRepository.Add(kind);

            int affected = await _kindRepository.UnitOfWork.SaveChangesAsync();

            return(_mapper.Map <KindResponse>(result));
        }
Esempio n. 2
0
        public async Task AddKind_should_return_the_expected_kind()
        {
            //Arrange
            AddKindRequest expectedKind = new AddKindRequest()
            {
                KindName = GenData.Create <string>()
            };

            KindService sut = new KindService(KindRepo, VideoRepo, Mapper);

            //Act
            KindResponse result = await sut.AddKindAsync(expectedKind);

            //Assert
            //expectedKind.Should().BeEquivalentTo(result, o =>
            //    o.Excluding(x => x.KindId));
            Assert.Equal(expectedKind.KindName, result.Name);
        }
Esempio n. 3
0
        public async Task Add_should_create_new_kind()
        {
            //Arrange
            AddKindRequest request = new AddKindRequest()
            {
                KindName = "new kind"
            };

            HttpClient    client      = Factory.CreateClient();
            StringContent httpContent = new StringContent(JsonConvert.SerializeObject(request),
                                                          Encoding.UTF8, "application/json");

            //Act
            HttpResponseMessage response = await client.PostAsync($"{Url}", httpContent);

            //Assert
            response.EnsureSuccessStatusCode();
            response.Headers.Location.Should().NotBeNull();
        }
Esempio n. 4
0
        public async Task <IActionResult> Post(AddKindRequest request)
        {
            KindResponse result = await KindService.AddKindAsync(request);

            return(CreatedAtAction(nameof(GetById), new { id = result.KindId }, null));
        }