예제 #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 Update()
        {
            var mock  = new ServiceMockFacade <IPenRepository>();
            var model = new ApiPenRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pen>())).Returns(Task.FromResult(new Pen()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).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);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PenModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPenRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Pen>()));
        }