public void UpdateListing() { using var _context = TestContext.GetContext(); var _mapper = TestMapper.GetTestMapper(); var _studioListingService = new StudioListingService(_context, _mapper); var update = new CreateUpdateStudioDto { Name = "Basil's Place", // updated name Description = "We are the best studio", IsBooked = false, Rate = 20 }; var response = _studioListingService.UpdateListing(2, update); Assert.IsType <ServiceResponse <StudioListingDto> >(response); Assert.IsType <StudioListingDto>(response.Data); Assert.Equal("Basil's Place", response.Data.Name); Assert.Equal("We are the best studio", response.Data.Description); Assert.False(response.Data.IsBooked); Assert.Equal(20, response.Data.Rate); Assert.NotEqual("The Hive", response.Data.Name); Assert.True(response.IsSuccess); }
public ServiceResponse <StudioListingDto> CreateListing(CreateUpdateStudioDto listing) { var studio = _mapper.Map <Studio>(listing); studio.CreatedOn = DateTime.UtcNow; studio.UpdatedOn = DateTime.UtcNow; try { _db.Studios.Add(studio); _db.SaveChanges(); return(new ServiceResponse <StudioListingDto> { Data = _mapper.Map <StudioListingDto>(studio), IsSuccess = true, Message = $"Successfully created studio {studio.Id} to database", Time = DateTime.UtcNow }); } catch (Exception ex) { return(new ServiceResponse <StudioListingDto> { Data = null, IsSuccess = false, Message = ex.Message, Time = DateTime.UtcNow }); } }
public void CreateListing() { using var _context = TestContext.GetContext(); var _mapper = TestMapper.GetTestMapper(); var _studioListingService = new StudioListingService(_context, _mapper); var newStudio = new CreateUpdateStudioDto { Name = "Chaos Records", Description = "The crazy studio", IsBooked = false, Rate = 23 }; var response = _studioListingService.CreateListing(newStudio); Assert.IsType <ServiceResponse <StudioListingDto> >(response); Assert.Equal("Chaos Records", response.Data.Name); Assert.Equal("The crazy studio", response.Data.Description); Assert.True(response.IsSuccess); }