public ActionResult <Species> Create([FromBody] Species species)
 {
     try
     {
         return(Ok(_serv.Create(species)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
        public async Task <ActionResult <Species> > Create(SpeciesDto species)
        {
            var newSpecies = new Species
            {
                Name      = species.Name,
                CatchRate = species.CatchRate
            };
            var result = await _speciesService.Create(newSpecies);

            return(CreatedAtRoute("GetSpecies", new { id = result.ID }, newSpecies));
        }
示例#3
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISpeciesRepository>();
            var model = new ApiSpeciesRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Species>())).Returns(Task.FromResult(new Species()));
            var service = new SpeciesService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLSpeciesMapperMock,
                                             mock.DALMapperMockFactory.DALSpeciesMapperMock,
                                             mock.BOLMapperMockFactory.BOLBreedMapperMock,
                                             mock.DALMapperMockFactory.DALBreedMapperMock);

            CreateResponse <ApiSpeciesResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpeciesRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Species>()));
        }
示例#4
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ISpeciesService, ISpeciesRepository>();

            var model = new ApiSpeciesServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Species>())).Returns(Task.FromResult(new Species()));
            var service = new SpeciesService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALSpeciesMapperMock,
                                             mock.DALMapperMockFactory.DALBreedMapperMock);

            CreateResponse <ApiSpeciesServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpeciesServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Species>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SpeciesCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
示例#5
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ISpeciesService, ISpeciesRepository>();
            var model         = new ApiSpeciesServerRequestModel();
            var validatorMock = new Mock <IApiSpeciesServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiSpeciesServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new SpeciesService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             validatorMock.Object,
                                             mock.DALMapperMockFactory.DALSpeciesMapperMock,
                                             mock.DALMapperMockFactory.DALBreedMapperMock);

            CreateResponse <ApiSpeciesServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpeciesServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SpeciesCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }