Exemplo n.º 1
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IDeviceService, IDeviceRepository>();

            var model = new ApiDeviceServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Device>())).Returns(Task.FromResult(new Device()));
            var service = new DeviceService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.DeviceModelValidatorMock.Object,
                                            mock.DALMapperMockFactory.DALDeviceMapperMock,
                                            mock.DALMapperMockFactory.DALDeviceActionMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.DeviceModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDeviceServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Device>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <DeviceCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Exemplo n.º 2
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IDeviceActionService, IDeviceActionRepository>();
            var model         = new ApiDeviceActionServerRequestModel();
            var validatorMock = new Mock <IApiDeviceActionServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new DeviceActionService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  validatorMock.Object,
                                                  mock.DALMapperMockFactory.DALDeviceActionMapperMock);

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

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