public void UpdatesWithValidData()
        {
            DateTime dtInitial = new DateTime(2020, 1, 1);
            DateTime dtChanged = new DateTime(2020, 2, 2);

            Entry entry;

            _userService.SetUser(_regularUser1);
            _context.Add(entry = new Entry()
            {
                Id = 123, Date = dtInitial, UserId = _regularUser1.Id, DistanceInMeters = 55, TimeInSeconds = 99
            });
            _context.SaveChanges();

            _controller.Update(entry.Id, new EntryDataDTO()
            {
                DistanceInMeters = entry.DistanceInMeters + 101,
                TimeInSeconds    = entry.TimeInSeconds + 102,
                UserId           = entry.UserId,
                Date             = dtChanged
            });

            var res = ((_controller.Get(dtChanged, dtChanged, _regularUser1.Id) as OkObjectResult).Value as IEnumerable <EntryDTO>).ToArray();

            Assert.AreEqual(123, res.Single().Id);
            Assert.AreEqual(156, res.Single().DistanceInMeters);
            Assert.AreEqual(201, res.Single().TimeInSeconds);
            Assert.AreEqual(dtChanged, res.Single().Date);
        }
Beispiel #2
0
        public async Task Update_EntryNotFound_ReturnsBadRequest()
        {
            _service.Setup(s =>
                           s.Update(It.IsAny <EntryDto>()))
            .ReturnsAsync(() => null);

            _controller = new EntriesController(_logger, _service.Object);

            var result = await _controller.Update(new EntryDto());

            result.Should().BeOfType <BadRequestResult>();
        }
Beispiel #3
0
        public async Task Update_EntryFound_Updated_ReturnsOk()
        {
            var entry = new EntryDto();

            _service.Setup(s =>
                           s.Update(It.IsAny <EntryDto>()))
            .ReturnsAsync(entry);

            _controller = new EntriesController(_logger, _service.Object);

            var result = await _controller.Update(entry);

            result.Should().BeOfType <OkObjectResult>();
        }