Пример #1
0
        public async Task <IResponse> Create([FromBody] PetModel pet)
        {
            var response = await PetService.Create(pet);

            ReplaceUrlTokens(response);
            SetResponseCode(response.Result);
            return(response);
        }
Пример #2
0
        public ActionResult <Pet> Create(string ownerID, string type)
        {
            Pet newPet = _petService.Create(ownerID, type);

            if (newPet == null)
            {
                return(BadRequest());
            }
            return(CreatedAtRoute("GetPet", new { id = newPet.Id.ToString() }, newPet));
        }
Пример #3
0
        public void CreatePet_NullName_ThrowsInvalidDataException()
        {
            Mock <IPetRepository> petRepository = new Mock <IPetRepository>();
            PetService            petService    = new PetService(petRepository.Object);
            Pet pet = new Pet()
            {
                Price = 1, Birthdate = DateTime.Now, SoldDate = DateTime.Now, Type = AnimalType.All
            };

            Action actual = () => petService.Create(pet);

            Assert.Throws <InvalidDataException>(actual);
        }
Пример #4
0
        public void CreatePet_SpecifiedId_ThrowsNotSupportedException()
        {
            Mock <IPetRepository> petRepository = new Mock <IPetRepository>();
            PetService            petService    = new PetService(petRepository.Object);
            Pet pet = new Pet()
            {
                Id = 1
            };

            Action actual = () => petService.Create(pet);

            Assert.Throws <NotSupportedException>(actual);
        }
Пример #5
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPetRepository>();
            var model = new ApiPetRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pet>())).Returns(Task.FromResult(new Pet()));
            var service = new PetService(mock.LoggerMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PetModelValidatorMock.Object,
                                         mock.BOLMapperMockFactory.BOLPetMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock,
                                         mock.BOLMapperMockFactory.BOLSaleMapperMock,
                                         mock.DALMapperMockFactory.DALSaleMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPetRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pet>()));
        }
Пример #6
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IPetService, IPetRepository>();

            var model = new ApiPetServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pet>())).Returns(Task.FromResult(new Pet()));
            var service = new PetService(mock.LoggerMock.Object,
                                         mock.MediatorMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PetModelValidatorMock.Object,
                                         mock.DALMapperMockFactory.DALPetMapperMock,
                                         mock.DALMapperMockFactory.DALSaleMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.PetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPetServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pet>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PetCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Пример #7
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPetService, IPetRepository>();
            var model         = new ApiPetServerRequestModel();
            var validatorMock = new Mock <IApiPetServerRequestModelValidator>();

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

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPetServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PetCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Пример #8
0
 public void CreatePetWithoutOwnerTest()
 {
     _usersDB.DeleteMany(user => true);
     _petsDB.DeleteMany(pet => true);
     Assert.Null(_petService.Create("000000000000000000000000", "dog"));
 }
Пример #9
0
 public ActionResult <Pet> Create(Pet pet)
 {
     _petService.Create(pet);
     return(CreatedAtRoute("GetPet", new { id = pet.PetId.ToString() }, pet));
 }