public async Task <NetflixTitleDto> Create(NetflixTitleDto dto) { try { dto.Id = Guid.NewGuid(); var netFlixTitleDomain = new NetflixTitleBuilder() .WithTitle(dto.Title) .WithDirector(dto.Director) .WithCountry(dto.Country) .WithDurationMin(dto.DurationMin) .WithCast(dto.Cast) .WithId(dto.Id) .Build(); if (!netFlixTitleDomain.IsValid()) { return(new NetflixTitleDto { ErrorMessage = netFlixTitleDomain.ErrorMessages.FirstOrDefault() }); } await _cassandraContext.InsertAsync(netFlixTitleDomain); } catch (Exception ex) { dto.ErrorMessage = $"Exceção não tratada: {ex.Message}"; } return(dto); }
public async Task Create_Exception() { var dto = new NetflixTitleDto { Director = "director", Country = "country", DurationMin = 1, Cast = "cast" }; var mockService = MockExceptionForCreate(); var result = await mockService.Create(dto); Assert.False(result.IsValid()); }
public async Task Create_DomainIsValid() { var dto = new NetflixTitleDto { Director = "director", Country = "country", DurationMin = 1, Cast = "cast", Title = "title" }; var mockService = MockServiceForCreate(); var result = await mockService.Create(dto); Assert.True(result.IsValid()); }
public async Task <IActionResult> Post(NetflixTitleDto dto) => Ok(await _createNetflixTitleServices.Create(dto));