public void TestValidate_WithSalesOrderNumberTooLong_ValidationError( GetSalesOrderQueryValidator sut, GetSalesOrderQuery query ) { //Act var result = sut.TestValidate(query); //Assert result.ShouldHaveValidationErrorFor(query => query.SalesOrderNumber) .WithErrorMessage("Sales order number must not exceed 25 characters"); }
public void TestValidate_WithValidSalesOrderNumber_NoValidationError( GetSalesOrderQueryValidator sut, GetSalesOrderQuery query ) { //Arrange query.SalesOrderNumber = query.SalesOrderNumber.Substring(0, 25); //Act var result = sut.TestValidate(query); //Assert result.ShouldNotHaveValidationErrorFor(query => query.SalesOrderNumber); }
public void TestValidate_WithoutSalesOrderNumber_ValidationError( GetSalesOrderQueryValidator sut, GetSalesOrderQuery query ) { //Arrange query.SalesOrderNumber = ""; //Act var result = sut.TestValidate(query); //Assert result.ShouldHaveValidationErrorFor(query => query.SalesOrderNumber) .WithErrorMessage("Sales order number is required"); }
public async Task Handle_SalesOrderWithStoreCustomer_Exists_ReturnSalesOrder( string userId, string userName, string cardSecurityNumber, string cardHolderName, Core.Entities.StoreCustomer customer, string shipMethod, ValueTypes.Address billToAddress, ValueTypes.Address shipToAddress, Core.Entities.CreditCard creditCard, [Frozen] Mock <IRepository <Core.Entities.SalesOrder> > salesOrderRepoMock, GetSalesOrderQueryHandler sut, GetSalesOrderQuery query ) { //Arrange creditCard.ExpYear = short.Parse(DateTime.Today.Year.ToString()); creditCard.ExpMonth = byte.Parse(DateTime.Today.Month.ToString()); var salesOrder = new Core.Entities.SalesOrder( userId, userName, customer, shipMethod, billToAddress, shipToAddress, creditCard, cardSecurityNumber, cardHolderName ); salesOrderRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetFullSalesOrderSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(salesOrder); //Act var result = await sut.Handle(query, CancellationToken.None); //Assert result.Should().NotBeNull(); salesOrderRepoMock.Verify(x => x.GetBySpecAsync( It.IsAny <GetFullSalesOrderSpecification>(), It.IsAny <CancellationToken>() )); result.SalesOrderNumber.Should().Be(salesOrder.SalesOrderNumber); }
public async Task GetSalesOrder_ShouldReturnNotFound_GivenNoSalesOrder( [Frozen] Mock <IMediator> mockMediator, [Greedy] SalesOrderController sut, GetSalesOrderQuery query ) { //Arrange mockMediator.Setup(x => x.Send(It.IsAny <GetSalesOrderQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync((Core.Handlers.GetSalesOrder.SalesOrderDto)null); //Act var actionResult = await sut.GetSalesOrder(query); //Assert var notFoundResult = actionResult as NotFoundResult; notFoundResult.Should().NotBeNull(); }
public void TestValidate_WithSalesOrderNumberDoesNotExist_ValidationError( [Frozen] Mock <IRepository <Core.Entities.SalesOrder> > salesOrderRepoMock, GetSalesOrderQueryValidator sut, GetSalesOrderQuery query ) { //Arrange salesOrderRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetFullSalesOrderSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((Core.Entities.SalesOrder)null); //Act var result = sut.TestValidate(query); //Assert result.ShouldHaveValidationErrorFor(query => query.SalesOrderNumber) .WithErrorMessage("Sales order does not exist"); }
public async Task GetSalesOrder_ShouldReturnSalesOrder_GivenSalesOrder( Core.Handlers.GetSalesOrder.SalesOrderDto salesOrder, [Frozen] Mock <IMediator> mockMediator, [Greedy] SalesOrderController sut, GetSalesOrderQuery query ) { //Arrange mockMediator.Setup(x => x.Send(It.IsAny <GetSalesOrderQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(salesOrder); //Act var actionResult = await sut.GetSalesOrder(query); //Assert var okObjectResult = actionResult as OkObjectResult; okObjectResult.Should().NotBeNull(); var result = okObjectResult.Value as Core.Models.SalesOrder; result.SalesOrderNumber.Should().Be(salesOrder.SalesOrderNumber); }