public async Task Detail_ReturnsViewModel() { //Arrange var mockSalesOrderViewModelService = new Mock <ISalesOrderViewModelService>(); mockSalesOrderViewModelService.Setup(x => x.GetSalesOrder( It.IsAny <string>() )) .ReturnsAsync(new SalesOrderDetailViewModel() ); var controller = new SalesOrderController( mockSalesOrderViewModelService.Object ); //Act var actionResult = await controller.Detail("SO43659"); //Assert var viewResult = actionResult.Should().BeAssignableTo <ViewResult>().Subject; var viewModel = viewResult.Model.Should().BeAssignableTo <SalesOrderDetailViewModel>().Subject; mockSalesOrderViewModelService.Verify(x => x.GetSalesOrder( It.IsAny <string>() )); }
public async Task GetSalesOrdersForCustomer_ShouldReturnSalesOrders_WhenGivenSalesOrders( [Frozen] Mock <IMediator> mockMediator, List <salesOrdersForCustomers.SalesOrderDto> salesOrders, [Greedy] SalesOrderController sut, salesOrdersForCustomers.GetSalesOrdersForCustomerQuery query ) { //Arrange var dto = new salesOrdersForCustomers.GetSalesOrdersDto { SalesOrders = salesOrders, TotalSalesOrders = salesOrders.Count }; mockMediator.Setup(x => x.Send( It.IsAny <salesOrdersForCustomers.GetSalesOrdersForCustomerQuery>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(dto); //Act var actionResult = await sut.GetSalesOrdersForCustomer(query); //Assert var okObjectResult = actionResult as OkObjectResult; okObjectResult.Should().NotBeNull(); var result = okObjectResult.Value as Core.Models.SalesOrdersResult; result.SalesOrders.Count.Should().Be(salesOrders.Count); }
public async Task Index_ReturnsViewModel() { //Arrange var mockSalesOrderViewModelService = new Mock <ISalesOrderViewModelService>(); mockSalesOrderViewModelService.Setup(x => x.GetSalesOrders( It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <CustomerType?>() )) .ReturnsAsync(new SalesOrderIndexViewModel()); var controller = new SalesOrderController( mockSalesOrderViewModelService.Object ); //Act var actionResult = await controller.Index( 0, null, null ); //Assert var viewResult = actionResult.Should().BeAssignableTo <ViewResult>().Subject; viewResult.Model.Should().BeAssignableTo <SalesOrderIndexViewModel>(); mockSalesOrderViewModelService.Verify(x => x.GetSalesOrders( It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <CustomerType?>() )); }
public void Test() { SetUp(); SalesOrderController orderController = new SalesOrderController(Configuration); var result = orderController.GetOrders(); Assert.IsNotNull(result); Assert.IsNotNull(result); Assert.IsTrue(true); }
public async Task GetSalesOrders_ShouldReturnNotFound_WhenGivenNoSalesOrders( [Greedy] SalesOrderController sut, GetSalesOrdersQuery query ) { //Act var actionResult = await sut.GetSalesOrders(query); //Assert var notFoundResult = actionResult as NotFoundResult; notFoundResult.Should().NotBeNull(); }
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 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); }