public async void Create() { var mock = new ServiceMockFacade <IBadgeRepository>(); var model = new ApiBadgeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Badge>())).Returns(Task.FromResult(new Badge())); var service = new BadgeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBadgeMapperMock, mock.DALMapperMockFactory.DALBadgeMapperMock); CreateResponse <ApiBadgeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBadgeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Badge>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IBadgeService, IBadgeRepository>(); var model = new ApiBadgeServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Badge>())).Returns(Task.FromResult(new Badge())); var service = new BadgeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Object, mock.DALMapperMockFactory.DALBadgeMapperMock); CreateResponse <ApiBadgeServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBadgeServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Badge>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <BadgeCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IBadgeService, IBadgeRepository>(); var model = new ApiBadgeServerRequestModel(); var validatorMock = new Mock <IApiBadgeServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiBadgeServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new BadgeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALBadgeMapperMock); CreateResponse <ApiBadgeServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBadgeServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <BadgeCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }