public async Task ValidateQuoteRequest_GivenAQuoteRequestWithANullRequestItems_ShouldReturnAValidationResultWithExpectedErrorMessage()
        {
            //Arrange
            var wholesalerId = Guid.NewGuid();
            var itemId       = Guid.NewGuid();

            RequestItem[] requestedItems = null;

            var quoteRequest = new QuoteRequest
            {
                WholesalerId = wholesalerId,
                RequestItems = requestedItems
            };

            var expectedErrorMessage = "Quote request cannot be empty";

            var mockedWholesalerQuery = new Mock <IWholesalerQuery>();

            mockedWholesalerQuery.Setup(query => query.GetWholesaler(It.IsAny <Guid>()))
            .ReturnsAsync(new Wholesaler());

            var wholesalerValidation = new WholesalerValidation(mockedWholesalerQuery.Object);

            //Act
            var results = await wholesalerValidation.ValidateQuoteRequest(quoteRequest);

            //Assert
            Assert.Contains(results, result => result != null && result.ErrorMessage.Equals(expectedErrorMessage));
        }
        public async Task ValidateQuoteRequest_GivenAQuoteRequestWithNonExistingWholesaler_ShouldReturnAValidationResultWithExpectedErrorMessage()
        {
            //Arrange
            var wholesalerId = Guid.NewGuid();
            var itemId       = Guid.NewGuid();

            var requestedItems = new[]
            {
                new RequestItem {
                    ItemId = itemId, Quantity = 1
                }
            };

            var quoteRequest = new QuoteRequest
            {
                WholesalerId = wholesalerId,
                RequestItems = requestedItems
            };

            var expectedErrorMessage = "The wholesaler does not exist";

            var mockedWholesalerQuery = new Mock <IWholesalerQuery>();

            mockedWholesalerQuery.Setup(query => query.GetWholesaler(It.IsAny <Guid>()))
            .ReturnsAsync((Wholesaler)null);

            var wholesalerValidation = new WholesalerValidation(mockedWholesalerQuery.Object);

            //Act
            var results = await wholesalerValidation.ValidateQuoteRequest(quoteRequest);

            //Assert
            Assert.Contains(results, result => result != null && result.ErrorMessage.Equals(expectedErrorMessage));
        }
        public async Task ValidateQuoteRequest_GivenAQuoteRequestWithoutWholesalerId_ShouldReturnAValidationResultWithExpectedErrorMessage()
        {
            //Arrange
            var wholesalerId = Guid.Empty;
            var itemId       = Guid.NewGuid();

            var requestedItems = new[]
            {
                new RequestItem {
                    ItemId = itemId, Quantity = 1
                }
            };

            var quoteRequest = new QuoteRequest
            {
                WholesalerId = wholesalerId,
                RequestItems = requestedItems
            };

            var expectedErrorMessage = "The wholesaler cannot be null or empty";


            var wholesalerValidation = new WholesalerValidation(null);

            //Act
            var results = await wholesalerValidation.ValidateQuoteRequest(quoteRequest);

            //Assert
            Assert.Contains(results, result => result != null && result.ErrorMessage.Equals(expectedErrorMessage));
        }
        public async Task ValidateQuoteRequest_GivenAQuoteRequestWithDuplicateElement_ShouldReturnAValidationResultWithExpectedErrorMessage()
        {
            //Arrange
            var wholesalerId = Guid.NewGuid();
            var itemId       = Guid.NewGuid();

            var requestedItems = new[]
            {
                new RequestItem {
                    ItemId = itemId, Quantity = 1
                },
                new RequestItem {
                    ItemId = itemId, Quantity = 1
                }
            };

            var wholesalerStock = new[]
            {
                new StockItem {
                    ItemId = itemId, Quantity = 1
                }
            };

            var quoteRequest = new QuoteRequest
            {
                WholesalerId = wholesalerId,
                RequestItems = requestedItems
            };

            var expectedErrorMessage = "All request items should be unique";

            var mockedWholesalerQuery = new Mock <IWholesalerQuery>();

            mockedWholesalerQuery.Setup(query => query.GetWholesaler(It.IsAny <Guid>()))
            .ReturnsAsync(new Wholesaler());
            mockedWholesalerQuery.Setup(query => query.GetWholesalerStock(It.IsAny <Guid>()))
            .ReturnsAsync(wholesalerStock);

            var wholesalerValidation = new WholesalerValidation(mockedWholesalerQuery.Object);

            //Act
            var results = await wholesalerValidation.ValidateQuoteRequest(quoteRequest);

            //Assert
            Assert.Contains(results, result => result != null && result.ErrorMessage.Equals(expectedErrorMessage));
        }
        public async Task ValidateQuoteRequest_GivenAQuoteRequestWithItemLargerQuantityThanSoldQuantity_ShouldReturnAValidationResultWithExpectedErrorMessage()
        {
            //Arrange
            var wholesalerId = Guid.NewGuid();
            var itemId       = Guid.NewGuid();

            var requestedItems = new[]
            {
                new RequestItem {
                    ItemId = itemId, Quantity = 2
                }
            };

            var wholesalerStock = new[]
            {
                new StockItem {
                    ItemId = itemId, Quantity = 1
                }
            };

            var quoteRequest = new QuoteRequest
            {
                WholesalerId = wholesalerId,
                RequestItems = requestedItems
            };

            var expectedErrorMessage = $"Requested quantity for item {itemId} is not available at this wholesaler";

            var mockedWholesalerQuery = new Mock <IWholesalerQuery>();

            mockedWholesalerQuery.Setup(query => query.GetWholesaler(It.IsAny <Guid>()))
            .ReturnsAsync(new Wholesaler());
            mockedWholesalerQuery.Setup(query => query.GetWholesalerStock(It.IsAny <Guid>()))
            .ReturnsAsync(wholesalerStock);

            var wholesalerValidation = new WholesalerValidation(mockedWholesalerQuery.Object);

            //Act
            var results = await wholesalerValidation.ValidateQuoteRequest(quoteRequest);

            //Assert
            Assert.Contains(results, result => result != null && result.ErrorMessage.Equals(expectedErrorMessage));
        }
        public async Task ValidateQuoteRequest_GivenAValidQuoteRequest_ShouldReturnAllSuccessValidationResults()
        {
            //Arrange
            var wholesalerId = Guid.NewGuid();
            var itemId       = Guid.NewGuid();

            var requestedItems = new[]
            {
                new RequestItem {
                    ItemId = itemId, Quantity = 1
                }
            };

            var wholesalerStock = new[]
            {
                new StockItem {
                    ItemId = itemId, Quantity = 1
                }
            };

            var quoteRequest = new QuoteRequest
            {
                WholesalerId = wholesalerId,
                RequestItems = requestedItems
            };

            var mockedWholesalerQuery = new Mock <IWholesalerQuery>();

            mockedWholesalerQuery.Setup(query => query.GetWholesaler(It.IsAny <Guid>()))
            .ReturnsAsync(new Wholesaler());
            mockedWholesalerQuery.Setup(query => query.GetWholesalerStock(It.IsAny <Guid>()))
            .ReturnsAsync(wholesalerStock);

            var wholesalerValidation = new WholesalerValidation(mockedWholesalerQuery.Object);

            //Act
            var results = await wholesalerValidation.ValidateQuoteRequest(quoteRequest);

            //Assert
            Assert.True(results.All(result => result == ValidationResult.Success));
        }