public async Task <TrainingLogModel> Post([FromBody] CreateTrainingLogModel requestModel)
        {
            var item = await _query.Create(requestModel);

            var model = _mapper.Map <TrainingLogModel>(item);

            return(model);
        }
        public async Task <Traininglog> Create(CreateTrainingLogModel model)
        {
            var trainingLog = new Traininglog
            {
                UserId      = _securityContext.User.Id,
                Date        = model.Date,
                Description = model.Description,
                Rating      = model.Rating,
                Comment     = model.Comment
            };

            _uow.Add(trainingLog);
            await _uow.CommitAsync();

            return(trainingLog);
        }
        public async Task CreateShouldSaveNew()
        {
            var model = new CreateTrainingLogModel
            {
                Date        = DateTime.Now,
                Description = _random.Next().ToString(),
                Rating      = _random.Next(),
                Comment     = _random.Next().ToString()
            };

            var result = await _query.Create(model);

            result.Date.Should().Be(model.Date);
            result.Description.Should().Be(model.Description);
            result.Rating.Should().Be(model.Rating);
            result.Comment.Should().Be(model.Comment);
            result.UserId.Should().Be(_currentUser.Id);

            _uow.Verify(x => x.Add(result));
            _uow.Verify(x => x.CommitAsync());
        }
Пример #4
0
        public async Task <TrainingLogModel> CreateNew()
        {
            var requestItem = new CreateTrainingLogModel()
            {
                Rating      = _random.Next(),
                Comment     = _random.Next().ToString(),
                Date        = DateTime.Now.AddMinutes(-15),
                Description = _random.Next().ToString()
            };

            var createdItem = await _client.PostAsync <TrainingLogModel>("api/Traininglog", requestItem);

            //createdItem.Id.Should().BeGreaterThan(0);
            createdItem.Rating.Should().Be(requestItem.Rating);
            createdItem.Comment.Should().Be(requestItem.Comment);
            createdItem.Date.Should().Be(requestItem.Date);
            createdItem.Description.Should().Be(requestItem.Description);
            createdItem.Username.Should().Be("admin admin");

            return(createdItem);
        }