public async void Delete_Errors() { var mock = new ServiceMockFacade <IArtistRepository>(); var model = new ApiArtistServerRequestModel(); var validatorMock = new Mock <IApiArtistServerRequestModelValidator>(); 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 ArtistService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALArtistMapperMock, mock.DALMapperMockFactory.DALBankAccountMapperMock, mock.DALMapperMockFactory.DALEmailMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); 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 <ArtistDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public virtual async Task <IActionResult> Create([FromBody] ApiArtistServerRequestModel model) { CreateResponse <ApiArtistServerResponseModel> result = await this.ArtistService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Artists/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiArtistServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiArtistServerRequestModel> patch) { var record = await this.ArtistService.Get(id); if (record == null) { return(null); } else { ApiArtistServerRequestModel request = this.ArtistModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void MapServerResponseToRequest() { var mapper = new ApiArtistServerModelMapper(); var model = new ApiArtistServerResponseModel(); model.SetProperties(1, "A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", "A", "A", "A", "A", "A"); ApiArtistServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.AspNetUserId.Should().Be("A"); response.Bio.Should().Be("A"); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Facebook.Should().Be("A"); response.Name.Should().Be("A"); response.SoundCloud.Should().Be("A"); response.Twitter.Should().Be("A"); response.Venmo.Should().Be("A"); response.Website.Should().Be("A"); }
public void CreatePatch() { var mapper = new ApiArtistServerModelMapper(); var model = new ApiArtistServerRequestModel(); model.SetProperties("A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", "A", "A", "A", "A", "A"); JsonPatchDocument <ApiArtistServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiArtistServerRequestModel(); patch.ApplyTo(response); response.AspNetUserId.Should().Be("A"); response.Bio.Should().Be("A"); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Facebook.Should().Be("A"); response.Name.Should().Be("A"); response.SoundCloud.Should().Be("A"); response.Twitter.Should().Be("A"); response.Venmo.Should().Be("A"); response.Website.Should().Be("A"); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiArtistServerRequestModel model) { ApiArtistServerRequestModel request = await this.PatchModel(id, this.ArtistModelMapper.CreatePatch(model)) as ApiArtistServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiArtistServerResponseModel> result = await this.ArtistService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void Create_NoErrors() { var mock = new ServiceMockFacade <IArtistRepository>(); var model = new ApiArtistServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Artist>())).Returns(Task.FromResult(new Artist())); var service = new ArtistService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ArtistModelValidatorMock.Object, mock.DALMapperMockFactory.DALArtistMapperMock, mock.DALMapperMockFactory.DALBankAccountMapperMock, mock.DALMapperMockFactory.DALEmailMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); CreateResponse <ApiArtistServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.ArtistModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiArtistServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Artist>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ArtistCreatedNotification>(), It.IsAny <CancellationToken>())); }
public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IArtistService service = testServer.Host.Services.GetService(typeof(IArtistService)) as IArtistService; var model = new ApiArtistServerRequestModel(); model.SetProperties("B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B", "B", "B", "B", "B", "B"); CreateResponse <ApiArtistServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.ArtistDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiArtistServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiArtistServerRequestModel> patch) { ApiArtistServerResponseModel record = await this.ArtistService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiArtistServerRequestModel model = await this.PatchModel(id, patch) as ApiArtistServerRequestModel; UpdateResponse <ApiArtistServerResponseModel> result = await this.ArtistService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }