Esempio n. 1
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPersonTypeService, IPersonTypeRepository>();
            var model         = new ApiPersonTypeServerRequestModel();
            var validatorMock = new Mock <IApiPersonTypeServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPersonTypeServerRequestModel>())).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 PersonType()));
            var service = new PersonTypeService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                validatorMock.Object,
                                                mock.DALMapperMockFactory.DALPersonTypeMapperMock,
                                                mock.DALMapperMockFactory.DALCallPersonMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPersonTypeServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PersonTypeUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 2
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IPersonTypeService, IPersonTypeRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PersonType>(null));
            var service = new PersonTypeService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.PersonTypeModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALPersonTypeMapperMock,
                                                mock.DALMapperMockFactory.DALCallPersonMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Esempio n. 3
0
        public async void CallPersonsByPersonTypeId_Not_Exists()
        {
            var mock = new ServiceMockFacade <IPersonTypeService, IPersonTypeRepository>();

            mock.RepositoryMock.Setup(x => x.CallPersonsByPersonTypeId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <CallPerson> >(new List <CallPerson>()));
            var service = new PersonTypeService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.PersonTypeModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALPersonTypeMapperMock,
                                                mock.DALMapperMockFactory.DALCallPersonMapperMock);

            List <ApiCallPersonServerResponseModel> response = await service.CallPersonsByPersonTypeId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.CallPersonsByPersonTypeId(default(int), It.IsAny <int>(), It.IsAny <int>()));
        }
Esempio n. 4
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IPersonTypeService, IPersonTypeRepository>();
            var records = new List <PersonType>();

            records.Add(new PersonType());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new PersonTypeService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.PersonTypeModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALPersonTypeMapperMock,
                                                mock.DALMapperMockFactory.DALCallPersonMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Esempio n. 5
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IPersonTypeService, IPersonTypeRepository>();
            var model = new ApiPersonTypeServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PersonTypeService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.PersonTypeModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALPersonTypeMapperMock,
                                                mock.DALMapperMockFactory.DALCallPersonMapperMock);

            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.PersonTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PersonTypeDeletedNotification>(), It.IsAny <CancellationToken>()));
        }