public void ReturnsBadRequestWhenImageDeleteIsCalledWithNoImageId() { var serviceId = Randomm.Id(); var response = _classUnderTest.DeleteServiceImage(serviceId, null).Result as BadRequestObjectResult; response.StatusCode.Should().Be(400); }
public void PatchTaxonomyControllerActionCallsTheTaxonomysUseCase() { var requestParams = Randomm.Create <TaxonomyRequest>(); var requestId = Randomm.Id(); _classUnderTest.PatchTaxonomy(requestId, requestParams); _mockUseCase.Verify(uc => uc.ExecutePatch(It.Is <int>(p => p == requestId), It.Is <TaxonomyRequest>(p => p == requestParams)), Times.Once); }
public void ReturnsEmptyResponseWith200StatusIfImageIsDeleted() { var serviceId = Randomm.Id(); var imageId = Randomm.Id(); var response = _classUnderTest.DeleteServiceImage(serviceId, imageId).Result as OkResult; response.StatusCode.Should().Be(200); }
public void CallsImageDeleteMethodWhenImageDeleteIsCalled() { var serviceId = Randomm.Id(); var imageId = Randomm.Id(); _classUnderTest.DeleteServiceImage(serviceId, imageId); _mockServiceImageUseCase.Verify(siuc => siuc.ExecuteDelete(It.IsAny <int>(), It.IsAny <int>()), Times.Once); }
public void ImageDeleteActionCallsServicesGateway() { var serviceId = Randomm.Id(); var imageId = Randomm.Id(); var file = EntityHelpers.CreateFile(); _mockServicesGateway.Setup(sg => sg.GetFile(It.IsAny <int>())).ReturnsAsync(file); _classUnderTest.ExecuteDelete(serviceId, imageId); _mockServicesGateway.Verify(sg => sg.DeleteFileInfo(It.IsAny <int>(), It.IsAny <File>()), Times.Once); }
public void CallsGatewayPostAndThrowsErrorIfInvalidVocabularyIdProvided() { var taxonomy = Randomm.Create <TaxonomyRequest>(); taxonomy.VocabularyId = 0; var requestId = Randomm.Id();; _mockTaxonomyGateway.Setup(gw => gw.CreateTaxonomy(It.IsAny <Taxonomy>())).Returns(taxonomy.ToDomain()); _classUnderTest.Invoking(c => c.ExecuteCreate(taxonomy)).Should().Throw <InvalidOperationException>(); }
public void GivenAnIdWhenGetTaxonomyUseCaseIsCalledThenItCallsGetTaxonomyGatewayMethodAndPassesInThatId() { // arrange var id = Randomm.Id(); // act _classUnderTest.ExecuteGet(id); // assert _mockTaxonomiesGateway.Verify(g => g.GetTaxonomy(It.Is <int>(p => p == id)), Times.Once); }
public void GivenAValidIdWhenGetTaxonomyControllerMethodIsCalledThenItCallsTheUseCaseGetMethodWithThatId() { // arrange var id = Randomm.Id(); //irrelevant // act _classUnderTest.GetTaxonomy(id); // assert _mockUseCase.Verify(u => u.ExecuteGet(It.Is <int>(p => p == id)), Times.Once); }
public void PatchOrganisationUseCaseCallsGatewayPatchOrganisation() { var organisation = Randomm.Create <OrganisationRequest>(); var requestId = Randomm.Id(); _mockOrganisationsGateway.Setup(gw => gw.GetOrganisation(It.IsAny <int>())).Returns(organisation.ToDomain()); _mockOrganisationsGateway.Setup(gw => gw.PatchOrganisation(It.IsAny <OrganisationDomain>())).Returns(organisation.ToDomain()); _classUnderTest.ExecutePatch(requestId, organisation); _mockOrganisationsGateway.Verify(u => u.GetOrganisation(It.IsAny <int>()), Times.Once); _mockOrganisationsGateway.Verify(u => u.PatchOrganisation(It.IsAny <OrganisationDomain>()), Times.Once); }
public void PatchTaxonomyUseCaseCallsGatewayPatchTaxonomy() { var taxonomy = Randomm.Create <TaxonomyRequest>(); taxonomy.VocabularyId = 1; var requestId = Randomm.Id(); _mockTaxonomyGateway.Setup(gw => gw.PatchTaxonomy(It.IsAny <int>(), It.IsAny <Taxonomy>())).Returns(taxonomy.ToDomain()); _classUnderTest.ExecutePatch(requestId, taxonomy); _mockTaxonomyGateway.Verify(u => u.PatchTaxonomy(It.IsAny <int>(), It.IsAny <Taxonomy>()), Times.Once); }
public async Task Returns404IfNoMatchingService() { // act var requestUri = new Uri($"api/v1/services/{Randomm.Id(1, 10)}", UriKind.Relative); var response = Client.GetAsync(requestUri).Result; var content = response.Content; var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true); var actualService = JsonConvert.DeserializeObject <GetServiceResponse>(stringResponse); // assert response.StatusCode.Should().Be(404); }
public void PatchReturnsResponseWithStatus() { var expected = Randomm.Create <TaxonomyResponse>(); var id = Randomm.Id(); var reqParams = Randomm.Create <TaxonomyRequest>(); _mockUseCase.Setup(u => u.ExecutePatch(It.IsAny <int>(), It.IsAny <TaxonomyRequest>())).Returns(expected); var response = _classUnderTest.PatchTaxonomy(id, reqParams) as OkObjectResult; response.Should().NotBeNull(); response.StatusCode.Should().Be(200); response.Value.Should().BeEquivalentTo(expected); }
public void GivenSuccessfulGetTaxonomyGatewayCallWhenGatewayReturnsAValueThenTheUseCaseReturnsThatSameValue() { // arrange var id = Randomm.Id(); //irrelevant var gatewayResult = Randomm.Create <TaxonomyEntity>(); _mockTaxonomiesGateway.Setup(g => g.GetTaxonomy(It.IsAny <int>())).Returns(gatewayResult); // act var usecaseResult = _classUnderTest.ExecuteGet(id); // assert usecaseResult.Should().BeEquivalentTo(gatewayResult.ToResponse()); }
public void GivenIdThatDoesNotHaveAMatchWhenGetServiceGatewayMethodIsCalledThenItReturnsNull() { // arrange var services = EntityHelpers.CreateServices(); DatabaseContext.Services.AddRange(services); DatabaseContext.SaveChanges(); var id = Randomm.Id(); // act var gatewayResult = _classUnderTest.GetService(id); // assert gatewayResult.Should().BeNull(); }
public void GivenASuccessfulGetTaxonomyCallWhenUseCaseReturnsAValueThenControllerResponseWrapsUpThatValue() { // arrange var expectedValue = Randomm.Create <TaxonomyEntity>().ToResponse(); _mockUseCase.Setup(u => u.ExecuteGet(It.IsAny <int>())).Returns(expectedValue); var id = Randomm.Id(); //irrelevant // act var controllerResponse = _classUnderTest.GetTaxonomy(id); // assert var responseValue = (controllerResponse as ObjectResult).Value; responseValue.Should().Be(expectedValue); }
public void WhenSearchedTaxonomyIsNotFoundThenThenGetTaxonomyControllerReturnsWrapedUpErrorResponse() { // arrange var id = Randomm.Id(); _mockUseCase.Setup(u => u.ExecuteGet(It.Is <int>(p => p == id))).Returns(null as TaxonomyResponse); var expectedValue = new ErrorResponse($"Taxonomy with an Id: {id} was not found."); // act var controllerResponse = _classUnderTest.GetTaxonomy(id); // assert var responseValue = (controllerResponse as ObjectResult).Value; responseValue.Should().BeEquivalentTo(expectedValue); }
public void WhenSearchedTaxonomyIsFoundSuccessfullyThenGetTaxonomyControllerReturns200OkResponse() { // arrange var expectedStatusCode = 200; var expectedRespType = typeof(OkObjectResult); var id = Randomm.Id(); _mockUseCase.Setup(u => u.ExecuteGet(It.Is <int>(p => p == id))).Returns(new TaxonomyResponse()); // act var controllerResponse = _classUnderTest.GetTaxonomy(id); // assert var responseObjectResult = controllerResponse as ObjectResult; responseObjectResult.Should().NotBeNull(); responseObjectResult.Should().BeOfType(expectedRespType); var responseStatusCode = responseObjectResult.StatusCode; responseStatusCode.Should().Be(expectedStatusCode); }
public void WhenSearchedTaxonomyIsNotFoundThenGetTaxonomyControllerReturnsOk404NotFoundResponse() { // arrange var expectedStatusCode = 404; var expectedRespType = typeof(NotFoundObjectResult); var id = Randomm.Id(); //irrelevant _mockUseCase.Setup(u => u.ExecuteGet(It.Is <int>(p => p == id))).Returns(null as TaxonomyResponse); // act var controllerResponse = _classUnderTest.GetTaxonomy(id); // assert var responseObjectResult = controllerResponse as ObjectResult; responseObjectResult.Should().NotBeNull(); responseObjectResult.Should().BeOfType(expectedRespType); var responseStatusCode = responseObjectResult.StatusCode; responseStatusCode.Should().Be(expectedStatusCode); }
public async Task GivenRequestWithIdThatDoesNotHaveAMatchWhenGetTaxonomyEndpointIsCalledThenItReturnsA404Response() { // arrange var taxonomies = EntityHelpers.CreateTaxonomies().ToList(); DatabaseContext.Taxonomies.AddRange(taxonomies); DatabaseContext.SaveChanges(); var nonMatchingId = Randomm.Id(); var expectedValue = new ErrorResponse($"Taxonomy with an Id: {nonMatchingId} was not found."); // act var requestUri = new Uri($"api/v1/taxonomies/{nonMatchingId}", UriKind.Relative); var response = Client.GetAsync(requestUri).Result; var content = response.Content; var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true); var deserializedBody = JsonConvert.DeserializeObject <ErrorResponse>(stringResponse); // assert response.StatusCode.Should().Be(404); deserializedBody.Should().BeEquivalentTo(expectedValue); }