public void UpdateAsync_ValidateRating_Test() { // Arrange var now = DateTime.Now; long orderId = 0; long customerId = 0; long productId = 0; var feedback = _dataFixture.GetFeedback(now, FeedbackType.Product); feedback.Rating = 6; _dataFixture.GetMocks <Feedback>(out var mockRepository, out var mockCacheManager, out var mockOptions); _dataFixture.GetMocks(out var orderFacadeMock, out var customerFacadeMock, out var productFacadeMock); mockRepository.Setup(repo => repo.GetManagerInstance <ProductFeedbackManager>()).Returns(() => new ProductFeedbackManager()); var productFeedbackFacade = new ProductFeedbackFacade (mockRepository.Object, orderFacadeMock.Object, customerFacadeMock.Object, productFacadeMock.Object, mockCacheManager.Object, mockOptions.Object); // Act & Assert var ex = Assert.Throws <AggregateException>(() => productFeedbackFacade.UpdateAsync(customerId, orderId, productId, feedback, CancellationToken.None).Result); Assert.Equal("One or more errors occurred. (Invalid rating. Rating must be between 1 to 5.)", ex.Message); }
public void UpdateAsync_Test() { // Arrange var now = DateTime.Now; long orderId = 0; long customerId = 0; long productId = 0; var customer = _dataFixture.GetCustomer(); var feedback = _dataFixture.GetFeedback(now, FeedbackType.Product); feedback.Products = new List <Product>(); var order = _dataFixture.GetOrder(now); order.FeedbackSid = feedback.Sid; var cachedFeedbackList = new List <Feedback> { }; var product = _dataFixture.GetProduct(); OrderToProduct orderToProduct = new OrderToProduct { Ordersid = orderId, ProductSid = productId, Ammount = 1, FeedbackSid = 0 }; _dataFixture.GetMocks <Feedback>(out var mockRepository, out var mockCacheManager, out var mockOptions); _dataFixture.GetMocks(out var orderFacadeMock, out var customerFacadeMock, out var productFacadeMock); mockCacheManager .Setup(cache => cache.GetFromCacheAsync <List <Feedback> >(It.IsAny <string>(), It.IsAny <CancellationToken>())) .ReturnsAsync(cachedFeedbackList); mockRepository .Setup(repo => repo.GetManagerInstance <ProductFeedbackManager>()) .Returns(() => new ProductFeedbackManager()); mockRepository .Setup(repo => repo.GetAsync <OrderToProduct>(otp => otp.Ordersid == orderId && otp.ProductSid == productId, CancellationToken.None)) .ReturnsAsync(orderToProduct); mockRepository .Setup(repo => repo.GetAsync <Product>(p => p.Sid == productId, CancellationToken.None)) .ReturnsAsync(product); mockRepository .Setup(repo => repo.GetAsync <Feedback>(feedback => feedback.Sid == orderToProduct.FeedbackSid && feedback.FeedbackType == (int)FeedbackType.Product, CancellationToken.None)) .ReturnsAsync(feedback); customerFacadeMock .Setup(facade => facade.GetCustommerByIdAsync(It.IsAny <long>(), It.IsAny <CancellationToken>())) .ReturnsAsync(customer); orderFacadeMock .Setup(facade => facade.GetOrderByIdAsync(It.IsAny <long>(), It.IsAny <CancellationToken>())) .ReturnsAsync(order); feedback.Comment = "Updated"; feedback.Rating = 5; var productFeedbackFacade = new ProductFeedbackFacade (mockRepository.Object, orderFacadeMock.Object, customerFacadeMock.Object, productFacadeMock.Object, mockCacheManager.Object, mockOptions.Object); // Act var result = productFeedbackFacade.UpdateAsync(customerId, orderId, productId, feedback, CancellationToken.None).Result; // Assert Assert.NotNull(result); Assert.Equal("Updated", result.Comment); Assert.Equal(5, result.Rating); }