public async Task <ActionResult <ControllerResponse <GetTimerDto> > > create(CreateTimerDto newTimer) { string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier).ToString(); var timer = _mapper.Map <Timer>(newTimer); timer.userId = userId; timer.dateCreated = DateTime.UtcNow; await _timerService.createAsync(timer); return(Created(new Uri($"{Request.Path}/{timer.id}", UriKind.Relative), new ControllerResponse <GetTimerDto> { data = _mapper.Map <GetTimerDto>(timer) })); }
public async void testAddTimer() { var client = _factory.CreateClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _projectsEnv._stringDict.GetValueOrDefault("token")); var timer = new CreateTimerDto { label = "TE", name = "test1", countDownInfo = new CreateCountDownInfoDto { breakTime = 10, overTime = 5, workTime = 45 }, timerType = TIMER_TYPE.TIMER }; var expectedTimer = new GetTimerDto { label = timer.label, timerType = timer.timerType.Value, name = timer.name, countDownInfo = new GetCountDownInfoDto { breakInterval = timer.countDownInfo.breakInterval, breakTime = timer.countDownInfo.breakTime, longerBreakTime = timer.countDownInfo.longerBreakTime, overTime = timer.countDownInfo.overTime, workTime = timer.countDownInfo.workTime }, userId = _projectsEnv._parsedToken.Claims.FirstOrDefault(claim => claim.Type == "nameid").Value }; // Act var actualResponseTimer = await client.testSuccessPostAsync <GetTimerDto, CreateTimerDto>("/api/timers", timer); // Assert expectedTimer.WithDeepEqual(actualResponseTimer.data) .SkipDefault <DateTime>() .IgnoreSourceProperty(x => x.id) .Assert(); // Act var actualResponseTimerGet = await client.testSuccessGetAsync <GetTimerDto>("/api/timers/" + actualResponseTimer.data.id); expectedTimer.id = actualResponseTimer.data.id; // Assert expectedTimer.WithDeepEqual(actualResponseTimerGet.data) .SkipDefault <DateTime>() .Assert(); _projectsEnv._stringDict.Add("timerId", actualResponseTimer.data.id); }