コード例 #1
0
        public async Task <IActionResult> AddNewEpisode([FromBody] CreateEpisodeModel createModel)
        {
            IEntityCreateResult identity = await _episodesService.CreateEpisodeAsync(createModel);

            await _databaseContext.SaveChangesAsync();

            int id = identity.GetId();

            string uri = $"episodes/{id}";

            return(Created(uri, id));
        }
コード例 #2
0
        public async Task <IEntityCreateResult> CreateCharacterAsync(ICreateCharacterModel createModel)
        {
            if (createModel is null)
            {
                throw new ArgumentNullException(nameof(createModel));
            }

            await _createCharacterValidator.ValidateAndThrowAsync(createModel);

            Character characterToAdd = await _createCharacterFactory.CreateAsync(createModel);

            IEntityCreateResult identity = _characterRepository.Add(characterToAdd);

            return(identity);
        }
コード例 #3
0
        public async Task <IEntityCreateResult> CreateEpisodeAsync(ICreateEpisodeModel createModel)
        {
            if (createModel is null)
            {
                throw new ArgumentNullException(nameof(createModel));
            }

            await _createEpisodeValidator.ValidateAndThrowAsync(createModel);

            Episode episodeToAdd = _createEpisodeFactory.Create(createModel);

            IEntityCreateResult identity = _episodeRepository.Add(episodeToAdd);

            return(identity);
        }
コード例 #4
0
        public void Add_Should_Return_Entity_Create_Result_Wih_Pointer_To_Key()
        {
            // Arrange
            int expectedId = 5;

            var element = new TestModel()
            {
                Key = expectedId
            };

            _databaseContextMock.Setup(x => x.Set <TestModel>())
            .Returns(new Mock <DbSet <TestModel> >().Object);

            // Assert
            IEntityCreateResult result = _repository.Add(element);

            // Assert
            result.GetId().Should().Be(expectedId);
        }