Пример #1
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IVenueRepository>();
            var model = new ApiVenueRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new VenueService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.VenueModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLVenueMapperMock,
                                           mock.DALMapperMockFactory.DALVenueMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.VenueModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Пример #2
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IVenueService, IVenueRepository>();
            var model = new ApiVenueServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new VenueService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.VenueModelValidatorMock.Object,
                                           mock.DALMapperMockFactory.DALVenueMapperMock);

            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.VenueModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VenueDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Пример #3
0
        public void Create_Correct_Venue()
        {
            //Arrange
            var venueDTO = new VenueDTO()
            {
                Name = "name", Description = "test", Address = "asd", Phone = "123"
            };

            //Act
            service.Create(venueDTO);
            var res = service.GetByName("name");

            //Assert
            Assert.AreEqual(venueDTO.Name, res.Name);

            service.Delete(res.Id);
        }
Пример #4
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IVenueService, IVenueRepository>();
            var model         = new ApiVenueServerRequestModel();
            var validatorMock = new Mock <IApiVenueServerRequestModelValidator>();

            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 VenueService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           validatorMock.Object,
                                           mock.DALMapperMockFactory.DALVenueMapperMock);

            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 <VenueDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }