public void CreateAsync_FeedbackAlreadyExists_Test() { // Arrange var now = DateTime.Now; long orderId = 0; long customerId = 0; var order = _dataFixture.GetOrder(now); var customer = _dataFixture.GetCustomer(); var feedback = _dataFixture.GetFeedback(now, FeedbackType.Order); order.FeedbackSid = feedback.Sid; var cachedFeedbackList = new List <Feedback> { feedback }; _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 <OrderFeedbackManager>()).Returns(() => new OrderFeedbackManager()); 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); var orderFeedbackFacade = new OrderFeedbackFacade (mockRepository.Object, orderFacadeMock.Object, customerFacadeMock.Object, productFacadeMock.Object, mockCacheManager.Object, mockOptions.Object); // Act & Assert var ex = Assert.Throws <AggregateException>(() => orderFeedbackFacade.CreateAsync(customerId, orderId, feedback, CancellationToken.None).Result); Assert.Equal("One or more errors occurred. (The order you are trying to rate has already been rated. Try modifying its feedback instead.)", ex.Message); }
public void CreateAsync_ValidateRating_Test() { // Arrange var now = DateTime.Now; long orderId = 0; long customerId = 0; var order = _dataFixture.GetOrder(now); var customer = _dataFixture.GetCustomer(); var feedback = _dataFixture.GetFeedback(now, FeedbackType.Order); //This is an invalid rating and should throw an exception feedback.Rating = 20; var cachedFeedbackList = new List <Feedback>(); _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 <OrderFeedbackManager>()).Returns(() => new OrderFeedbackManager()); 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); var orderFeedbackFacade = new OrderFeedbackFacade (mockRepository.Object, orderFacadeMock.Object, customerFacadeMock.Object, productFacadeMock.Object, mockCacheManager.Object, mockOptions.Object); // Act & Assert var ex = Assert.Throws <AggregateException>(() => orderFeedbackFacade.CreateAsync(customerId, orderId, feedback, CancellationToken.None).Result); Assert.Equal("One or more errors occurred. (Invalid rating. Rating must be between 1 to 5.)", ex.Message); }
public void CreateAsync_ValidateOrderDoesNotBelongToCustomer_Test() { // Arrange var now = DateTime.Now; long orderId = 0; long customerId = 0; var order = _dataFixture.GetOrder(now); var customer = _dataFixture.GetCustomer(); // orderId and customerId won't match and will throw an exception customer.Sid = 1; var feedback = _dataFixture.GetFeedback(now, FeedbackType.Order); _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 <OrderFeedbackManager>()).Returns(() => new OrderFeedbackManager()); 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); var orderFeedbackFacade = new OrderFeedbackFacade (mockRepository.Object, orderFacadeMock.Object, customerFacadeMock.Object, productFacadeMock.Object, mockCacheManager.Object, mockOptions.Object); // Act & Assert var ex = Assert.Throws <AggregateException>(() => orderFeedbackFacade.CreateAsync(customerId, orderId, feedback, CancellationToken.None).Result); Assert.Equal("One or more errors occurred. (User 0 does not own an order with Id 0)", ex.Message); }