Esempio n. 1
0
        private async Task AddOneFilmAsync(string title, short year, short length)
        {
            var f      = new BaseFilmDto(title, year, length);
            var result = await PostAsync <OperationResult, BaseFilmDto>("Film", "Add", f);

            Debug.Assert(result.Status.Value == 0);
        }
Esempio n. 2
0
        public override async Task <OperationStatus> UpdateAsync(FilmDto dto)
        {
            var b           = new BaseFilmDto(dto.Title, dto.Year, dto.Length);
            var jsonContent = new StringContent(JsonConvert.SerializeObject(b), Encoding.UTF8, "application/json");
            var status      = await _client.PutAsync(_route, jsonContent);

            return(StatusFromResponse(status));
        }
Esempio n. 3
0
        public async System.Threading.Tasks.Task AddReturnsPrettyWomanAsync()
        {
            // Arrange
            var title  = "Avanti!";
            var year   = (short)1972;
            var length = (short)140;
            var dto    = new BaseFilmDto(title, year, length);

            // Act
            var result1 = await PostAsync <OperationStatus, BaseFilmDto>("Film", "Add", dto);

            var result2 = await GetResultAsync <KeyedFilmDto>("Film", "Result");

            // Assert
            Assert.Equal(OperationStatus.OK.Value, result1.Value);
            Assert.Equal(title, result2.Title);
            Assert.Equal(year, result2.Year);
            Assert.Equal(length, result2.Length);
        }
Esempio n. 4
0
        public override async Task <OperationStatus> AddAsync(FilmDto dto)
        {
            var result      = OperationStatus.OK;
            var b           = new BaseFilmDto(dto.Title, dto.Year, dto.Length);
            var jsonContent = new StringContent(JsonConvert.SerializeObject(b), Encoding.UTF8, "application/json");
            var response    = await _client.PostAsync(_route, jsonContent);

            result = StatusFromResponse(response);
            if (result == OperationStatus.OK)
            {
                var key       = _keyService.ConstructFilmKey(dto.Title, dto.Year);
                var response1 = await _client.GetAsync($"{_route}/{key}");

                var stringResponse = await response1.Content.ReadAsStringAsync();

                _addResult     = JsonConvert.DeserializeObject <FilmDto>(stringResponse);
                _addResult.Key = _keyService.ConstructFilmKey(_addResult.Title, _addResult.Year);
            }
            else
            {
                _addResult = null;
            }
            return(result);
        }
Esempio n. 5
0
 public async Task <OperationStatus> Put([FromBody] BaseFilmDto model)
 {
     return(await _service.UpdateAsync(model));
 }
Esempio n. 6
0
 public async Task <OperationResult <IKeyedDto> > PostAsync([FromBody] BaseFilmDto model)
 {
     return(await _service.AddAsync(model));
 }