Пример #1
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPenService, IPenRepository>();
            var model         = new ApiPenServerRequestModel();
            var validatorMock = new Mock <IApiPenServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPenServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Pen()));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.MediatorMock.Object,
                                         mock.RepositoryMock.Object,
                                         validatorMock.Object,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            UpdateResponse <ApiPenServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPenServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PenUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Пример #2
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IPenService, IPenRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Pen>(null));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.MediatorMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            ApiPenServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Пример #3
0
        public async void PetsByPenId_Not_Exists()
        {
            var mock = new ServiceMockFacade <IPenService, IPenRepository>();

            mock.RepositoryMock.Setup(x => x.PetsByPenId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <Pet> >(new List <Pet>()));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.MediatorMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            List <ApiPetServerResponseModel> response = await service.PetsByPenId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.PetsByPenId(default(int), It.IsAny <int>(), It.IsAny <int>()));
        }
Пример #4
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IPenRepository>();
            var record = new Pen();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.BOLMapperMockFactory.BOLPenMapperMock,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.BOLMapperMockFactory.BOLPetMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            ApiPenResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Пример #5
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IPenService, IPenRepository>();
            var records = new List <Pen>();

            records.Add(new Pen());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.MediatorMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            List <ApiPenServerResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Пример #6
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPenRepository>();
            var model = new ApiPenRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pen>())).Returns(Task.FromResult(new Pen()));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.BOLMapperMockFactory.BOLPenMapperMock,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.BOLMapperMockFactory.BOLPetMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PenModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPenRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pen>()));
        }
Пример #7
0
        public async void Pets_Exists()
        {
            var mock    = new ServiceMockFacade <IPenRepository>();
            var records = new List <Pet>();

            records.Add(new Pet());
            mock.RepositoryMock.Setup(x => x.Pets(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.BOLMapperMockFactory.BOLPenMapperMock,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.BOLMapperMockFactory.BOLPetMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            List <ApiPetResponseModel> response = await service.Pets(default(int));

            response.Should().NotBeEmpty();
            mock.RepositoryMock.Verify(x => x.Pets(default(int), It.IsAny <int>(), It.IsAny <int>()));
        }
Пример #8
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IPenRepository>();
            var model = new ApiPenRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.BOLMapperMockFactory.BOLPenMapperMock,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.BOLMapperMockFactory.BOLPetMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.PenModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Пример #9
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IPenService, IPenRepository>();
            var model = new ApiPenServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.MediatorMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.PenModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PenDeletedNotification>(), It.IsAny <CancellationToken>()));
        }