Пример #1
0
        public async void testUpdateTimer()
        {
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _projectsEnv._stringDict.GetValueOrDefault("token"));
            var timer = new UpdateTimerDto
            {
                label     = "TA",
                name      = "test111",
                timerType = TIMER_TYPE.STOPWATCH
            };
            var expectedTimer = new GetTimerDto
            {
                label         = timer.label,
                timerType     = timer.timerType.Value,
                name          = timer.name,
                countDownInfo = new GetCountDownInfoDto {
                    breakInterval   = null,
                    breakTime       = 0,
                    longerBreakTime = null,
                    overTime        = 0,
                    workTime        = 0
                },
                userId = _projectsEnv._parsedToken.Claims.FirstOrDefault(claim => claim.Type == "nameid").Value
            };

            // Act
            var actualResponseTimer = await client
                                      .testSuccessPutAsync <GetTimerDto, UpdateTimerDto>($"/api/timers/{ _projectsEnv._stringDict.GetValueOrDefault("timerId")}", 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();
        }
Пример #2
0
        public async Task <ActionResult <ControllerResponse <GetTimerDto> > > update(string id, UpdateTimerDto timerIn)
        {
            string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier).ToString();

            var timer = await _timerService.getByIdAsync(id);

            if (timer.userId != userId)
            {
                throw new UnauthorizedAccessException("Timer don't belong to you");
            }
            timer = _mapper.Map <UpdateTimerDto, Timer>(timerIn, timer);
            await _timerService.updateAsync(id, timer);

            return(Ok(new ControllerResponse <GetTimerDto>
            {
                data = _mapper.Map <GetTimerDto>(timer)
            }));
        }