public void CreateApplication_EmptyApplicationName_ReturnsBadRequest() { // Arrange Application app = new Application { ApplicationName = "", Description = "Xunit test", BookId = 3, AppTypeName = "Applicaion server" }; int tenantId = 1; // Act var controller = new ApplicationController(logger.Object, applicationServiceMoq.Object); var response = controller.CreateApplication(app, tenantId); // Assert Assert.IsType <BadRequestObjectResult>(response); }
public void CreateApplication_Unsuccessfull() { // Arrange Application app = new Application { ApplicationName = "Test", Description = "Xunit test", BookId = 3, AppTypeName = "Applicaion server" }; int tenantId = 1; applicationServiceMoq.Setup(c => c.CreateApplication(app, tenantId)).Returns(false); // Act var controller = new ApplicationController(logger.Object, applicationServiceMoq.Object); var response = controller.CreateApplication(app, tenantId) as BadRequestObjectResult; // Assert Assert.IsType <BadRequestObjectResult>(response); Assert.Equal("Application Not created", response.Value); applicationServiceMoq.Verify(c => c.CreateApplication(app, tenantId), Times.Once); }
public async Task Then_CreateApplicationCommand_Is_Sent( CreateApplicationRequest request, [Frozen] Mock <IMediator> mockMediator, [Greedy] ApplicationController controller) { var applicationId = request.ApplicationId; mockMediator .Setup(mediator => mediator.Send( It.Is <CreateApplicationCommand>(c => c.AccountId == request.AccountId && c.AccountLegalEntityId == request.AccountLegalEntityId && c.ApplicationId == request.ApplicationId && c.ApprenticeshipIds == request.ApprenticeshipIds ), It.IsAny <CancellationToken>())) .ReturnsAsync(Unit.Value); var controllerResult = await controller.CreateApplication(request) as CreatedResult; Assert.IsNotNull(controllerResult); controllerResult.StatusCode.Should().Be((int)HttpStatusCode.Created); controllerResult.Location.Should().Be($"/accounts/{request.AccountId}/applications/{applicationId}"); }